Skip to content

Commit

Permalink
- renamed messages
Browse files Browse the repository at this point in the history
  • Loading branch information
eben-roux committed Aug 14, 2022
1 parent bf28366 commit 3b587b6
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 40 deletions.
22 changes: 11 additions & 11 deletions Shuttle.Esb.Process.Tests/DefaultProcessActivatorFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ public void Should_be_able_to_request_mapping_registration()

Assert.IsFalse(activator.IsProcessMessage(transportMessage, new MockNullCommand()));

Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockRegisterOrderCommand()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockEMailSentEvent()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockCompleteOrderCommand()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockRegisterOrder()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockEMailSent()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockCompleteOrder()));

Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockRegisterMemberCommand()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockCompleteMemberRegistrationCommand()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockRegisterMember()));
Assert.IsTrue(activator.IsProcessMessage(transportMessage, new MockCompleteMemberRegistration()));
}

[Test]
Expand All @@ -40,10 +40,10 @@ public void Should_be_able_to_resolve_message_to_multiple_processes()

var activator = new ProcessActivator(Options.Create(processManagementOptions));

activator.RegisterResolver<MockEMailSentEvent>(
activator.RegisterResolver<MockEMailSent>(
(transport, message) => new MessageProcessType(typeof (MockOrderProcess), false));

var instance = activator.Create(transportMessage, new MockEMailSentEvent());
var instance = activator.Create(transportMessage, new MockEMailSent());

Assert.IsTrue(instance.GetType() == typeof (MockOrderProcess));
}
Expand All @@ -59,9 +59,9 @@ public void Should_be_able_to_start_process()
var activator = new ProcessActivator(Options.Create(processManagementOptions));

Assert.IsTrue(typeof (MockOrderProcess) ==
activator.Create(transportMessage, new MockRegisterOrderCommand()).GetType());
activator.Create(transportMessage, new MockRegisterOrder()).GetType());
Assert.IsTrue(typeof (MockMemberRegistrationProcess) ==
activator.Create(transportMessage, new MockRegisterMemberCommand()).GetType());
activator.Create(transportMessage, new MockRegisterMember()).GetType());
}

[Test]
Expand All @@ -71,7 +71,7 @@ public void Should_throw_exception_when_creating_unknown_process()

var activator = new ProcessActivator(Options.Create(new ProcessManagementOptions()));

Assert.Throws<ProcessException>(() => activator.Create(transportMessage, new MockRegisterMemberCommand()));
Assert.Throws<ProcessException>(() => activator.Create(transportMessage, new MockNullCommand()));
}

[Test]
Expand All @@ -84,7 +84,7 @@ public void Should_throw_exception_when_no_resolver_for_message_to_multiple_proc

var activator = new ProcessActivator(Options.Create(processManagementOptions));

