shoc-backend/Api.SeaHavenIndustries.Tests/ServiceRegistrationTests.cs
2026-07-24 10:27:35 -03:00

57 lines
2.2 KiB
C#

using Data.SeaHavenIndustries;
using FluentAssertions;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
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.AddDbContext<ApplicationDbContext>(options =>
options.UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>();
services.AddDataServices();
services.AddBusinessServices();
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>();
}
}