using Data.SeaHavenIndustries; using FluentAssertions; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using SeaHaven.DataServices.DependencyInjection; using SeaHaven.DataServices.Implementation; using SeaHaven.DataServices.Interfaces; using SeaHaven.Services.DependencyInjection; using SeaHaven.Services.Implementation; using SeaHaven.Services.Interfaces; using Xunit; namespace Api.SeaHavenIndustries.Tests; public class ServiceRegistrationTests { private static ServiceProvider BuildProvider() { var services = new ServiceCollection(); services.AddLogging(); services.AddSingleton(new ConfigurationBuilder().Build()); services.AddSingleton(_ => new DummyZipCodeDistance()); services.AddSingleton(_ => new DummyEmailSender()); services.AddDbContext(options => options.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString())); services.AddIdentity() .AddEntityFrameworkStores(); services.AddDataServices(); services.AddBusinessServices(); return services.BuildServiceProvider(); } [Fact] public void ConventionDi_RegistersAllFiveFeatureServices() { using var provider = BuildProvider(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); } [Fact] public void ConventionDi_RegistersFeatureDataServices() { using var provider = BuildProvider(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); } [Fact] public void ConventionDi_RegistersFollowUpLocationDispatchSettingsServices() { using var provider = BuildProvider(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); } [Fact] public void ConventionDi_RegistersFollowUpLocationDispatchSettingsDataServices() { using var provider = BuildProvider(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); } [Fact] public void ConventionDi_RegistersVendorAndUpliftServices() { using var provider = BuildProvider(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService() .Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); } [Fact] public void ConventionDi_RegistersVendorAndUpliftDataServices() { using var provider = BuildProvider(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); provider.GetRequiredService().Should().BeOfType(); } private sealed class DummyZipCodeDistance : IZipCodeDistance { public double? GetDistanceMiles(string? zip1, string? zip2) => null; } private sealed class DummyEmailSender : IEmailSender { public Task SendEmailAsync(string emailTo, string subject, string body) => Task.FromResult(true); } }