Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add business rules architecture tests #72

Merged
merged 3 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,18 @@

public sealed class ContractsArchitectureTests
{
private readonly Assembly _solution = typeof(Program).Assembly;

[Theory]
[InlineData(Modules.Passes)]
[InlineData(Modules.Offers)]
[InlineData(Modules.Reports)]
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);

Expand Down
1 change: 1 addition & 0 deletions Chapter-1-initial-architecture/Src/Fitnet/Fitnet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ItemGroup>
<InternalsVisibleTo Include="EvolutionaryArchitecture.Fitnet.UnitTests" />
<InternalsVisibleTo Include="EvolutionaryArchitecture.Fitnet.IntegrationTests" />
<InternalsVisibleTo Include="EvolutionaryArchitecture.Fitnet.ArchitectureTests" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -22,6 +23,7 @@ public IDbConnection Create()
return _connection;
}

[ExcludeFromCodeCoverage]
public void Dispose()
{
if (_connection is { State: ConnectionState.Open })
Expand Down
Loading