diff --git a/Chapter-1-initial-architecture/Src/Fitnet.ArchitectureTests/BussinessRulesArchitectureTests.cs b/Chapter-1-initial-architecture/Src/Fitnet.ArchitectureTests/BussinessRulesArchitectureTests.cs new file mode 100644 index 00000000..e7ef173d --- /dev/null +++ b/Chapter-1-initial-architecture/Src/Fitnet.ArchitectureTests/BussinessRulesArchitectureTests.cs @@ -0,0 +1,26 @@ +namespace EvolutionaryArchitecture.Fitnet.ArchitectureTests; + +using Common; +using Fitnet.Common.BusinessRulesEngine; + +public class BusinessRulesArchitectureTests +{ + [Theory] + [InlineData("Endpoint")] + [InlineData("Consumer")] + internal void BusinessRules_Should_Not_Have_Dependency_On_Module(string forbiddenTypeEnding) + { + // Arrange + var businessRules = Solution.Types.That().ImplementInterface(typeof(IBusinessRule)).GetModuleTypes(); + var forbiddenTypes = Solution + .Types + .That() + .HaveNameEndingWith(forbiddenTypeEnding); + + // Act + var validationResult = forbiddenTypes!.Should().NotHaveDependencyOnAny(businessRules).GetResult(); + + // Assert + validationResult.FailingTypes.Should().BeNull(); + } +} diff --git a/Chapter-1-initial-architecture/Src/Fitnet.ArchitectureTests/ContractsArchitectureTests.cs b/Chapter-1-initial-architecture/Src/Fitnet.ArchitectureTests/ContractsArchitectureTests.cs index fa274605..745126f8 100644 --- a/Chapter-1-initial-architecture/Src/Fitnet.ArchitectureTests/ContractsArchitectureTests.cs +++ b/Chapter-1-initial-architecture/Src/Fitnet.ArchitectureTests/ContractsArchitectureTests.cs @@ -4,8 +4,6 @@ public sealed class ContractsArchitectureTests { - private readonly Assembly _solution = typeof(Program).Assembly; - [Theory] [InlineData(Modules.Passes)] [InlineData(Modules.Offers)] @@ -13,11 +11,11 @@ public sealed class ContractsArchitectureTests internal void Contracts_should_not_have_dependency_on_module(string moduleName) { // Arrange - var contractsModule = Types.InAssembly(_solution) + var contractsModule = Solution.Types .That() .ResideInNamespace(Modules.Contracts); - var forbiddenModule = Types.InAssembly(_solution) + var forbiddenModule = Solution.Types .That() .ResideInNamespace(moduleName); var forbiddenModuleTypes = forbiddenModule.GetModuleTypes(); diff --git a/Chapter-1-initial-architecture/Src/Fitnet/Contracts/SignContract/SignContractEndpoint.cs b/Chapter-1-initial-architecture/Src/Fitnet/Contracts/SignContract/SignContractEndpoint.cs index 3b53f5b4..84ed99ce 100644 --- a/Chapter-1-initial-architecture/Src/Fitnet/Contracts/SignContract/SignContractEndpoint.cs +++ b/Chapter-1-initial-architecture/Src/Fitnet/Contracts/SignContract/SignContractEndpoint.cs @@ -4,6 +4,7 @@ namespace EvolutionaryArchitecture.Fitnet.Contracts.SignContract; using Events; using EvolutionaryArchitecture.Fitnet.Common.Events.EventBus; using Common.Validation.Requests; +using PrepareContract.BusinessRules; internal static class SignContractEndpoint { @@ -14,6 +15,11 @@ internal static void MapSignContract(this IEndpointRouteBuilder app) => app.MapP TimeProvider timeProvider, CancellationToken cancellationToken) => { + var test = new ContractCanBePreparedOnlyForAdultRule(10); +#pragma warning disable S1481 + var _ = test.Error; +#pragma warning restore S1481 + var contract = await persistence.Contracts.FindAsync(new object[] { id }, cancellationToken: cancellationToken); diff --git a/Chapter-1-initial-architecture/Src/Fitnet/Fitnet.csproj b/Chapter-1-initial-architecture/Src/Fitnet/Fitnet.csproj index df162f68..6123cb1e 100644 --- a/Chapter-1-initial-architecture/Src/Fitnet/Fitnet.csproj +++ b/Chapter-1-initial-architecture/Src/Fitnet/Fitnet.csproj @@ -20,6 +20,7 @@ + diff --git a/Chapter-2-modules-separation/Src/Reports/Fitnet.Reports/DataAccess/DatabaseConnectionFactory.cs b/Chapter-2-modules-separation/Src/Reports/Fitnet.Reports/DataAccess/DatabaseConnectionFactory.cs index 3e786ab5..a10b770d 100644 --- a/Chapter-2-modules-separation/Src/Reports/Fitnet.Reports/DataAccess/DatabaseConnectionFactory.cs +++ b/Chapter-2-modules-separation/Src/Reports/Fitnet.Reports/DataAccess/DatabaseConnectionFactory.cs @@ -2,6 +2,7 @@ namespace EvolutionaryArchitecture.Fitnet.Reports.DataAccess; using Microsoft.Extensions.Configuration; using System.Data; +using System.Diagnostics.CodeAnalysis; using Npgsql; internal sealed class DatabaseConnectionFactory(IConfiguration configuration) : IDatabaseConnectionFactory @@ -22,6 +23,7 @@ public IDbConnection Create() return _connection; } + [ExcludeFromCodeCoverage] public void Dispose() { if (_connection is { State: ConnectionState.Open })