Files
jdescopingtool/NEW/tests/JdeScoping.Api.Tests/Configuration/ServiceRegistrationTests.cs
T

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?>
{
["Ldap: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>();
}
}