@inherits Bunit.TestContext

@code 
{
  private Mock<IPostService> _postServiceMock = new();

  [Test]
  public void Feed_WhenRendedAndNoPosts_ItShouldRenderNoPostsMessage()
  {
    _postServiceMock
      .Setup(x => x.GetPostsAsync())
      .ReturnsAsync(new List<Post>());

    var ctx = new TestContext();

    ctx.Services.AddSingleton(_postServiceMock.Object);

    var cut = ctx.Render(@<Feed />);

    cut.Find("p").MarkupMatches("<p>Looks like writers block. Check back later.</p>");
  }

  [Test]
  public void Feed_WhenRendedAndPosts_ItShouldRenderPosts()
  {
    List<Post> posts = [
      new Post() { Title = "Post 1", },
      new Post() { Title = "Post 2", },
    ];

    _postServiceMock
      .Setup(x => x.GetPostsAsync())
      .ReturnsAsync(posts);

    var ctx = new TestContext();

    ctx.Services.AddScoped(_ => _postServiceMock.Object);

    var cut = ctx.Render(@<Feed />);

    var articles = cut.FindAll("article");

    articles.Count.Should().Be(2);
  }
}