-
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.
Merge pull request #90 from wemogy/feat/remote-processing
Feat/remote processing
- Loading branch information
Showing
94 changed files
with
2,043 additions
and
598 deletions.
There are no files selected for viewing
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
Large diffs are not rendered by default.
Oops, something went wrong.
7 changes: 7 additions & 0 deletions
7
...emogy.CQRS.UnitTests.AssemblyA/Commands/PrintHelloAssemblyA/PrintHelloAssemblyACommand.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,7 @@ | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
|
||
namespace Wemogy.CQRS.UnitTests.AssemblyA.Commands.PrintHelloAssemblyA; | ||
|
||
public class PrintHelloAssemblyACommand : ICommand | ||
{ | ||
} |
17 changes: 17 additions & 0 deletions
17
...QRS.UnitTests.AssemblyA/Commands/PrintHelloAssemblyA/PrintHelloAssemblyACommandHandler.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,17 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
|
||
namespace Wemogy.CQRS.UnitTests.AssemblyA.Commands.PrintHelloAssemblyA; | ||
|
||
public class PrintHelloAssemblyACommandHandler : ICommandHandler<PrintHelloAssemblyACommand> | ||
{ | ||
public static int CallCount { get; private set; } | ||
|
||
public Task HandleAsync(PrintHelloAssemblyACommand command) | ||
{ | ||
Console.WriteLine("Hello from Assembly A!"); | ||
CallCount++; | ||
return Task.CompletedTask; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/core/Wemogy.CQRS.UnitTests.AssemblyA/DependencyInjection.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 Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Wemogy.CQRS.UnitTests.AssemblyA; | ||
|
||
public static class DependencyInjection | ||
{ | ||
public static void AddAssemblyA(this IServiceCollection services) | ||
{ | ||
services.AddCQRS(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...emogy.CQRS.UnitTests.AssemblyB/Commands/PrintHelloAssemblyB/PrintHelloAssemblyBCommand.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,7 @@ | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
|
||
namespace Wemogy.CQRS.UnitTests.AssemblyB.Commands.PrintHelloAssemblyB; | ||
|
||
public class PrintHelloAssemblyBCommand : ICommand | ||
{ | ||
} |
17 changes: 17 additions & 0 deletions
17
...QRS.UnitTests.AssemblyB/Commands/PrintHelloAssemblyB/PrintHelloAssemblyBCommandHandler.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,17 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
|
||
namespace Wemogy.CQRS.UnitTests.AssemblyB.Commands.PrintHelloAssemblyB; | ||
|
||
public class PrintHelloAssemblyBCommandHandler : ICommandHandler<PrintHelloAssemblyBCommand> | ||
{ | ||
public static int CallCount { get; private set; } | ||
|
||
public Task HandleAsync(PrintHelloAssemblyBCommand command) | ||
{ | ||
Console.WriteLine("Hello from Assembly B!"); | ||
CallCount++; | ||
return Task.CompletedTask; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/core/Wemogy.CQRS.UnitTests.AssemblyB/DependencyInjection.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 Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Wemogy.CQRS.UnitTests.AssemblyB; | ||
|
||
public static class DependencyInjection | ||
{ | ||
public static void AddAssemblyB(this IServiceCollection services) | ||
{ | ||
services.AddCQRS(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/core/Wemogy.CQRS.UnitTests.AssemblyB/Wemogy.CQRS.UnitTests.AssemblyB.csproj
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Wemogy.CQRS\Wemogy.CQRS.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
43 changes: 43 additions & 0 deletions
43
src/core/Wemogy.CQRS.UnitTests/DependencyInjectionTests.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,43 @@ | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
using Wemogy.CQRS.UnitTests.AssemblyA; | ||
using Wemogy.CQRS.UnitTests.AssemblyA.Commands.PrintHelloAssemblyA; | ||
using Wemogy.CQRS.UnitTests.AssemblyB; | ||
using Wemogy.CQRS.UnitTests.AssemblyB.Commands.PrintHelloAssemblyB; | ||
using Wemogy.CQRS.UnitTests.TestApplication.Commands.TrackUserLogin; | ||
using Xunit; | ||
|
||
namespace Wemogy.CQRS.UnitTests; | ||
|
||
public class DependencyInjectionTests | ||
{ | ||
[Fact] | ||
public async Task CallingAddCQRSMultipleTimesInDifferentAssembliesShouldWork() | ||
{ | ||
// Arrange | ||
var serviceCollection = new ServiceCollection(); | ||
serviceCollection.AddCQRS(); | ||
serviceCollection.AddAssemblyA(); | ||
serviceCollection.AddAssemblyB(); | ||
var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
var commands = serviceProvider.GetRequiredService<ICommands>(); | ||
var helloAssemblyACommand = new PrintHelloAssemblyACommand(); | ||
var helloAssemblyBCommand = new PrintHelloAssemblyBCommand(); | ||
var trackUserLoginCommand = new TrackUserLoginCommand("test-user-id"); | ||
|
||
// Act | ||
var trackUserLoginCommandException = await Record.ExceptionAsync(() => commands.RunAsync(trackUserLoginCommand)); | ||
var helloAssemblyACommandException = await Record.ExceptionAsync(() => commands.RunAsync(helloAssemblyACommand)); | ||
var helloAssemblyBCommandException = await Record.ExceptionAsync(() => commands.RunAsync(helloAssemblyBCommand)); | ||
|
||
// Assert | ||
TrackUserLoginCommandHandler.CallCount.Should().Be(1); | ||
trackUserLoginCommandException.Should().BeNull(); | ||
PrintHelloAssemblyACommandHandler.CallCount.Should().Be(1); | ||
helloAssemblyACommandException.Should().BeNull(); | ||
PrintHelloAssemblyBCommandHandler.CallCount.Should().Be(1); | ||
helloAssemblyBCommandException.Should().BeNull(); | ||
} | ||
} |
96 changes: 96 additions & 0 deletions
96
src/core/Wemogy.CQRS.UnitTests/Extensions/ServiceCollectionExtensionsTests.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,96 @@ | ||
using System.Linq; | ||
using System.Reflection; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
using Wemogy.CQRS.Extensions; | ||
using Wemogy.CQRS.UnitTests.TestApplication.Commands.CreateUser; | ||
using Wemogy.CQRS.UnitTests.TestApplication.Commands.KitchenSinkWithoutResult; | ||
using Wemogy.CQRS.UnitTests.TestApplication.Commands.KitchenSinkWithResult; | ||
using Wemogy.CQRS.UnitTests.TestApplication.Commands.RecalculateTotalUserCount; | ||
using Xunit; | ||
|
||
namespace Wemogy.CQRS.UnitTests.Extensions; | ||
|
||
public class ServiceCollectionExtensionsTests | ||
{ | ||
[Fact] | ||
public void AddImplementationsOfInterfaceScoped_ShouldWork() | ||
{ | ||
// Arrange | ||
var serviceCollection = new ServiceCollection(); | ||
var assemblies = new[] | ||
{ | ||
Assembly.GetExecutingAssembly(), | ||
Assembly.GetCallingAssembly() | ||
}.ToList(); | ||
|
||
// Act | ||
serviceCollection.AddImplementationsOfGenericInterfaceScoped( | ||
typeof(ICommandPreProcessor<>), | ||
assemblies); | ||
|
||
// Assert | ||
var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
serviceProvider.GetServices<ICommandPreProcessor<KitchenSinkWithoutResultCommand>>() | ||
.Should().HaveCount(2); | ||
serviceProvider.GetServices<ICommandPreProcessor<CreateUserCommand>>() | ||
.Should().HaveCount(1); | ||
serviceProvider.GetServices<ICommandPreProcessor<RecalculateTotalUserCountCommand>>() | ||
.Should().HaveCount(0); | ||
} | ||
|
||
[Fact] | ||
public void AddImplementationsOfInterfaceScoped_ShouldAddOnlyOnceIfCalledManyTimes() | ||
{ | ||
// Arrange | ||
var serviceCollection = new ServiceCollection(); | ||
var assemblies = new[] | ||
{ | ||
Assembly.GetExecutingAssembly(), | ||
Assembly.GetCallingAssembly() | ||
}.ToList(); | ||
|
||
// Act | ||
serviceCollection.AddImplementationsOfGenericInterfaceScoped( | ||
typeof(ICommandPreProcessor<>), | ||
assemblies); | ||
serviceCollection.AddImplementationsOfGenericInterfaceScoped( | ||
typeof(ICommandPreProcessor<>), | ||
assemblies); | ||
serviceCollection.AddImplementationsOfGenericInterfaceScoped( | ||
typeof(ICommandPreProcessor<>), | ||
assemblies); | ||
|
||
// Assert | ||
var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
serviceProvider.GetServices<ICommandPreProcessor<KitchenSinkWithoutResultCommand>>() | ||
.Should().HaveCount(2); | ||
serviceProvider.GetServices<ICommandPreProcessor<CreateUserCommand>>() | ||
.Should().HaveCount(1); | ||
serviceProvider.GetServices<ICommandPreProcessor<RecalculateTotalUserCountCommand>>() | ||
.Should().HaveCount(0); | ||
} | ||
|
||
[Fact] | ||
public void AddImplementationsOfInterfaceScoped_ShouldWorkForInterfaceWithTwoGenerics() | ||
{ | ||
// Arrange | ||
var serviceCollection = new ServiceCollection(); | ||
var assemblies = new[] | ||
{ | ||
Assembly.GetExecutingAssembly(), | ||
Assembly.GetCallingAssembly() | ||
}.ToList(); | ||
|
||
// Act | ||
serviceCollection.AddImplementationsOfGenericInterfaceScoped( | ||
typeof(ICommandHandler<,>), | ||
assemblies); | ||
|
||
// Assert | ||
var serviceProvider = serviceCollection.BuildServiceProvider(); | ||
serviceProvider.GetServices<ICommandHandler<KitchenSinkWithResultCommand, int>>() | ||
.Should().ContainSingle(); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
....UnitTests/TestApplication/Commands/KitchenSinkWithResult/KitchenSinkWithResultCommand.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,7 @@ | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
|
||
namespace Wemogy.CQRS.UnitTests.TestApplication.Commands.KitchenSinkWithResult; | ||
|
||
public class KitchenSinkWithResultCommand : ICommand<int> | ||
{ | ||
} |
15 changes: 15 additions & 0 deletions
15
...sts/TestApplication/Commands/KitchenSinkWithResult/KitchenSinkWithResultCommandHandler.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,15 @@ | ||
using System.Threading.Tasks; | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
|
||
namespace Wemogy.CQRS.UnitTests.TestApplication.Commands.KitchenSinkWithResult; | ||
|
||
public class KitchenSinkWithResultCommandHandler : ICommandHandler<KitchenSinkWithResultCommand, int> | ||
{ | ||
public int CalledCount { get; private set; } | ||
|
||
public Task<int> HandleAsync(KitchenSinkWithResultCommand command) | ||
{ | ||
CalledCount++; | ||
return Task.FromResult(42); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ests/TestApplication/Commands/KitchenSinkWithoutResult/KitchenSinkWithoutResultCommand.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,7 @@ | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
|
||
namespace Wemogy.CQRS.UnitTests.TestApplication.Commands.KitchenSinkWithoutResult; | ||
|
||
public class KitchenSinkWithoutResultCommand : ICommand | ||
{ | ||
} |
15 changes: 15 additions & 0 deletions
15
...stApplication/Commands/KitchenSinkWithoutResult/KitchenSinkWithoutResultCommandHandler.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,15 @@ | ||
using System.Threading.Tasks; | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
|
||
namespace Wemogy.CQRS.UnitTests.TestApplication.Commands.KitchenSinkWithoutResult; | ||
|
||
public class KitchenSinkWithoutResultCommandHandler : ICommandHandler<KitchenSinkWithoutResultCommand> | ||
{ | ||
public int CalledCount { get; private set; } | ||
|
||
public Task HandleAsync(KitchenSinkWithoutResultCommand command) | ||
{ | ||
CalledCount++; | ||
return Task.CompletedTask; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ication/Commands/KitchenSinkWithoutResult/KitchenSinkWithoutResultCommandPreProcessor1.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,14 @@ | ||
using System.Threading.Tasks; | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
|
||
namespace Wemogy.CQRS.UnitTests.TestApplication.Commands.KitchenSinkWithoutResult; | ||
|
||
public class KitchenSinkWithoutResultCommandPreProcessor1 : ICommandPreProcessor<KitchenSinkWithoutResultCommand> | ||
{ | ||
public int CalledCount { get; private set; } | ||
public Task ProcessAsync(KitchenSinkWithoutResultCommand command) | ||
{ | ||
CalledCount++; | ||
return Task.CompletedTask; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...ication/Commands/KitchenSinkWithoutResult/KitchenSinkWithoutResultCommandPreProcessor2.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,14 @@ | ||
using System.Threading.Tasks; | ||
using Wemogy.CQRS.Commands.Abstractions; | ||
|
||
namespace Wemogy.CQRS.UnitTests.TestApplication.Commands.KitchenSinkWithoutResult; | ||
|
||
public class KitchenSinkWithoutResultCommandPreProcessor2 : ICommandPreProcessor<KitchenSinkWithoutResultCommand> | ||
{ | ||
public int CalledCount { get; private set; } | ||
public Task ProcessAsync(KitchenSinkWithoutResultCommand command) | ||
{ | ||
CalledCount++; | ||
return Task.CompletedTask; | ||
} | ||
} |
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
9 changes: 9 additions & 0 deletions
9
src/core/Wemogy.CQRS/Abstractions/ICommandQueryDependencyResolver.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,9 @@ | ||
using System.Collections.Generic; | ||
using Wemogy.CQRS.Common.ValueObjects; | ||
|
||
namespace Wemogy.CQRS.Abstractions; | ||
|
||
public interface ICommandQueryDependencyResolver | ||
{ | ||
List<CommandQueryDependency> ResolveDependencies(); | ||
} |
Oops, something went wrong.