Assert.Throws<ProcessException>(() => activator.Create(transportMessage, new MockEMailSentEvent()));
Assert.Throws<ProcessException>(() => activator.Create(transportMessage, new MockEMailSent()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Shuttle.Esb.Process.Tests
{
public class MockCompleteMemberRegistration
{
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Shuttle.Esb.Process.Tests
{
public class MockEMailSentEvent
public class MockCompleteOrder
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Shuttle.Esb.Process.Tests
{
public class MockRegisterOrderCommand
public class MockEMailSent
{
}
}
12 changes: 6 additions & 6 deletions Shuttle.Esb.Process.Tests/Mocks/MockMemberRegistrationProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ namespace Shuttle.Esb.Process.Tests
{
public class MockMemberRegistrationProcess :
IProcessManager,
IProcessStartMessageHandler<MockRegisterMemberCommand>,
IProcessMessageHandler<MockEMailSentEvent>,
IProcessMessageHandler<MockCompleteMemberRegistrationCommand>
IProcessStartMessageHandler<MockRegisterMember>,
IProcessMessageHandler<MockEMailSent>,
IProcessMessageHandler<MockCompleteMemberRegistration>
{
public Guid CorrelationId { get; set; }

public void ProcessMessage(IProcessHandlerContext<MockCompleteMemberRegistrationCommand> context)
public void ProcessMessage(IProcessHandlerContext<MockCompleteMemberRegistration> context)
{
throw new NotImplementedException();
}

public void ProcessMessage(IProcessHandlerContext<MockEMailSentEvent> context)
public void ProcessMessage(IProcessHandlerContext<MockEMailSent> context)
{
throw new NotImplementedException();
}

public void ProcessMessage(IProcessHandlerContext<MockRegisterMemberCommand> context)
public void ProcessMessage(IProcessHandlerContext<MockRegisterMember> context)
{
throw new NotImplementedException();
}
Expand Down
12 changes: 6 additions & 6 deletions Shuttle.Esb.Process.Tests/Mocks/MockOrderProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ namespace Shuttle.Esb.Process.Tests
{
public class MockOrderProcess :
IProcessManager,
IProcessStartMessageHandler<MockRegisterOrderCommand>,
IProcessMessageHandler<MockEMailSentEvent>,
IProcessMessageHandler<MockCompleteOrderCommand>
IProcessStartMessageHandler<MockRegisterOrder>,
IProcessMessageHandler<MockEMailSent>,
IProcessMessageHandler<MockCompleteOrder>
{
public Guid CorrelationId { get; set; }

public void ProcessMessage(IProcessHandlerContext<MockCompleteOrderCommand> context)
public void ProcessMessage(IProcessHandlerContext<MockCompleteOrder> context)
{
throw new NotImplementedException();
}

public void ProcessMessage(IProcessHandlerContext<MockEMailSentEvent> context)
public void ProcessMessage(IProcessHandlerContext<MockEMailSent> context)
{
throw new NotImplementedException();
}

public void ProcessMessage(IProcessHandlerContext<MockRegisterOrderCommand> context)
public void ProcessMessage(IProcessHandlerContext<MockRegisterOrder> context)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Shuttle.Esb.Process.Tests
{
public class MockCompleteOrderCommand
public class MockRegisterMember
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace Shuttle.Esb.Process.Tests
{
public class MockRegisterMemberCommand
public class MockRegisterOrder
{
}
}
11 changes: 8 additions & 3 deletions Shuttle.Esb.Process/ProcessActivator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.Options;
using Shuttle.Core.Contract;
Expand Down Expand Up @@ -28,10 +29,14 @@ public ProcessActivator(IOptions<ProcessManagementOptions> processManagementOpti

_processFactoryFunction = type => (IProcessManager) Activator.CreateInstance(type);

foreach (var assemblyName in processManagementOptions.Value.AssemblyNames)
{
var assembly = Assembly.Load(assemblyName);
var assemblies = new List<Assembly>();

assemblies.AddRange((processManagementOptions.Value.AssemblyNames ?? Enumerable.Empty<string>()).Any()
? processManagementOptions.Value.AssemblyNames.Select(Assembly.Load)
: new ReflectionService().GetRuntimeAssemblies());

foreach (var assembly in assemblies)
{
RegisterMappings(assembly, typeof(IProcessMessageHandler<>), false);
RegisterMappings(assembly, typeof(IProcessStartMessageHandler<>), true);
}
Expand Down
12 changes: 10 additions & 2 deletions Shuttle.Esb.Process/ProcessMessageHandlerInvoker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.Options;
using Shuttle.Core.Contract;
Expand Down Expand Up @@ -52,9 +54,15 @@ public ProcessMessageHandlerInvoker(IServiceProvider serviceProvider, IOptionsMo

var reflectionService = new ReflectionService();

foreach (var assemblyName in processManagementOptions.Value.AssemblyNames)
var assemblies = new List<Assembly>();

assemblies.AddRange((processManagementOptions.Value.AssemblyNames ?? Enumerable.Empty<string>()).Any()
? processManagementOptions.Value.AssemblyNames.Select(Assembly.Load)
: new ReflectionService().GetRuntimeAssemblies());

foreach (var assembly in assemblies)
{
foreach (var type in reflectionService.GetTypesAssignableTo<IProcessMessageAssessor>(Assembly.Load(assemblyName)))
foreach (var type in reflectionService.GetTypesAssignableTo<IProcessMessageAssessor>(assembly))
{
try
{
Expand Down
6 changes: 4 additions & 2 deletions Shuttle.Esb.Process/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
using Shuttle.Core.Contract;

namespace Shuttle.Esb.Process
Expand All @@ -15,8 +16,9 @@ public static IServiceCollection AddProcessManagement(this IServiceCollection se

builder?.Invoke(processManagementBuilder);

services.TryAddSingleton<IProcessActivator, ProcessActivator>();
services.TryAddSingleton<IMessageHandlerInvoker, ProcessMessageHandlerInvoker>();
services.AddSingleton<IProcessActivator, ProcessActivator>();
services.AddSingleton<IMessageHandlerInvoker, ProcessMessageHandlerInvoker>();
services.AddSingleton<IValidateOptions<ProcessManagementOptions>, ProcessManagementOptionsValidator>();

services.AddOptions<ProcessManagementOptions>().Configure(options =>
{
Expand Down

0 comments on commit 3b587b6

Please sign in to comment.