26ff8d9b4f
Set up repository with legacy .NET Framework 4.8 source (OLD/), new .NET 10 Blazor solution (NEW/), OpenSpec specifications, documentation, and project configuration.
83 lines
2.6 KiB
C#
83 lines
2.6 KiB
C#
using JdeScoping.Core.Interfaces;
|
|
using JdeScoping.Infrastructure.Auth;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Shouldly;
|
|
|
|
namespace JdeScoping.Api.Tests.Configuration;
|
|
|
|
public class ServiceRegistrationTests
|
|
{
|
|
[Fact]
|
|
public void AddInfrastructure_WithUseFakeAuthTrue_RegistersFakeAuthService()
|
|
{
|
|
// Arrange
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
|
|
var configuration = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["Auth:UseFakeAuth"] = "true"
|
|
})
|
|
.Build();
|
|
|
|
// Act
|
|
services.AddInfrastructure(configuration);
|
|
var provider = services.BuildServiceProvider();
|
|
var authService = provider.GetRequiredService<IAuthService>();
|
|
|
|
// Assert
|
|
authService.ShouldBeOfType<FakeAuthService>();
|
|
}
|
|
|
|
[Fact]
|
|
public void AddInfrastructure_WithUseFakeAuthFalse_RegistersLdapAuthService()
|
|
{
|
|
// Arrange
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
|
|
var configuration = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["Auth:UseFakeAuth"] = "false",
|
|
["Ldap:ServerUrls:0"] = "ldap://localhost:389",
|
|
["Ldap:SearchBase"] = "DC=example,DC=com"
|
|
})
|
|
.Build();
|
|
|
|
// Act
|
|
services.AddInfrastructure(configuration);
|
|
var provider = services.BuildServiceProvider();
|
|
var authService = provider.GetRequiredService<IAuthService>();
|
|
|
|
// Assert
|
|
authService.ShouldBeOfType<LdapAuthService>();
|
|
}
|
|
|
|
[Fact]
|
|
public void AddInfrastructure_WithNoAuthConfig_RegistersLdapAuthServiceByDefault()
|
|
{
|
|
// Arrange
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
|
|
var configuration = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["Ldap:ServerUrls:0"] = "ldap://localhost:389",
|
|
["Ldap:SearchBase"] = "DC=example,DC=com"
|
|
})
|
|
.Build();
|
|
|
|
// Act
|
|
services.AddInfrastructure(configuration);
|
|
var provider = services.BuildServiceProvider();
|
|
var authService = provider.GetRequiredService<IAuthService>();
|
|
|
|
// Assert
|
|
authService.ShouldBeOfType<LdapAuthService>();
|
|
}
|
|
}
|