diff --git a/src/ServiceControl.AcceptanceTests/ExternalIntegrations/When_a_message_has_custom_checks.cs b/src/ServiceControl.AcceptanceTests/ExternalIntegrations/When_a_message_has_custom_checks.cs new file mode 100644 index 0000000000..6c002f08a2 --- /dev/null +++ b/src/ServiceControl.AcceptanceTests/ExternalIntegrations/When_a_message_has_custom_checks.cs @@ -0,0 +1,150 @@ +namespace ServiceBus.Management.AcceptanceTests.ExternalIntegrations +{ + using System; + using Contexts; + using NServiceBus; + using NServiceBus.AcceptanceTesting; + using NServiceBus.Config; + using NServiceBus.Config.ConfigurationSource; + using NServiceBus.Features; + using NServiceBus.Unicast.Subscriptions; + using NServiceBus.Unicast.Subscriptions.MessageDrivenSubscriptions; + using NUnit.Framework; + using ServiceControl.Contracts; + using ServiceControl.Contracts.Operations; + + [TestFixture] + public class When_a_message_has_custom_checks : AcceptanceTest + { + [Test] + public void Notification_should_be_published_on_the_bus() + { + var context = new MyContext(); + + Scenario.Define(context) + .WithEndpoint(b => b.Given((bus, c) => Subscriptions.OnEndpointSubscribed(s => + { + if (s.SubscriberReturnAddress.Queue.Contains("ExternalProcessor")) + { + c.ExternalProcessorSubscribed = true; + } + }, () => c.ExternalProcessorSubscribed = true)) + .When(c => c.ExternalProcessorSubscribed, bus => + { + bus.Publish(new ServiceControl.Contracts.CustomChecks.CustomCheckSucceeded + { + Category = "Testing", + CustomCheckId = "Success custom check", + OriginatingEndpoint = new EndpointDetails + { + Host = "MyHost", + HostId = Guid.Empty, + Name = "Testing" + }, + SucceededAt = DateTime.Now, + }); + bus.Publish(new ServiceControl.Contracts.CustomChecks.CustomCheckFailed + { + Category = "Testing", + CustomCheckId = "Fail custom check", + OriginatingEndpoint = new EndpointDetails + { + Host = "MyHost", + HostId = Guid.Empty, + Name = "Testing" + }, + FailedAt = DateTime.Now, + FailureReason = "Because I can", + }); + }).AppConfig(PathToAppConfig)) + .WithEndpoint(b => b.Given((bus, c) => + { + bus.Subscribe(); + bus.Subscribe(); + })) + .Done(c => c.CustomCheckFailedReceived && c.CustomCheckFailedReceived) + .Run(); + + Assert.IsTrue(context.CustomCheckFailedReceived); + Assert.IsTrue(context.CustomCheckSucceededReceived); + } + + [Serializable] + public class Subscriptions + { + public static Action, Action> OnEndpointSubscribed = (actionToPerformIfMessageDrivenSubscriptions, actionToPerformIfMessageDrivenSubscriptionsNotRequired) => + { + if (Feature.IsEnabled()) + { + Configure.Instance.Builder.Build().ClientSubscribed += + (sender, args) => + { + actionToPerformIfMessageDrivenSubscriptions(args); + }; + + return; + } + + actionToPerformIfMessageDrivenSubscriptionsNotRequired(); + }; + } + + public class ExternalIntegrationsManagementEndpoint : EndpointConfigurationBuilder + { + public ExternalIntegrationsManagementEndpoint() + { + EndpointSetup(); + } + } + + public class ExternalProcessor : EndpointConfigurationBuilder + { + public ExternalProcessor() + { + EndpointSetup(); + } + + public class CustomCheckSucceededHandler : IHandleMessages + { + public MyContext Context { get; set; } + + public void Handle(CustomCheckSucceeded message) + { + Context.CustomCheckSucceededReceived = true; + } + } + + public class CustomCheckFailedHandler : IHandleMessages + { + public MyContext Context { get; set; } + + public void Handle(CustomCheckFailed message) + { + Context.CustomCheckFailedReceived = true; + } + } + + public class UnicastOverride : IProvideConfiguration + { + public UnicastBusConfig GetConfiguration() + { + var config = new UnicastBusConfig(); + var serviceControlMapping = new MessageEndpointMapping + { + Messages = "ServiceControl.Contracts", + Endpoint = "Particular.ServiceControl" + }; + config.MessageEndpointMappings.Add(serviceControlMapping); + return config; + } + } + } + + public class MyContext : ScenarioContext + { + public bool CustomCheckSucceededReceived { get; set; } + public bool CustomCheckFailedReceived { get; set; } + public bool ExternalProcessorSubscribed { get; set; } + } + } +} \ No newline at end of file diff --git a/src/ServiceControl.AcceptanceTests/ServiceControl.AcceptanceTests.csproj b/src/ServiceControl.AcceptanceTests/ServiceControl.AcceptanceTests.csproj index 80e821b8f4..60b7e852fe 100644 --- a/src/ServiceControl.AcceptanceTests/ServiceControl.AcceptanceTests.csproj +++ b/src/ServiceControl.AcceptanceTests/ServiceControl.AcceptanceTests.csproj @@ -114,7 +114,7 @@ False - ..\packages\ServiceControl.Contracts.1.0.0\lib\net45\ServiceControl.Contracts.dll + ..\packages\ServiceControl.Contracts.1.1.0\lib\net45\ServiceControl.Contracts.dll False @@ -180,7 +180,8 @@ - + + diff --git a/src/ServiceControl.AcceptanceTests/packages.config b/src/ServiceControl.AcceptanceTests/packages.config index 20e9bb9490..f6614b1ca0 100644 --- a/src/ServiceControl.AcceptanceTests/packages.config +++ b/src/ServiceControl.AcceptanceTests/packages.config @@ -18,7 +18,7 @@ - + diff --git a/src/ServiceControl.IntegrationDemo/ServiceControl.IntegrationDemo.csproj b/src/ServiceControl.IntegrationDemo/ServiceControl.IntegrationDemo.csproj index 34545b9be7..03ba1559e3 100644 --- a/src/ServiceControl.IntegrationDemo/ServiceControl.IntegrationDemo.csproj +++ b/src/ServiceControl.IntegrationDemo/ServiceControl.IntegrationDemo.csproj @@ -47,7 +47,7 @@ False - ..\packages\ServiceControl.Contracts.1.0.0\lib\net45\ServiceControl.Contracts.dll + ..\packages\ServiceControl.Contracts.1.1.0\lib\net45\ServiceControl.Contracts.dll diff --git a/src/ServiceControl.IntegrationDemo/packages.config b/src/ServiceControl.IntegrationDemo/packages.config index 802e6629d0..4be01563f7 100644 --- a/src/ServiceControl.IntegrationDemo/packages.config +++ b/src/ServiceControl.IntegrationDemo/packages.config @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/src/ServiceControl.UnitTests/ServiceControl.UnitTests.csproj b/src/ServiceControl.UnitTests/ServiceControl.UnitTests.csproj index d8e6c72d72..eb7cb2246c 100644 --- a/src/ServiceControl.UnitTests/ServiceControl.UnitTests.csproj +++ b/src/ServiceControl.UnitTests/ServiceControl.UnitTests.csproj @@ -74,7 +74,7 @@ False - ..\packages\ServiceControl.Contracts.1.0.0\lib\net45\ServiceControl.Contracts.dll + ..\packages\ServiceControl.Contracts.1.1.0\lib\net45\ServiceControl.Contracts.dll diff --git a/src/ServiceControl.UnitTests/packages.config b/src/ServiceControl.UnitTests/packages.config index 8c5257959e..ae64cdeafd 100644 --- a/src/ServiceControl.UnitTests/packages.config +++ b/src/ServiceControl.UnitTests/packages.config @@ -9,7 +9,7 @@ - + \ No newline at end of file diff --git a/src/ServiceControl/ExternalIntegrations/CustomCheckFailedPublisher.cs b/src/ServiceControl/ExternalIntegrations/CustomCheckFailedPublisher.cs new file mode 100644 index 0000000000..97991fdcde --- /dev/null +++ b/src/ServiceControl/ExternalIntegrations/CustomCheckFailedPublisher.cs @@ -0,0 +1,51 @@ +namespace ServiceControl.ExternalIntegrations +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Raven.Client; + using CustomCheckFailed = ServiceControl.Contracts.CustomCheckFailed; + + + public class CustomCheckFailedPublisher : EventPublisher + { + protected override DispatchContext CreateDispatchRequest(Contracts.CustomChecks.CustomCheckFailed @event) + { + return new DispatchContext + { + EndpointHost = @event.OriginatingEndpoint.Host, + EndpointHostId = @event.OriginatingEndpoint.HostId, + EndpointName = @event.OriginatingEndpoint.Name, + FailedAt = @event.FailedAt, + Category = @event.Category, + FailureReason = @event.FailureReason, + CustomCheckId = @event.CustomCheckId, + }; + } + + protected override IEnumerable PublishEvents(IEnumerable contexts, IDocumentSession session) + { + return contexts.Select(r => new CustomCheckFailed + { + FailedAt = r.FailedAt, + Category = r.Category, + FailureReason = r.FailureReason, + CustomCheckId = r.CustomCheckId, + Host = r.EndpointHost, + HostId = r.EndpointHostId, + EndpointName = r.EndpointName + }); + } + + public class DispatchContext + { + public string EndpointName { get; set; } + public Guid EndpointHostId { get; set; } + public string EndpointHost { get; set; } + public string CustomCheckId { get; set; } + public string Category { get; set; } + public string FailureReason { get; set; } + public DateTime FailedAt { get; set; } + } + } +} \ No newline at end of file diff --git a/src/ServiceControl/ExternalIntegrations/CustomCheckSucceededPublisher.cs b/src/ServiceControl/ExternalIntegrations/CustomCheckSucceededPublisher.cs new file mode 100644 index 0000000000..cb0ae81f29 --- /dev/null +++ b/src/ServiceControl/ExternalIntegrations/CustomCheckSucceededPublisher.cs @@ -0,0 +1,47 @@ +namespace ServiceControl.ExternalIntegrations +{ + using System; + using System.Collections.Generic; + using System.Linq; + using Raven.Client; + using ServiceControl.Contracts; + + public class CustomCheckSucceededPublisher : EventPublisher + { + protected override DispatchContext CreateDispatchRequest(Contracts.CustomChecks.CustomCheckSucceeded @event) + { + return new DispatchContext + { + EndpointHost = @event.OriginatingEndpoint.Host, + EndpointHostId = @event.OriginatingEndpoint.HostId, + EndpointName = @event.OriginatingEndpoint.Name, + SucceededAt = @event.SucceededAt, + Category = @event.Category, + CustomCheckId = @event.CustomCheckId, + }; + } + + protected override IEnumerable PublishEvents(IEnumerable contexts, IDocumentSession session) + { + return contexts.Select(r => new CustomCheckSucceeded + { + SucceededAt = r.SucceededAt, + Category = r.Category, + CustomCheckId = r.CustomCheckId, + Host = r.EndpointHost, + HostId = r.EndpointHostId, + EndpointName = r.EndpointName + }); + } + + public class DispatchContext + { + public string EndpointName { get; set; } + public Guid EndpointHostId { get; set; } + public string EndpointHost { get; set; } + public string CustomCheckId { get; set; } + public string Category { get; set; } + public DateTime SucceededAt { get; set; } + } + } +} \ No newline at end of file diff --git a/src/ServiceControl/ExternalIntegrations/ExternalIntegrationsInitializer.cs b/src/ServiceControl/ExternalIntegrations/ExternalIntegrationsInitializer.cs index dad847607f..bec135c183 100644 --- a/src/ServiceControl/ExternalIntegrations/ExternalIntegrationsInitializer.cs +++ b/src/ServiceControl/ExternalIntegrations/ExternalIntegrationsInitializer.cs @@ -9,6 +9,8 @@ public void Init() Configure.Component(DependencyLifecycle.SingleInstance); Configure.Component(DependencyLifecycle.SingleInstance); Configure.Component(DependencyLifecycle.SingleInstance); + Configure.Component(DependencyLifecycle.SingleInstance); + Configure.Component(DependencyLifecycle.SingleInstance); } } } \ No newline at end of file diff --git a/src/ServiceControl/ServiceControl.csproj b/src/ServiceControl/ServiceControl.csproj index 133535923e..7ec18b6608 100644 --- a/src/ServiceControl/ServiceControl.csproj +++ b/src/ServiceControl/ServiceControl.csproj @@ -152,7 +152,7 @@ False - ..\packages\ServiceControl.Contracts.1.0.0\lib\net45\ServiceControl.Contracts.dll + ..\packages\ServiceControl.Contracts.1.1.0\lib\net45\ServiceControl.Contracts.dll @@ -250,11 +250,13 @@ + + diff --git a/src/ServiceControl/packages.config b/src/ServiceControl/packages.config index 11f9218c2d..ce6d4f2a21 100644 --- a/src/ServiceControl/packages.config +++ b/src/ServiceControl/packages.config @@ -31,7 +31,7 @@ - +