Skip to content

Commit 4fa74a9

Browse files
committed
Nullable annotations for unit test project
1 parent 914e492 commit 4fa74a9

27 files changed

+95
-73
lines changed

src/LinkDotNet.Blog.Domain/Enumeration.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ protected Enumeration(string key)
2020

2121
public string Key { get; }
2222

23-
public static bool operator ==(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b)
23+
public static bool operator ==(Enumeration<TEnumeration>? a, Enumeration<TEnumeration>? b)
2424
=> a is not null && b is not null && a.Key.Equals(b.Key, StringComparison.Ordinal);
2525

26-
public static bool operator !=(Enumeration<TEnumeration> a, Enumeration<TEnumeration> b) => !(a == b);
26+
public static bool operator !=(Enumeration<TEnumeration>? a, Enumeration<TEnumeration>? b) => !(a == b);
2727

2828
public static TEnumeration Create(string key)
2929
=> All.SingleOrDefault(p => p.Key == key)

tests/LinkDotNet.Blog.TestUtilities/ApplicationConfigurationBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ public ApplicationConfigurationBuilder WithIsDisqusEnabled(bool isDisqusEnabled)
6767
return this;
6868
}
6969

70-
public ApplicationConfigurationBuilder WithKofiToken(string kofiToken)
70+
public ApplicationConfigurationBuilder WithKofiToken(string? kofiToken)
7171
{
7272
this.kofiToken = kofiToken;
7373
return this;
7474
}
7575

