72 lines
2.9 KiB
C#
72 lines
2.9 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using NTP.Application;
|
|
using NTP.Application.Abstractions;
|
|
using NTP.Application.Refinery.Integrations;
|
|
using NTP.Application.Refinery.RemainingBalance;
|
|
using NTP.Application.Refinery.Trips;
|
|
using NTP.Infrastructure;
|
|
using NTP.Infrastructure.Integrations;
|
|
|
|
namespace NTP.Tests.Refinery;
|
|
|
|
/// <summary>The conventionally registered services of the trips slice and the Dinarak gateway resolve (no connection is opened).</summary>
|
|
public class TripsWiringTests
|
|
{
|
|
private static ServiceProvider Build(bool dinarak = false)
|
|
{
|
|
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",
|
|
["Refinery:Dinarak:Enabled"] = dinarak ? "true" : "false",
|
|
["Refinery:Trips:MaxPaymentAmount"] = "250",
|
|
}).Build();
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
services.AddSingleton<IConfiguration>(cfg);
|
|
services.AddApplication();
|
|
services.AddInfrastructure(cfg);
|
|
services.AddHttpContextAccessor();
|
|
services.AddScoped<ICurrentUser>(_ => null!);
|
|
return services.BuildServiceProvider();
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(typeof(ITripQueryService))]
|
|
[InlineData(typeof(ITripActionService))]
|
|
[InlineData(typeof(ITripReportService))]
|
|
[InlineData(typeof(ITripAmountsService))]
|
|
[InlineData(typeof(IRemainingBalanceService))]
|
|
[InlineData(typeof(ITripRepository))]
|
|
[InlineData(typeof(IVoucherSerialRepository))]
|
|
[InlineData(typeof(IDinarakGateway))]
|
|
[InlineData(typeof(IDinarakReferenceGateway))]
|
|
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_and_dinarak_is_off_by_default()
|
|
{
|
|
using var sp = Build();
|
|
using var scope = sp.CreateScope();
|
|
Assert.Equal(250m, scope.ServiceProvider.GetRequiredService<ITripSettingsService>().Value.MaxPaymentAmount);
|
|
Assert.False(scope.ServiceProvider.GetRequiredService<Microsoft.Extensions.Options.IOptions<DinarakOptions>>().Value.Enabled);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Disabled_gateway_answers_106_without_touching_the_database()
|
|
{
|
|
using var sp = Build();
|
|
using var scope = sp.CreateScope();
|
|
var r = await scope.ServiceProvider.GetRequiredService<IDinarakGateway>().TransferAsync(1, "795000000", "1", 5m, "x");
|
|
Assert.Equal("106", r.Code);
|
|
var s = await scope.ServiceProvider.GetRequiredService<IDinarakReferenceGateway>().GetTransferByReferenceAsync(1.1m);
|
|
Assert.Equal("DISABLED", s.StatusName);
|
|
}
|
|
}
|