Skip to content

Commit

Permalink
Architecture tests for other modules (Payments, Administration, UserA…
Browse files Browse the repository at this point in the history
…ccess).
  • Loading branch information
kgrzybek committed Nov 24, 2019
1 parent b44ffa9 commit 22f84e0
Show file tree
Hide file tree
Showing 59 changed files with 1,650 additions and 107 deletions.

This file was deleted.

47 changes: 34 additions & 13 deletions src/CompanyName.MyMeetings.sln
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,17 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{237A249C
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompanyName.MyMeetings.Modules.Meetings.Domain.UnitTests", "Modules\Meetings\Tests\UnitTests\CompanyName.MyMeetings.Modules.Meetings.Domain.UnitTests.csproj", "{E13970C6-87EE-40B1-854A-3053C95BC4C9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompanyName.MyMeetings.Modules.Meetings.ArchitectureTests", "CompanyName.MyMeetings.Modules.Meetings.ArchitectureTests\CompanyName.MyMeetings.Modules.Meetings.ArchitectureTests.csproj", "{842B8E3E-425D-45B0-8676-7F3EE1DDAF13}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{8B08A9EE-CE27-4CC3-ACB3-3BD9628E5479}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompanyName.MyMeetings.ArchitectureTests", "CompanyName.MyMeetings.ArchitectureTests\CompanyName.MyMeetings.ArchitectureTests.csproj", "{7AF71F45-8727-4F54-8DD7-2710A647A175}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompanyName.MyMeetings.ArchTests", "Tests\ArchTests\CompanyName.MyMeetings.ArchTests.csproj", "{88081DDB-2FBD-4F7D-830F-24F5F6B78294}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompanyName.MyMeetings.Modules.Administration.ArchTests", "Modules\Administration\Tests\ArchTests\CompanyName.MyMeetings.Modules.Administration.ArchTests.csproj", "{F2B164AC-99AC-4906-A133-85D6BB8432B4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompanyName.MyMeetings.Modules.Meetings.ArchTests", "Modules\Meetings\Tests\ArchTests\CompanyName.MyMeetings.Modules.Meetings.ArchTests.csproj", "{475AF987-1458-447E-8504-4F1040B56A2C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompanyName.MyMeetings.Modules.Payments.ArchTests", "Modules\Payments\Tests\ArchTests\CompanyName.MyMeetings.Modules.Payments.ArchTests.csproj", "{1885C71E-1624-4673-B0BC-BF4035CFFE72}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CompanyName.MyMeetings.Modules.UserAccess.ArchTests", "Modules\UserAccess\Tests\ArchTests\CompanyName.MyMeetings.Modules.UserAccess.ArchTests.csproj", "{F8EE61DA-0E8B-4074-A0AF-433244EC1FB8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -201,14 +207,26 @@ Global
{E13970C6-87EE-40B1-854A-3053C95BC4C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E13970C6-87EE-40B1-854A-3053C95BC4C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E13970C6-87EE-40B1-854A-3053C95BC4C9}.Release|Any CPU.Build.0 = Release|Any CPU
{842B8E3E-425D-45B0-8676-7F3EE1DDAF13}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{842B8E3E-425D-45B0-8676-7F3EE1DDAF13}.Debug|Any CPU.Build.0 = Debug|Any CPU
{842B8E3E-425D-45B0-8676-7F3EE1DDAF13}.Release|Any CPU.ActiveCfg = Release|Any CPU
{842B8E3E-425D-45B0-8676-7F3EE1DDAF13}.Release|Any CPU.Build.0 = Release|Any CPU
{7AF71F45-8727-4F54-8DD7-2710A647A175}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7AF71F45-8727-4F54-8DD7-2710A647A175}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7AF71F45-8727-4F54-8DD7-2710A647A175}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7AF71F45-8727-4F54-8DD7-2710A647A175}.Release|Any CPU.Build.0 = Release|Any CPU
{88081DDB-2FBD-4F7D-830F-24F5F6B78294}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88081DDB-2FBD-4F7D-830F-24F5F6B78294}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88081DDB-2FBD-4F7D-830F-24F5F6B78294}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88081DDB-2FBD-4F7D-830F-24F5F6B78294}.Release|Any CPU.Build.0 = Release|Any CPU
{F2B164AC-99AC-4906-A133-85D6BB8432B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F2B164AC-99AC-4906-A133-85D6BB8432B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F2B164AC-99AC-4906-A133-85D6BB8432B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F2B164AC-99AC-4906-A133-85D6BB8432B4}.Release|Any CPU.Build.0 = Release|Any CPU
{475AF987-1458-447E-8504-4F1040B56A2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{475AF987-1458-447E-8504-4F1040B56A2C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{475AF987-1458-447E-8504-4F1040B56A2C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{475AF987-1458-447E-8504-4F1040B56A2C}.Release|Any CPU.Build.0 = Release|Any CPU
{1885C71E-1624-4673-B0BC-BF4035CFFE72}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1885C71E-1624-4673-B0BC-BF4035CFFE72}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1885C71E-1624-4673-B0BC-BF4035CFFE72}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1885C71E-1624-4673-B0BC-BF4035CFFE72}.Release|Any CPU.Build.0 = Release|Any CPU
{F8EE61DA-0E8B-4074-A0AF-433244EC1FB8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F8EE61DA-0E8B-4074-A0AF-433244EC1FB8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F8EE61DA-0E8B-4074-A0AF-433244EC1FB8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F8EE61DA-0E8B-4074-A0AF-433244EC1FB8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -248,8 +266,11 @@ Global
{AC73F391-BC1F-4B7F-AF49-BD87223E2BB0} = {F544D6DA-740A-4313-9542-D989666EA9DE}
{237A249C-B589-49B8-9B84-CA504DE5D137} = {9CD43CAC-C149-41E1-9654-157D578143B7}
{E13970C6-87EE-40B1-854A-3053C95BC4C9} = {237A249C-B589-49B8-9B84-CA504DE5D137}
{842B8E3E-425D-45B0-8676-7F3EE1DDAF13} = {237A249C-B589-49B8-9B84-CA504DE5D137}
{7AF71F45-8727-4F54-8DD7-2710A647A175} = {8B08A9EE-CE27-4CC3-ACB3-3BD9628E5479}
{88081DDB-2FBD-4F7D-830F-24F5F6B78294} = {8B08A9EE-CE27-4CC3-ACB3-3BD9628E5479}
{F2B164AC-99AC-4906-A133-85D6BB8432B4} = {F544D6DA-740A-4313-9542-D989666EA9DE}
{475AF987-1458-447E-8504-4F1040B56A2C} = {237A249C-B589-49B8-9B84-CA504DE5D137}
{1885C71E-1624-4673-B0BC-BF4035CFFE72} = {53E4F002-E708-45F7-8444-19EB8977B5C9}
{F8EE61DA-0E8B-4074-A0AF-433244EC1FB8} = {0FF699EF-8156-43CB-8D18-8EA28F30E9EE}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6B94C21A-AA6D-4D82-963E-C69C0353B938}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using CompanyName.MyMeetings.Modules.Administration.Application.Contracts;
using MediatR;