76-
public ApplicationConfigurationBuilder WithGithubSponsorName(string githubSponsorName)
76+
public ApplicationConfigurationBuilder WithGithubSponsorName(string? githubSponsorName)
7777
{
7878
this.githubSponsorName = githubSponsorName;
7979
return this;
@@ -85,7 +85,7 @@ public ApplicationConfigurationBuilder WithShowReadingIndicator(bool showReading
8585
return this;
8686
}
8787

88-
public ApplicationConfigurationBuilder WithPatreonName(string patreonName)
88+
public ApplicationConfigurationBuilder WithPatreonName(string? patreonName)
8989
{
9090
this.patreonName = patreonName;
9191
return this;

tests/LinkDotNet.Blog.TestUtilities/BlogPostBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public BlogPostBuilder WithPreviewImageUrl(string url)
4040
return this;
4141
}
4242

43-
public BlogPostBuilder WithPreviewImageUrlFallback(string url)
43+
public BlogPostBuilder WithPreviewImageUrlFallback(string? url)
4444
{
4545
previewImageUrlFallback = url;
4646
return this;

tests/LinkDotNet.Blog.TestUtilities/IntroductionBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class IntroductionBuilder
88
private string profilePictureUrl = "ProfilePictureUrl";
99
private string description = "Description";
1010

11-
public IntroductionBuilder WithBackgroundUrl(string backgroundUrl)
11+
public IntroductionBuilder WithBackgroundUrl(string? backgroundUrl)
1212
{
1313
this.backgroundUrl = backgroundUrl;
1414
return this;

tests/LinkDotNet.Blog.TestUtilities/SkillBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public SkillBuilder WithSkillName(string skill)
1515
return this;
1616
}
1717

18-
public SkillBuilder WithIconUrl(string iconUrl)
18+
public SkillBuilder WithIconUrl(string? iconUrl)
1919
{
2020
this.iconUrl = iconUrl;
2121
return this;

tests/LinkDotNet.Blog.UnitTests/Domain/EnumerationTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ public void GivenInvalidKey_WhenCreatingEnumeration_ThenErrorResult()
5555
[InlineData(null)]
5656
[InlineData("")]
5757
[InlineData(" ")]
58-
public void GivenNullOrEmptyKey_WhenCreating_ThenException(string key)
58+
public void GivenNullOrEmptyKey_WhenCreating_ThenException(string? key)
5959
{
60-
Action result = () => new TestEnumeration(key);
60+
Action result = () => new TestEnumeration(key!);
6161

6262
// Assert
6363
result.ShouldThrow<ArgumentException>();
@@ -66,7 +66,7 @@ public void GivenNullOrEmptyKey_WhenCreating_ThenException(string key)
6666
[Fact]
6767
public void NullEnumerationNeverEqual()
6868
{
69-
var isEqual = null == (TestEnumeration)null;
69+
var isEqual = null! == (TestEnumeration?)null;
7070

7171
isEqual.ShouldBeFalse();
7272
}

tests/LinkDotNet.Blog.UnitTests/Domain/ProficiencyLevelTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public void ShouldCreateValidLevels(string key)
2020
[InlineData("NotALevel")]
2121
[InlineData("")]
2222
[InlineData(null)]
23-
public void ShouldNotCreateInvalidLevels(string key)
23+
public void ShouldNotCreateInvalidLevels(string? key)
2424
{
25-
Action act = () => ProficiencyLevel.Create(key);
25+
Action act = () => ProficiencyLevel.Create(key!);
2626

2727
act.ShouldThrow<Exception>();
2828
}

tests/LinkDotNet.Blog.UnitTests/Domain/ProfileInformationEntryTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ public void ShouldCreateObject()
1818
[InlineData("")]
1919
[InlineData(" ")]
2020
[InlineData(null)]
21-
public void ShouldThrowExceptionWhenEmptyKeyOrValue(string content)
21+
public void ShouldThrowExceptionWhenEmptyKeyOrValue(string? content)
2222
{
23-
Action act = () => ProfileInformationEntry.Create(content, 0);
23+
Action act = () => ProfileInformationEntry.Create(content!, 0);
2424

2525
act.ShouldThrow<ArgumentException>();
2626
}

tests/LinkDotNet.Blog.UnitTests/Domain/SkillTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ public void ShouldCreateSkillTrimmedWhitespaces()
2020
[InlineData(null)]
2121
[InlineData("")]
2222
[InlineData(" ")]
23-
public void ShouldThrowWhenWhitespaceName(string name)
23+
public void ShouldThrowWhenWhitespaceName(string? name)
2424
{
25-
Action result = () => Skill.Create(name, "url", "backend", ProficiencyLevel.Expert.Key);
25+
Action result = () => Skill.Create(name!, "url", "backend", ProficiencyLevel.Expert.Key);
2626

2727
result.ShouldThrow<ArgumentException>();
2828
}
@@ -31,9 +31,9 @@ public void ShouldThrowWhenWhitespaceName(string name)
3131
[InlineData(null)]
3232
[InlineData("")]
3333
[InlineData(" ")]
34-
public void ShouldThrowWhenWhitespaceCapability(string capability)
34+
public void ShouldThrowWhenWhitespaceCapability(string? capability)
3535
{
36-
Action result = () => Skill.Create("name", "url", capability, ProficiencyLevel.Expert.Key);
36+
Action result = () => Skill.Create("name", "url", capability!, ProficiencyLevel.Expert.Key);
3737

3838
result.ShouldThrow<ArgumentException>();
3939
}
@@ -49,7 +49,7 @@ public void ShouldThrowWhenInvalidProficiencyLevel()
4949
[InlineData(null)]
5050
[InlineData("")]
5151
[InlineData(" ")]
52-
public void ShouldSetUrlToNullWhenWhitespace(string url)
52+
public void ShouldSetUrlToNullWhenWhitespace(string? url)
5353
{
5454
var skill = Skill.Create("name", url, "cap", ProficiencyLevel.Expert.Key);
5555

@@ -71,7 +71,7 @@ public void ShouldThrowWhenProficiencyIsNull()
7171
{
7272
var skill = Skill.Create("name", null, "cap", ProficiencyLevel.Familiar.Key);
7373

74-
Action result = () => skill.SetProficiencyLevel(null);
74+
Action result = () => skill.SetProficiencyLevel(null!);
7575

7676
result.ShouldThrow<ArgumentNullException>();
7777
}

tests/LinkDotNet.Blog.UnitTests/Domain/TalkTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public void CreateTalkWithTrimmedWhiteSpaces()
2626
[InlineData("title", "place", null)]
2727
[InlineData("title", "place", "")]
2828
[InlineData("title", "place", " ")]
29-
public void TalkWithInvalidInvariantShouldNotBeCreated(string title, string place, string desc)
29+
public void TalkWithInvalidInvariantShouldNotBeCreated(string? title, string? place, string? desc)
3030
{
31-
Action act = () => Talk.Create(title, place, desc, DateTime.MinValue);
31+
Action act = () => Talk.Create(title!, place!, desc!, DateTime.MinValue);
3232

3333
act.ShouldThrow<Exception>();
3434
}

0 commit comments

Comments
 (0)