Skip to content

Commit 8e58266

Browse files
committed
Fixed wrong mapping in AppConfiguration and added tests
1 parent bbeae29 commit 8e58266

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

LinkDotNet.Blog.IntegrationTests/Web/Shared/NavMenuTests.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Bunit;
1+
using System.Linq;
2+
using AngleSharp.Dom;
3+
using Bunit;
24
using Bunit.TestDoubles;
35
using FluentAssertions;
46
using LinkDotNet.Blog.Web;
@@ -24,5 +26,29 @@ public void ShouldNavigateToSearchPage()
2426

2527
navigationManager.Uri.Should().EndWith("search/Text");
2628
}
29+
30+
[Theory]
31+
[InlineData(null, null, false, false)]
32+
[InlineData(null, "linkedin", false, true)]
33+
[InlineData("github", null, true, false)]
34+
public void ShouldDisplayGithubAndLinkedInPageWhenOnlyWhenSet(
35+
string github,
36+
string linkedin,
37+
bool githubAvailable,
38+
bool linkedinAvailable)
39+
{
40+
var config = new AppConfiguration
41+
{
42+
GithubAccountUrl = github,
43+
LinkedinAccountUrl = linkedin,
44+
};
45+
Services.AddScoped(_ => config);
46+
this.AddTestAuthorization();
47+
48+
var cut = RenderComponent<NavMenu>();
49+
50+
cut.FindAll("li").Any(l => l.TextContent.Contains("Github")).Should().Be(githubAvailable);
51+
cut.FindAll("li").Any(l => l.TextContent.Contains("LinkedIn")).Should().Be(linkedinAvailable);
52+
}
2753
}
2854
}

LinkDotNet.Blog.UnitTests/Web/AppConfigurationFactoryTests.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,23 @@ public void ShouldMapFromAppConfiguration()
5050
appConfiguration.ProfileInformation.ProfilePictureUrl.Should().Be("Url");
5151
}
5252

53-
[Fact]
54-
public void ShouldSetGithubLinkedAccountAccordingToValueSet()
53+
[Theory]
54+
[InlineData(null, null, false, false)]
55+
[InlineData(null, "linkedin", false, true)]
56+
[InlineData("github", null, true, false)]
57+
public void ShouldSetGithubLinkedAccountAccordingToValueSet(
58+
string githubUrl,
59+
string linkedInUrl,
60+
bool githubAvailable,
61+
bool linkedInAvailable)
5562
{
5663
var inMemorySettings = new Dictionary<string, string>
5764
{
5865
{ "Introduction:BackgroundUrl", "someurl" },
5966
{ "Introduction:ProfilePictureUrl", "anotherurl" },
6067
{ "Introduction:Description", "desc" },
68+
{ "GithubAccountUrl", githubUrl },
69+
{ "LinkedInAccountUrl", linkedInUrl },
6170
{ "BlogPostsPerPage", "2" },
6271
{ "IsAboutMeEnabled", "false" },
6372
};
@@ -67,8 +76,8 @@ public void ShouldSetGithubLinkedAccountAccordingToValueSet()
6776

6877
var appConfiguration = AppConfigurationFactory.Create(configuration);
6978

70-
appConfiguration.HasGithubAccount.Should().BeFalse();
71-
appConfiguration.HasLinkedinAccount.Should().BeFalse();
79+
appConfiguration.HasGithubAccount.Should().Be(githubAvailable);
80+
appConfiguration.HasLinkedinAccount.Should().Be(linkedInAvailable);
7281
}
7382
}
7483
}

LinkDotNet.Blog.Web/AppConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public record AppConfiguration
1212

1313
public string GithubAccountUrl { get; init; }
1414

15-
public bool HasGithubAccount => !string.IsNullOrEmpty(LinkedinAccountUrl);
15+
public bool HasGithubAccount => !string.IsNullOrEmpty(GithubAccountUrl);
1616

1717
public Introduction Introduction { get; init; }
1818

0 commit comments

Comments
 (0)