fix: replace deprecated TestContext with BunitContext

This commit is contained in:
Stevan Freeborn
2025-11-22 07:23:37 -06:00
parent a1fa9f8a37
commit 4d186a0274
3 changed files with 16 additions and 16 deletions
+11 -11
View File
@@ -1,6 +1,6 @@
@inherits Bunit.TestContext @inherits Bunit.BunitContext
@code @code
{ {
private Mock<IPostService> _postServiceMock = new(); private Mock<IPostService> _postServiceMock = new();
@@ -8,10 +8,10 @@
public void Feed_WhenRendedAndNoPosts_ItShouldRenderNoPostsMessage() public void Feed_WhenRendedAndNoPosts_ItShouldRenderNoPostsMessage()
{ {
_postServiceMock _postServiceMock
.Setup(x => x.GetPostsAsync()) .Setup(x => x.GetPostsAsync())
.ReturnsAsync(new List<Post>()); .ReturnsAsync(new List<Post>());
var ctx = new TestContext(); var ctx = new BunitContext();
ctx.Services.AddSingleton(_postServiceMock.Object); ctx.Services.AddSingleton(_postServiceMock.Object);
@@ -24,15 +24,15 @@
public void Feed_WhenRendedAndPosts_ItShouldRenderPosts() public void Feed_WhenRendedAndPosts_ItShouldRenderPosts()
{ {
List<Post> posts = [ List<Post> posts = [
new Post() { Title = "Post 1", }, new Post() { Title = "Post 1", },
new Post() { Title = "Post 2", }, new Post() { Title = "Post 2", },
]; ];
_postServiceMock _postServiceMock
.Setup(x => x.GetPostsAsync()) .Setup(x => x.GetPostsAsync())
.ReturnsAsync(posts); .ReturnsAsync(posts);
var ctx = new TestContext(); var ctx = new BunitContext();
ctx.Services.AddScoped(_ => _postServiceMock.Object); ctx.Services.AddScoped(_ => _postServiceMock.Object);
+3 -3
View File
@@ -1,11 +1,11 @@
@inherits Bunit.TestContext @inherits Bunit.BunitContext
@code @code
{ {
[Test] [Test]
public void Footer_WhenRendered_ItShouldRenderFooterWithNavLinks() public void Footer_WhenRendered_ItShouldRenderFooterWithNavLinks()
{ {
var ctx = new TestContext(); var ctx = new BunitContext();
var cut = ctx.Render(@<Footer />); var cut = ctx.Render(@<Footer />);
+2 -2
View File
@@ -1,4 +1,4 @@
@inherits Bunit.TestContext @inherits Bunit.BunitContext
@code @code
{ {
@@ -29,4 +29,4 @@
var image = cut.Find("img[alt='Stevan Freeborn']"); var image = cut.Find("img[alt='Stevan Freeborn']");
image.Should().NotBeNull(); image.Should().NotBeNull();
} }
} }