diff --git a/.github/workflows/codecoverage.yml b/.github/workflows/codecoverage.yml index 7d02dae..ffd8e0a 100644 --- a/.github/workflows/codecoverage.yml +++ b/.github/workflows/codecoverage.yml @@ -33,6 +33,7 @@ jobs: run: | echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" dotnet run --project "EstateReportingAPI.Tests\EstateReportingAPI.Tests.csproj" --configuration Release --no-build -- --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml --results-directory "./coverage/unit" + dotnet run --project "EstateReportingAPI.BusinessLogic.UnitTests\EstateReportingAPI.BusinessLogic.UnitTests.csproj" --configuration Release --no-build -- --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml --results-directory "./coverage/unit" - name: Build Docker Image run: docker build . --file EstateReportingAPI/Dockerfile --tag estatereportingapi:latest diff --git a/.github/workflows/nightlybuild.yml b/.github/workflows/nightlybuild.yml index 2196acf..a324341 100644 --- a/.github/workflows/nightlybuild.yml +++ b/.github/workflows/nightlybuild.yml @@ -39,6 +39,7 @@ jobs: run: | echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" dotnet run --project "EstateReportingAPI.Tests\EstateReportingAPI.Tests.csproj" --configuration Release --no-build -- --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml --results-directory "./coverage/unit" + dotnet run --project "EstateReportingAPI.BusinessLogic.UnitTests\EstateReportingAPI.BusinessLogic.UnitTests.csproj" --configuration Release --no-build -- --coverage --coverage-output-format cobertura --coverage-output coverage.cobertura.xml --results-directory "./coverage/unit" - name: Build Docker Image run: docker build . --file EstateReportingAPI/Dockerfile --tag estatereportingapi:latest diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 6916776..4a7404d 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -31,6 +31,7 @@ jobs: run: | echo "ASPNETCORE_ENVIRONMENT are > ${ASPNETCORE_ENVIRONMENT}" dotnet run --project "EstateReportingAPI.Tests\EstateReportingAPI.Tests.csproj" --configuration Release --no-build + dotnet run --project "EstateReportingAPI.BusinessLogic.UnitTests\EstateReportingAPI.BusinessLogic.UnitTests.csproj" --configuration Release --no-build - name: Run Integration Tests run: | diff --git a/Directory.Packages.props b/Directory.Packages.props index 4387e8e..e36daf7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,7 +10,7 @@ - + @@ -52,4 +52,4 @@ - \ No newline at end of file + diff --git a/EstateReportingAPI.BusinessLogic.UnitTests/EstateReportingAPI.BusinessLogic.UnitTests.csproj b/EstateReportingAPI.BusinessLogic.UnitTests/EstateReportingAPI.BusinessLogic.UnitTests.csproj index 5f04f9e..60be8a5 100644 --- a/EstateReportingAPI.BusinessLogic.UnitTests/EstateReportingAPI.BusinessLogic.UnitTests.csproj +++ b/EstateReportingAPI.BusinessLogic.UnitTests/EstateReportingAPI.BusinessLogic.UnitTests.csproj @@ -1,7 +1,9 @@ - net7.0 + net10.0 + Exe + true enable enable @@ -16,9 +18,9 @@ - + - + runtime; build; native; contentfiles; analyzers; buildtransitive all diff --git a/EstateReportingAPI.BusinessLogic.UnitTests/UnitTest1.cs b/EstateReportingAPI.BusinessLogic.UnitTests/UnitTest1.cs index 25541a0..d20a4f8 100644 --- a/EstateReportingAPI.BusinessLogic.UnitTests/UnitTest1.cs +++ b/EstateReportingAPI.BusinessLogic.UnitTests/UnitTest1.cs @@ -1,10 +1,15 @@ +using TransactionProcessor.Database.Contexts; +using TransactionProcessor.Database.Entities; +using EstateReportingAPI.BusinessLogic.Queries; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Shared.EntityFramework; +using Imposter.Abstractions; + +[assembly: GenerateImposter(typeof(Shared.EntityFramework.IDbContextResolver))] + namespace EstateReportingAPI.BusinessLogic.UnitTests { - using EstateManagement.Database.Contexts; - using EstateManagement.Database.Entities; - using Microsoft.EntityFrameworkCore; - using Microsoft.EntityFrameworkCore.Infrastructure; - using Moq; using Shouldly; public class ReportingManagerTests @@ -28,11 +33,11 @@ public class TestData{ public async Task ReportingManager_GetCalendarYears_YearsAreReturned(){ //Required properties '{'DayOfWeek', 'DayOfWeekShort', 'MonthNameLong', 'MonthNameShort', 'WeekNumberString', 'YearWeekNumber'}' - var options = new DbContextOptionsBuilder() + var options = new DbContextOptionsBuilder() .UseInMemoryDatabase(databaseName: "TestDatabase") .Options; - EstateManagementGenericContext context = new EstateManagementSqlServerContext(options); + EstateManagementContext context = new EstateManagementContext(options); await context.Database.EnsureCreatedAsync(); await context.Calendar.AddRangeAsync(new Calendar{ @@ -68,17 +73,20 @@ await context.Calendar.AddRangeAsync(new Calendar{ Year = 2021 }); await context.SaveChangesAsync(); - Mock> resolver = new Mock>(); - resolver.Setup(r => r.GetContext(It.IsAny(), It.IsAny(), It.IsAny())).ReturnsAsync(context); + var services = new ServiceCollection() + .AddDbContext(builder => builder.UseInMemoryDatabase("TestDatabase")) + .BuildServiceProvider(); + var resolver = new IDbContextResolverImposter(); + resolver.Resolve(Arg.Any(), Arg.Any()).Returns(new ResolvedDbContext(services.CreateScope())); - var manager = new ReportingManager(resolver.Object); + var manager = new ReportingManager(resolver.Instance()); - var years = await manager.GetCalendarYears(TestData.EstateId, CancellationToken.None); + var years = await manager.GetCalendarYears(new CalendarQueries.GetYearsQuery(TestData.EstateId), CancellationToken.None); - years.Count.ShouldBe(3); - years.ShouldContain(2021); - years.ShouldContain(2022); - years.ShouldContain(2023); + years.Data.Count.ShouldBe(3); + years.Data.ShouldContain(2021); + years.Data.ShouldContain(2022); + years.Data.ShouldContain(2023); } } } diff --git a/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj b/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj index 9fd8de3..1a152fa 100644 --- a/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj +++ b/EstateReportingAPI.Tests/EstateReportingAPI.Tests.csproj @@ -19,7 +19,6 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - diff --git a/EstateReportingAPI.sln b/EstateReportingAPI.sln index 96964f1..150f624 100644 --- a/EstateReportingAPI.sln +++ b/EstateReportingAPI.sln @@ -21,6 +21,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EstateReportingAPI.Models", EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EstateReportingAPI.IntegrationTests", "EstateReportingAPI.IntegrationTests\EstateReportingAPI.IntegrationTests.csproj", "{85555B3A-FC04-4291-B0CB-F0835AC23D3E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EstateReportingAPI.BusinessLogic.UnitTests", "EstateReportingAPI.BusinessLogic.UnitTests\EstateReportingAPI.BusinessLogic.UnitTests.csproj", "{E92B7A1C-4D67-4A0E-9D31-8B6D2F3C5A70}" +EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A296632F-ABDB-4D3E-9351-51346C70C08A}" EndProject Global @@ -57,6 +59,10 @@ Global {85555B3A-FC04-4291-B0CB-F0835AC23D3E}.Debug|Any CPU.Build.0 = Debug|Any CPU {85555B3A-FC04-4291-B0CB-F0835AC23D3E}.Release|Any CPU.ActiveCfg = Release|Any CPU {85555B3A-FC04-4291-B0CB-F0835AC23D3E}.Release|Any CPU.Build.0 = Release|Any CPU + {E92B7A1C-4D67-4A0E-9D31-8B6D2F3C5A70}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E92B7A1C-4D67-4A0E-9D31-8B6D2F3C5A70}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E92B7A1C-4D67-4A0E-9D31-8B6D2F3C5A70}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E92B7A1C-4D67-4A0E-9D31-8B6D2F3C5A70}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -69,6 +75,7 @@ Global {B71070E8-85FC-4C22-BF94-4E56D477466F} = {713556C8-BFC0-4AB6-8F13-7631C1C82D07} {B3BE4743-D80E-4247-BAC0-1224D5A6D472} = {713556C8-BFC0-4AB6-8F13-7631C1C82D07} {85555B3A-FC04-4291-B0CB-F0835AC23D3E} = {C48C544B-7C3B-4AA2-8A37-E49296A86499} + {E92B7A1C-4D67-4A0E-9D31-8B6D2F3C5A70} = {C48C544B-7C3B-4AA2-8A37-E49296A86499} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B2BE269B-F142-45A3-9B75-483227C765A6}