Skip to content

Commit

Permalink
Migrated Integration tests to nullable enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
linkdotnet committed Sep 6, 2024
1 parent 4fa74a9 commit 5facfc2
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public async Task ShouldBeUpdateable()
await DbContext.SaveChangesAsync();
var blogPostFromDb = await Repository.GetByIdAsync(blogPost.Id);
var updater = new BlogPostBuilder().WithTitle("New Title").Build();
blogPostFromDb.Update(updater);
blogPostFromDb!.Update(updater);

await Repository.StoreAsync(blogPostFromDb);

Expand Down Expand Up @@ -130,11 +130,12 @@ public async Task GivenBlogPostWithTags_WhenLoadingAndDeleting_ThenShouldBeUpdat
await sut.StoreAsync(bp);
var updateBp = new BlogPostBuilder().WithTags("tag 2").Build();
var bpFromCache = await sut.GetByIdAsync(bp.Id);
bpFromCache.Update(updateBp);
bpFromCache!.Update(updateBp);
await sut.StoreAsync(bpFromCache);

var bpFromDb = await sut.GetByIdAsync(bp.Id);

bpFromDb.ShouldNotBeNull();
bpFromDb.Tags.Single().ShouldBe("tag 2");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,18 @@ private sealed class SlowRepository : IRepository<BlogPost>
{
public ValueTask<HealthCheckResult> PerformHealthCheckAsync() => throw new NotImplementedException();

public ValueTask<BlogPost> GetByIdAsync(string id) => throw new NotImplementedException();
public ValueTask<BlogPost?> GetByIdAsync(string id) => throw new NotImplementedException();

public ValueTask<IPagedList<BlogPost>> GetAllAsync(Expression<Func<BlogPost, bool>> filter = null,
Expression<Func<BlogPost, object>> orderBy = null,
public ValueTask<IPagedList<BlogPost>> GetAllAsync(Expression<Func<BlogPost, bool>>? filter = null,
Expression<Func<BlogPost, object>>? orderBy = null,
bool descending = true,
int page = 1,
int pageSize = int.MaxValue) => throw new NotImplementedException();

public async ValueTask<IPagedList<TProjection>> GetAllByProjectionAsync<TProjection>(
Expression<Func<BlogPost, TProjection>> selector,
Expression<Func<BlogPost, bool>> filter = null,
Expression<Func<BlogPost, object>> orderBy = null,
Expression<Func<BlogPost, TProjection>>? selector,
Expression<Func<BlogPost, bool>>? filter = null,
Expression<Func<BlogPost, object>>? orderBy = null,
bool descending = true,
int page = 1,
int pageSize = int.MaxValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public async Task ShouldPublishScheduledBlogPosts()

await sut.RunAsync(Substitute.For<IJobExecutionContext>(), CancellationToken.None);

(await Repository.GetByIdAsync(bp1.Id)).IsPublished.ShouldBeTrue();
(await Repository.GetByIdAsync(bp2.Id)).IsPublished.ShouldBeTrue();
(await Repository.GetByIdAsync(bp3.Id)).IsPublished.ShouldBeFalse();
(await Repository.GetByIdAsync(bp1.Id))!.IsPublished.ShouldBeTrue();
(await Repository.GetByIdAsync(bp2.Id))!.IsPublished.ShouldBeTrue();
(await Repository.GetByIdAsync(bp3.Id))!.IsPublished.ShouldBeFalse();
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public async Task ShouldSetPageToFirstIfOutOfRange(int? page)
}

private static (ApplicationConfiguration ApplicationConfiguration, Introduction Introduction)
CreateSampleAppConfiguration(string profilePictureUri = null)
CreateSampleAppConfiguration(string? profilePictureUri = null)
{
return (new ApplicationConfigurationBuilder()
.WithBlogName(string.Empty)
Expand All @@ -162,7 +162,7 @@ private async Task CreatePublishedBlogPosts(int amount)
}
}

private void RegisterComponents(BunitContext ctx, string profilePictureUri = null)
private void RegisterComponents(BunitContext ctx, string? profilePictureUri = null)
{
ctx.Services.AddScoped(_ => Repository);
ctx.Services.AddScoped(_ => Options.Create(CreateSampleAppConfiguration(profilePictureUri).ApplicationConfiguration));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public async Task ShouldSetStructuredData()
ctx.JSInterop.Mode = JSRuntimeMode.Loose;
ctx.AddAuthorization();
RegisterComponents(ctx);
ctx.ComponentFactories.AddStub<HeadContent>(ps => ps.Get(p => p.ChildContent));
ctx.ComponentFactories.AddStub<HeadContent>(ps => ps.Get(p => p.ChildContent)!);
var cut = ctx.Render<ShowBlogPostPage>(
p => p.Add(b => b.BlogPostId, post.Id));

Expand All @@ -115,7 +115,7 @@ public void ShouldShowErrorPageWhenBlogPostNotFound()
cut.FindAll("#no-blog-post-error").ShouldHaveSingleItem();
}

private void RegisterComponents(BunitContext ctx, ILocalStorageService localStorageService = null)
private void RegisterComponents(BunitContext ctx, ILocalStorageService? localStorageService = null)
{
ctx.Services.AddScoped(_ => Repository);
ctx.Services.AddScoped(_ => localStorageService ?? Substitute.For<ILocalStorageService>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void ShouldShowBrandImageIfAvailable()
[Theory]
[InlineData(null)]
[InlineData("")]
public void ShouldShowBlogNameWhenNotBrand(string brandUrl)
public void ShouldShowBlogNameWhenNotBrand(string? brandUrl)
{
var config = Options.Create(new ApplicationConfigurationBuilder()
.WithBlogBrandUrl(brandUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void ShouldShowAdminActionsWhenLoggedIn()
public void ShouldAddEntry()
{
var (repo, _) = RegisterServices();
ProfileInformationEntry entryToDb = null;
ProfileInformationEntry? entryToDb = null;
repo.When(r => r.StoreAsync(Arg.Any<ProfileInformationEntry>()))
.Do(call => entryToDb = call.Arg<ProfileInformationEntry>());
var cut = RenderProfileInAdmin();
Expand Down Expand Up @@ -100,7 +100,7 @@ public void ShouldAddEntryWithCorrectSortOrder()
var (repo, _) = RegisterServices();
var entry = new ProfileInformationEntryBuilder().WithSortOrder(1).Build();
SetupGetAll(repo, entry);
ProfileInformationEntry entryToDb = null;
ProfileInformationEntry? entryToDb = null;
repo.When(r => r.StoreAsync(Arg.Any<ProfileInformationEntry>()))
.Do(call => entryToDb = call.Arg<ProfileInformationEntry>());
var cut = RenderProfileInAdmin();
Expand All @@ -121,7 +121,7 @@ public void ShouldSetNewOrderWhenItemDragAndDropped()
var source = new ProfileInformationEntryBuilder().WithSortOrder(200).Build();
var (repo, calculator) = RegisterServices();
SetupGetAll(repo, target, source);
ProfileInformationEntry entryToDb = null;
ProfileInformationEntry? entryToDb = null;
repo.When(r => r.StoreAsync(Arg.Any<ProfileInformationEntry>()))
.Do(call => entryToDb = call.Arg<ProfileInformationEntry>());
var cut = RenderProfileInAdmin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using LinkDotNet.Blog.Domain;
using LinkDotNet.Blog.Infrastructure.Persistence;
using LinkDotNet.Blog.Web.Features.Admin.Sitemap.Services;
using Microsoft.AspNetCore.Components;

namespace LinkDotNet.Blog.IntegrationTests.Web.Shared.Services;

Expand All @@ -16,7 +17,7 @@ public sealed class SitemapServiceTests : IDisposable
public SitemapServiceTests()
{
var repositoryMock = Substitute.For<IRepository<BlogPost>>();
sut = new SitemapService(repositoryMock, null, new XmlFileWriter());
sut = new SitemapService(repositoryMock, Substitute.For<NavigationManager>(), new XmlFileWriter());
Directory.CreateDirectory("wwwroot");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public async Task ShouldUpdateProficiencyWhenSkillTagDragged()
cut.FindAll(".proficiency-level")[1].Drop();

var skillFromDb = await Repository.GetByIdAsync(skill.Id);
skillFromDb.ShouldNotBeNull();
skillFromDb.ProficiencyLevel.ShouldBe(ProficiencyLevel.Proficient);
}

Expand All @@ -107,6 +108,7 @@ public async Task ShouldStayOnSameProficiencyWhenDroppedOnSameProficiencyLevel()
cut.FindAll(".proficiency-level")[0].Drop();

var skillFromDb = await Repository.GetByIdAsync(skill.Id);
skillFromDb.ShouldNotBeNull();
skillFromDb.ProficiencyLevel.ShouldBe(ProficiencyLevel.Familiar);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public ApplicationConfigurationBuilder WithShowSimilarPosts(bool showSimilarPost
return this;
}

public ApplicationConfigurationBuilder WithBlogBrandUrl(string blogBrandUrl)
public ApplicationConfigurationBuilder WithBlogBrandUrl(string? blogBrandUrl)
{
this.blogBrandUrl = blogBrandUrl;
return this;
Expand Down

0 comments on commit 5facfc2

Please sign in to comment.