Files
jdescopingtool/NEW/tests/JdeScoping.Api.Tests/Configuration/ServiceRegistrationTests.cs
T
Joseph Doherty 26ff8d9b4f Initial commit: JDE Scoping Tool migration project
Set up repository with legacy .NET Framework 4.8 source (OLD/),
new .NET 10 Blazor solution (NEW/), OpenSpec specifications,
documentation, and project configuration.
2026-01-02 07:43:29 -05:00

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>();
}
}