mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-10-07 16:19:07 +00:00
117 lines
4.9 KiB
C#
117 lines
4.9 KiB
C#
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 configuration = new ConfigurationBuilder().Build();
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
services.AddSingleton<IConfiguration>(configuration);
|
|
services.AddSingleton<IZipCodeDistance>(_ => new DummyZipCodeDistance());
|
|
services.AddSingleton<IEmailSender>(_ => new DummyEmailSender());
|
|
|
|
services.AddDbContext<ApplicationDbContext>(options =>
|
|
options.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()));
|
|
|
|
services.AddIdentity<ApplicationUser, IdentityRole>()
|
|
.AddEntityFrameworkStores<ApplicationDbContext>();
|
|
|
|
services.AddDataServices();
|
|
services.AddBusinessServices(configuration);
|
|
|
|
return services.BuildServiceProvider();
|
|
}
|
|
|
|
[Fact]
|
|
public void ConventionDi_RegistersAllFiveFeatureServices()
|
|
{
|
|
using var provider = BuildProvider();
|
|
|
|
provider.GetRequiredService<ICalendarService>().Should().BeOfType<CalendarService>();
|
|
provider.GetRequiredService<ICommonService>().Should().BeOfType<CommonService>();
|
|
provider.GetRequiredService<IDashboardService>().Should().BeOfType<DashboardService>();
|
|
provider.GetRequiredService<IDropdownOptionsService>().Should().BeOfType<DropdownOptionsService>();
|
|
provider.GetRequiredService<ITaskListTemplateService>().Should().BeOfType<TaskListTemplateService>();
|
|
}
|
|
|
|
[Fact]
|
|
public void ConventionDi_RegistersFeatureDataServices()
|
|
{
|
|
using var provider = BuildProvider();
|
|
|
|
provider.GetRequiredService<ICalendarDataService>().Should().BeOfType<CalendarDataService>();
|
|
provider.GetRequiredService<ICommonDataService>().Should().BeOfType<CommonDataService>();
|
|
provider.GetRequiredService<IDashboardDataService>().Should().BeOfType<DashboardDataService>();
|
|
provider.GetRequiredService<IDropdownOptionsDataService>().Should().BeOfType<DropdownOptionsDataService>();
|
|
}
|
|
|
|
[Fact]
|
|
public void ConventionDi_RegistersFollowUpLocationDispatchSettingsServices()
|
|
{
|
|
using var provider = BuildProvider();
|
|
|
|
provider.GetRequiredService<IFollowUpService>().Should().BeOfType<FollowUpService>();
|
|
provider.GetRequiredService<ILocationService>().Should().BeOfType<LocationService>();
|
|
provider.GetRequiredService<IDispatchService>().Should().BeOfType<DispatchService>();
|
|
provider.GetRequiredService<ISettingsService>().Should().BeOfType<SettingsService>();
|
|
}
|
|
|
|
[Fact]
|
|
public void ConventionDi_RegistersFollowUpLocationDispatchSettingsDataServices()
|
|
{
|
|
using var provider = BuildProvider();
|
|
|
|
provider.GetRequiredService<IFollowUpDataService>().Should().BeOfType<FollowUpDataService>();
|
|
provider.GetRequiredService<ILocationDataService>().Should().BeOfType<LocationDataService>();
|
|
provider.GetRequiredService<IDispatchDataService>().Should().BeOfType<DispatchDataService>();
|
|
provider.GetRequiredService<ISettingsDataService>().Should().BeOfType<SettingsDataService>();
|
|
}
|
|
|
|
[Fact]
|
|
public void ConventionDi_RegistersVendorAndUpliftServices()
|
|
{
|
|
using var provider = BuildProvider();
|
|
|
|
provider.GetRequiredService<IVendorService>().Should().BeOfType<VendorService>();
|
|
provider.GetRequiredService<IVendorPortalService>().Should().BeOfType<VendorPortalService>();
|
|
provider.GetRequiredService<IVendorPortalTokenService>()
|
|
.Should().BeOfType<SeaHaven.Services.Implementation.VendorPortalTokenService>();
|
|
provider.GetRequiredService<IUpliftService>().Should().BeOfType<UpliftService>();
|
|
}
|
|
|
|
[Fact]
|
|
public void ConventionDi_RegistersVendorAndUpliftDataServices()
|
|
{
|
|
using var provider = BuildProvider();
|
|
|
|
provider.GetRequiredService<IVendorDataService>().Should().BeOfType<VendorDataService>();
|
|
provider.GetRequiredService<IUpliftDataService>().Should().BeOfType<UpliftDataService>();
|
|
provider.GetRequiredService<ICommentDataService>().Should().BeOfType<CommentDataService>();
|
|
}
|
|
|
|
private sealed class DummyZipCodeDistance : IZipCodeDistance
|
|
{
|
|
public double? GetDistanceMiles(string? zip1, string? zip2) => null;
|
|
}
|
|
|
|
private sealed class DummyEmailSender : IEmailSender
|
|
{
|
|
public Task<bool> SendEmailAsync(string emailTo, string subject, string body) =>
|
|
Task.FromResult(true);
|
|
}
|
|
}
|