Skip to content

Commit 639970d

Browse files
committed
Added Tests
1 parent 88a1475 commit 639970d

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

LinkDotNet.Blog.IntegrationTests/Web/Pages/IndexTests.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Linq;
1+
using System;
2+
using System.Linq;
23
using System.Threading.Tasks;
34
using Bunit;
45
using FluentAssertions;
@@ -8,6 +9,7 @@
89
using LinkDotNet.Blog.Web;
910
using LinkDotNet.Blog.Web.Shared;
1011
using LinkDotNet.Blog.Web.Shared.Services;
12+
using Microsoft.AspNetCore.Components;
1113
using Microsoft.Extensions.DependencyInjection;
1214
using Moq;
1315
using Toolbelt.Blazor.HeadElement;
@@ -74,7 +76,7 @@ public async Task ShouldOnlyLoadTenEntities()
7476
}
7577

7678
[Fact]
77-
public async Task ShouldLoadNextBatchOnClick()
79+
public async Task ShouldGoToNextPageOnNextClick()
7880
{
7981
await CreatePublishedBlogPosts(11);
8082
using var ctx = new TestContext();
@@ -84,28 +86,42 @@ public async Task ShouldLoadNextBatchOnClick()
8486

8587
cut.FindComponent<BlogPostNavigation>().Find("li:last-child a").Click();
8688

87-
cut.WaitForState(() => cut.FindAll(".blog-card").Count == 1);
88-
var blogPosts = cut.FindComponents<ShortBlogPost>();
89-
blogPosts.Count.Should().Be(1);
89+
var navigationManager = ctx.Services.GetService<NavigationManager>();
90+
cut.WaitForState(() => navigationManager.Uri.Contains("/2"));
91+
navigationManager.Uri.Should().Contain("/2");
9092
}
9193

9294
[Fact]
93-
public async Task ShouldLoadPreviousBatchOnClick()
95+
public async Task ShouldGoToPreviousPageOnPreviousClick()
9496
{
9597
await CreatePublishedBlogPosts(11);
9698
using var ctx = new TestContext();
9799
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
98100
RegisterComponents(ctx);
99-
var cut = ctx.RenderComponent<Index>();
100-
cut.WaitForState(() => cut.FindAll(".blog-card").Any());
101-
cut.FindComponent<BlogPostNavigation>().Find("li:last-child a").Click();
102-
cut.WaitForState(() => cut.FindAll(".blog-card").Count == 1);
101+
var cut = ctx.RenderComponent<Index>(
102+
p => p.Add(s => s.Page, 2));
103103

104104
cut.FindComponent<BlogPostNavigation>().Find("li:first-child a").Click();
105105

106-
cut.WaitForState(() => cut.FindAll(".blog-card").Count > 1);
106+
var navigationManager = ctx.Services.GetService<NavigationManager>();
107+
cut.WaitForState(() => navigationManager.Uri.Contains("/1"));
108+
navigationManager.Uri.Should().Contain("/1");
109+
}
110+
111+
[Fact]
112+
public async Task ShouldLoadOnlyItemsInPage()
113+
{
114+
await CreatePublishedBlogPosts(11);
115+
using var ctx = new TestContext();
116+
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
117+
RegisterComponents(ctx);
118+
119+
var cut = ctx.RenderComponent<Index>(
120+
p => p.Add(s => s.Page, 2));
121+
122+
cut.WaitForState(() => cut.FindAll(".blog-card").Any());
107123
var blogPosts = cut.FindComponents<ShortBlogPost>();
108-
blogPosts.Count.Should().Be(10);
124+
blogPosts.Should().HaveCount(1);
109125
}
110126

111127
[Fact]

LinkDotNet.Blog.UnitTests/Web/Shared/Services/UserRecordServiceTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class UserRecordServiceTests : TestContext
2222
public UserRecordServiceTests()
2323
{
2424
repositoryMock = new Mock<IRepository<UserRecord>>();
25-
fakeNavigationManager = new FakeNavigationManager(this.Renderer);
25+
fakeNavigationManager = new FakeNavigationManager(Renderer);
2626
fakeAuthenticationStateProvider = new FakeAuthenticationStateProvider();
2727
localStorageService = new Mock<ILocalStorageService>();
2828
sut = new UserRecordService(

LinkDotNet.Blog.Web/Pages/Index.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242

4343
protected override async Task OnParametersSetAsync()
4444
{
45-
currentPage = await blogPostRepository.GetAllAsync(
45+
currentPage = await blogPostRepository.GetAllAsync(
4646
p => p.IsPublished,
4747
b => b.UpdatedDate,
4848
pageSize: appConfiguration.BlogPostsPerPage,

0 commit comments

Comments
 (0)