forked from kgrzybek/modular-monolith-with-ddd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Architecture tests for other modules (Payments, Administration, UserA…
…ccess).
- Loading branch information
Showing
59 changed files
with
1,650 additions
and
107 deletions.
There are no files selected for viewing
37 changes: 0 additions & 37 deletions
37
src/CompanyName.MyMeetings.ArchitectureTests/CompanyName.MyMeetings.ArchitectureTests.csproj
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/Modules/Administration/Application/Configuration/Processing/IQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
src/Modules/Administration/Tests/ArchTests/Application/ApplicationTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.