Skip to content

Commit

Permalink
Removed Social From App Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
manishtiwari25 committed Dec 14, 2023
1 parent 3a43a61 commit 04ac364
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 16 deletions.
2 changes: 2 additions & 0 deletions src/LinkDotNet.Blog.Domain/Social.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ namespace LinkDotNet.Blog.Domain;

public sealed record Social
{
public const string SocialSection = "Social";

public string LinkedinAccountUrl { get; init; }

public bool HasLinkedinAccount => !string.IsNullOrEmpty(LinkedinAccountUrl);
Expand Down
2 changes: 0 additions & 2 deletions src/LinkDotNet.Blog.Web/ApplicationConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ public sealed record ApplicationConfiguration

public string BlogBrandUrl { get; init; }

public Social Social { get; init; }

public string ConnectionString { get; init; }

public string DatabaseName { get; init; }
Expand Down
24 changes: 24 additions & 0 deletions src/LinkDotNet.Blog.Web/ConfigurationExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,28 @@ public static IServiceCollection AddAuthenticationConfigurations(this IServiceCo
});
return services;
}

public static IServiceCollection AddIntroductionConfigurations(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);

services.AddOptions<Introduction>()
.Configure<IConfiguration>((settings, config) =>
{
config.GetSection(Introduction.IntroductionSection).Bind(settings);
});
return services;
}

public static IServiceCollection AddSocialConfigurations(this IServiceCollection services)
{
ArgumentNullException.ThrowIfNull(services);

services.AddOptions<AuthInformation>()
.Configure<IConfiguration>((settings, config) =>
{
config.GetSection(Social.SocialSection).Bind(settings);
});
return services;
}
}
4 changes: 3 additions & 1 deletion src/LinkDotNet.Blog.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ private static void RegisterServices(WebApplicationBuilder builder)

builder.Services
.AddConfigurations()
.AddAuthenticationConfigurations();
.AddAuthenticationConfigurations()
.AddIntroductionConfigurations()
.AddSocialConfigurations();

builder.Services.AddBlazoredToast();
builder.Services.RegisterServices();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,11 @@ public async Task ShouldSetPageToFirstIfOutOfRange(int? page)
cut.FindAll(".blog-card").Count.Should().Be(10);
}

private static (ApplicationConfiguration ApplicationConfiguration,Introduction Introduction) CreateSampleAppConfiguration(string profilePictureUri = null)
private static (ApplicationConfiguration ApplicationConfiguration, Introduction Introduction) CreateSampleAppConfiguration(string profilePictureUri = null)
{
return (new ApplicationConfiguration
{
BlogName = string.Empty,
Social = new Social(),
BlogPostsPerPage = 10,
},
new Introduction
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ public void ShouldMapFromAppConfiguration()

appConfiguration.BlogName.Should().Be("UnitTest");
appConfiguration.BlogBrandUrl.Should().Be("http://localhost");
appConfiguration.Social.GithubAccountUrl.Should().Be("github");
appConfiguration.Social.HasGithubAccount.Should().BeTrue();
appConfiguration.Social.LinkedinAccountUrl.Should().Be("linkedIn");
appConfiguration.Social.HasLinkedinAccount.Should().BeTrue();
appConfiguration.Social.TwitterAccountUrl.Should().Be("twitter");
appConfiguration.Social.HasTwitterAccount.Should().BeTrue();
appConfiguration.ConnectionString.Should().Be("cs");
appConfiguration.DatabaseName.Should().Be("db");
appConfiguration.BlogPostsPerPage.Should().Be(5);
Expand All @@ -75,6 +69,15 @@ public void ShouldMapFromAppConfiguration()
appConfiguration.PatreonName.Should().Be("linkdotnet");
appConfiguration.IsPatreonEnabled.Should().BeTrue();

var social = new Social();
configuration.GetSection(Social.SocialSection).Bind(social);
social.GithubAccountUrl.Should().Be("github");
social.HasGithubAccount.Should().BeTrue();
social.LinkedinAccountUrl.Should().Be("linkedIn");
social.HasLinkedinAccount.Should().BeTrue();
social.TwitterAccountUrl.Should().Be("twitter");
social.HasTwitterAccount.Should().BeTrue();

var introduction = new Introduction();
configuration.GetSection(Introduction.IntroductionSection).Bind(introduction);
introduction.BackgroundUrl.Should().Be("someurl");
Expand Down Expand Up @@ -115,12 +118,12 @@ public void ShouldSetGithubLinkedAccountAccordingToValueSet(
.AddInMemoryCollection(inMemorySettings)
.Build();

var appConfiguration = new ApplicationConfiguration();
configuration.Bind(appConfiguration);
var socialConfiguration = new Social();
configuration.GetSection(Social.SocialSection).Bind(socialConfiguration);

appConfiguration.Social.HasGithubAccount.Should().Be(githubAvailable);
appConfiguration.Social.HasLinkedinAccount.Should().Be(linkedInAvailable);
appConfiguration.Social.HasTwitterAccount.Should().Be(twitterAvailable);
socialConfiguration.HasGithubAccount.Should().Be(githubAvailable);
socialConfiguration.HasLinkedinAccount.Should().Be(linkedInAvailable);
socialConfiguration.HasTwitterAccount.Should().Be(twitterAvailable);
}

[Fact]
Expand Down

0 comments on commit 04ac364

Please sign in to comment.