51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NTP.Application;
|
|
using NTP.Application.Abstractions;
|
|
using NTP.Application.Grains.Permits;
|
|
using NTP.Infrastructure;
|
|
|
|
namespace NTP.Tests;
|
|
|
|
/// <summary>Proves that the conventionally registered services/repositories of the permits slice resolve (no connection is opened).</summary>
|
|
public class PermitsWiringTests
|
|
{
|
|
private static ServiceProvider Build()
|
|
{
|
|
var cfg = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["ConnectionStrings:NAFITHTCS"] = "User Id=x;Password=x;Data Source=localhost:1521/x",
|
|
["ConnectionStrings:NtpSchema"] = "User Id=x;Password=x;Data Source=localhost:1521/x",
|
|
["Grains:Permits:BadiyaScac"] = "327",
|
|
}).Build();
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
services.AddSingleton<IConfiguration>(cfg);
|
|
services.AddApplication();
|
|
services.AddInfrastructure(cfg);
|
|
services.AddScoped<ICurrentUser>(_ => null!);
|
|
return services.BuildServiceProvider();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(typeof(IPermitService))]
|
|
[InlineData(typeof(IQueueService))]
|
|
[InlineData(typeof(IDestinationService))]
|
|
[InlineData(typeof(IDistributionService))]
|
|
[InlineData(typeof(IWeighbridgeService))]
|
|
public void Services_resolve(Type service)
|
|
{
|
|
using var sp = Build();
|
|
using var scope = sp.CreateScope();
|
|
Assert.NotNull(scope.ServiceProvider.GetRequiredService(service));
|
|
}
|
|
|
|
[Fact]
|
|
public void Settings_are_bound_from_configuration()
|
|
{
|
|
using var sp = Build();
|
|
using var scope = sp.CreateScope();
|
|
Assert.Equal(327, scope.ServiceProvider.GetRequiredService<IGrainsPermitsSettingsService>().Value.BadiyaScac);
|
|
}
|
|
}
|