namespace CompanyName.MyMeetings.Modules.Administration.Application.Configuration.Processing
{
public interface IQueryHandler<in TQuery, TResult> :
IRequestHandler<TQuery, TResult> where TQuery : IQuery<TResult>
{

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace CompanyName.MyMeetings.Modules.Administration.Application.Configuration.Processing.Inbox
{
internal class ProcessInboxCommandHandler : IRequestHandler<ProcessInboxCommand>
internal class ProcessInboxCommandHandler : ICommandHandler<ProcessInboxCommand>
{
private readonly IMediator _mediator;
private readonly ISqlConnectionFactory _sqlConnectionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace CompanyName.MyMeetings.Modules.Administration.Application.Configuration.Processing.InternalCommands
{
internal abstract class InternalCommandBase : ICommand
public abstract class InternalCommandBase : ICommand
{
public Guid Id { get; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace CompanyName.MyMeetings.Modules.Administration.Application.Configuration.Processing.InternalCommands
{
internal class ProcessInternalCommandsCommandHandler : IRequestHandler<ProcessInternalCommandsCommand>
internal class ProcessInternalCommandsCommandHandler : ICommandHandler<ProcessInternalCommandsCommand>
{
private readonly ISqlConnectionFactory _sqlConnectionFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace CompanyName.MyMeetings.Modules.Administration.Application.Configuration.Processing.Outbox
{
public class ProcessOutboxCommandHandler : IRequestHandler<ProcessOutboxCommand>
internal class ProcessOutboxCommandHandler : ICommandHandler<ProcessOutboxCommand>
{
private readonly IMediator _mediator;
private readonly ISqlConnectionFactory _sqlConnectionFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace CompanyName.MyMeetings.Modules.Administration.Application.Configuration.Processing
{
public class UnitOfWorkCommandHandlerDecorator<T> : ICommandHandler<T> where T:ICommand
internal class UnitOfWorkCommandHandlerDecorator<T> : ICommandHandler<T> where T:ICommand
{
private readonly ICommandHandler<T> _decorated;
private readonly IUnitOfWork _unitOfWork;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class RequestMeetingGroupProposalVerificationCommand : InternalCommandB
public DateTime ProposalDate { get; }

[JsonConstructor]
public RequestMeetingGroupProposalVerificationCommand(
internal RequestMeetingGroupProposalVerificationCommand(
Guid id,
Guid meetingGroupProposalId,
string name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public async Task<Unit> Handle(RequestMeetingGroupProposalVerificationCommand re
request.MeetingGroupProposalId,
request.Name,
request.Description,
new MeetingGroupLocation(request.LocationCity, request.LocationCountryCode),
MeetingGroupLocation.Create(request.LocationCity, request.LocationCountryCode),
new UserId(request.ProposalUserId),
request.ProposalDate
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ namespace CompanyName.MyMeetings.Modules.Administration.Domain.MeetingGroupPropo
{
public class MeetingGroupLocation : ValueObject
{
public MeetingGroupLocation(string city, string countryCode)
private MeetingGroupLocation(string city, string countryCode)
{
City = city;
CountryCode = countryCode;
}

public static MeetingGroupLocation Create(string city, string countryCode)
{
return new MeetingGroupLocation(city, countryCode);
}

public string City { get; }

public string CountryCode { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ internal MeetingGroupProposalStatus GetStatusForDecision()
{
if (this.IsAccepted)
{
return new MeetingGroupProposalStatus("Verified");
return MeetingGroupProposalStatus.Create("Verified");
}

if (this.IsRejected)
{
return new MeetingGroupProposalStatus("Rejected");
return MeetingGroupProposalStatus.Create("Rejected");
}

return MeetingGroupProposalStatus.ToVerify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ public class MeetingGroupProposalStatus : ValueObject

public string Value { get; }

internal MeetingGroupProposalStatus(string value)
private MeetingGroupProposalStatus(string value)
{
Value = value;
}

internal static MeetingGroupProposalStatus Create(string value)
{
return new MeetingGroupProposalStatus(value);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using CompanyName.MyMeetings.Modules.Administration.Application.Configuration.Processing;
using CompanyName.MyMeetings.Modules.Administration.Application.Configuration.Processing.InternalCommands;
using CompanyName.MyMeetings.Modules.Administration.Application.Contracts;
using CompanyName.MyMeetings.Modules.Administration.ArchTests.SeedWork;
using MediatR;
using NetArchTest.Rules;
using Newtonsoft.Json;
using NUnit.Framework;

namespace CompanyName.MyMeetings.Modules.Administration.ArchTests.Application
{
[TestFixture]
public class ApplicationTests : TestBase
{
[Test]
public void Command_Should_Be_Immutable()
{
var types = Types.InAssembly(ApplicationAssembly)
.That().Inherit(typeof(CommandBase))
.Or().Inherit(typeof(InternalCommandBase))
.Or().ImplementInterface(typeof(ICommand))
.Or().ImplementInterface(typeof(ICommand<>))
.GetTypes();

AssertAreImmutable(types);
}

[Test]
public void Query_Should_Be_Immutable()
{
var types = Types.InAssembly(ApplicationAssembly)
.That().ImplementInterface(typeof(IQuery<>)).GetTypes();

AssertAreImmutable(types);
}

[Test]
public void CommandHandler_Should_Have_Name_EndingWith_CommandHandler()
{
var result = Types.InAssembly(ApplicationAssembly)
.That()
.ImplementInterface(typeof(ICommandHandler<>))
.And()
.DoNotHaveNameMatching(".*Decorator.*").Should()
.HaveNameEndingWith("CommandHandler")
.GetResult();

AssertArchTestResult(result);
}

[Test]
public void QueryHandler_Should_Have_Name_EndingWith_QueryHandler()
{
var result = Types.InAssembly(ApplicationAssembly)
.That()
.ImplementInterface(typeof(IQueryHandler<,>))
.Should()
.HaveNameEndingWith("QueryHandler")
.GetResult();

AssertArchTestResult(result);
}

[Test]
public void InternalCommands_Should_Not_Be_Public()
{
var result = Types.InAssembly(ApplicationAssembly)
.That()
.Inherit(typeof(InternalCommandBase))
.Should()
.NotBePublic()
.GetResult();

AssertArchTestResult(result);
}

[Test]
public void Command_And_Query_Handlers_Should_Not_Be_Public()
{
var types = Types.InAssembly(ApplicationAssembly)
.That()
.ImplementInterface(typeof(IQueryHandler<,>))
.Or()
.ImplementInterface(typeof(ICommandHandler<>))
.Should().NotBePublic().GetResult().FailingTypes;

AssertFailingTypes(types);
}

[Test]
public void InternalCommand_Should_Have_Internal_Constructor_With_JsonConstructorAttribute()
{
var types = Types.InAssembly(ApplicationAssembly)
.That().Inherit(typeof(InternalCommandBase)).GetTypes();

var failingTypes = new List<Type>();

foreach (var type in types)
{
bool hasJsonConstructorDefined = false;
var constructors = type.GetConstructors(BindingFlags.NonPublic | BindingFlags.Instance);
foreach (var constructorInfo in constructors)
{
var jsonConstructorAttribute = constructorInfo.GetCustomAttributes(typeof(JsonConstructorAttribute), false);
if (jsonConstructorAttribute.Length > 0)
{
hasJsonConstructorDefined = true;
break;
}
}

if (!hasJsonConstructorDefined)
{
failingTypes.Add(type);
}
}

AssertFailingTypes(failingTypes);
}

[Test]
public void MediatR_RequestHandler_Should_NotBe_Used_Directly()
{
var types = Types.InAssembly(ApplicationAssembly)
.That().DoNotHaveName("ICommandHandler`1")
.Should().ImplementInterface(typeof(IRequestHandler<>))
.GetTypes();

List<Type> failingTypes = new List<Type>();
foreach (var type in types)
{
bool isCommandHandler = type.GetInterfaces().Any(x =>
x.IsGenericType &&
x.GetGenericTypeDefinition() == typeof(ICommandHandler<>));
bool isQueryHandler = type.GetInterfaces().Any(x =>
x.IsGenericType &&
x.GetGenericTypeDefinition() == typeof(IQueryHandler<,>));
if (!isCommandHandler && !isQueryHandler)
{
failingTypes.Add(type);
}
}

AssertFailingTypes(failingTypes);
}
}
}
Loading

0 comments on commit 22f84e0

Please sign in to comment.