public void Setup() { _testObj = new SubjectMessageBus <string>(); }
public void Setup() { _testObj = new SubjectMessageBus<string>(); }
public void Setup() { _scheduler = new TestScheduler(); _testObj = new SubjectMessageBus <string>(_scheduler); }
public void ShouldPublishMessagesWithNoEndpointToLocalBusWhenConfigured() { FakeServiceEndpoint fakeServiceEndpoint = new FakeServiceEndpoint(typeof(ITestServiceMessage1)); FakeServiceEndpoint fakeServer = new FakeServiceEndpoint(typeof(ITestServiceMessage2)); var localBus = new SubjectMessageBus<IMessage>(); var testScheduler = new TestScheduler(); IServiceBus serviceBus = ServiceBus.Configure() .WithEndpoint((IServiceEndpoint)fakeServiceEndpoint) .WithEndpoint((IServiceEndpointClient)fakeServer) .PublishLocally(localBus).OnlyMessagesWithNoEndpoints() .UsingConsoleMonitor(TimeSpan.FromSeconds(5), testScheduler) .UsingConsoleLogging() .Create(); List<Exception> exceptions = new List<Exception>(); List<IMessage> serviceBusMessages = new List<IMessage>(); List<IMessage> localBusMessages = new List<IMessage>(); serviceBus.Exceptions.Subscribe(exceptions.Add); serviceBus.Events.Subscribe(serviceBusMessages.Add); serviceBus.Commands.Subscribe(serviceBusMessages.Add); serviceBus.Requests.Subscribe(serviceBusMessages.Add); localBus.Messages.Subscribe(localBusMessages.Add); fakeServer.Commands.Subscribe(command => fakeServer.PublishAsync(new TestServiceEvent2())); fakeServer.Requests.Subscribe(request => fakeServer.ReplyAsync(request, new TestServiceResponse2())); serviceBus.Requests.OfType<TestServiceRequest1>().Subscribe(request => { serviceBus.ReplyAsync(request, new TestServiceResponse1()); }); serviceBus.GetResponses(new TestServiceRequest1()).Subscribe(serviceBusMessages.Add); serviceBus.GetResponses(new TestServiceRequest2()).Subscribe(serviceBusMessages.Add); serviceBus.SendAsync(new TestServiceCommand2()); serviceBus.PublishAsync(new TestServiceEvent1()); serviceBus.SendAsync(new TestServiceCommand1()); serviceBus.PublishAsync(new TestEventBelongingToNoService()); Assert.That(exceptions.Count(), Is.EqualTo(0)); Assert.That(localBusMessages.Count(), Is.EqualTo(1)); Assert.That(localBusMessages[0].GetType(), Is.EqualTo(typeof(TestEventBelongingToNoService))); Assert.That(serviceBusMessages.Count(), Is.EqualTo(3)); Assert.That(serviceBusMessages[0].GetType(), Is.EqualTo(typeof(TestServiceResponse2))); Assert.That(serviceBusMessages[1].GetType(), Is.EqualTo(typeof(TestServiceEvent2))); Assert.That(serviceBusMessages[2].GetType(), Is.EqualTo(typeof(TestEventBelongingToNoService))); // locally published testScheduler.AdvanceBy(TimeSpan.FromSeconds(10).Ticks); }
public void ShouldPublishMessagesToLocalBusWhenConfigured() { FakeServiceEndpoint fakeServiceEndpoint = new FakeServiceEndpoint(typeof(ITestServiceMessage1)); FakeServiceEndpoint fakeServer = new FakeServiceEndpoint(typeof(ITestServiceMessage2)); var localBus = new SubjectMessageBus<IMessage>(); IServiceBus serviceBus = ServiceBus.Configure() .WithEndpoint((IServiceEndpoint)fakeServiceEndpoint) .WithEndpoint((IServiceEndpointClient)fakeServer) .PublishLocally(localBus).AnyMessagesWithNoEndpointClients() .Create(); List<Exception> exceptions = new List<Exception>(); List<IMessage> serviceBusMessages = new List<IMessage>(); List<IMessage> localBusMessages = new List<IMessage>(); serviceBus.Exceptions.Subscribe(exceptions.Add); serviceBus.Events.Subscribe(serviceBusMessages.Add); serviceBus.Commands.Subscribe(serviceBusMessages.Add); serviceBus.Requests.Subscribe(serviceBusMessages.Add); localBus.Messages.Subscribe(localBusMessages.Add); fakeServer.Commands.Subscribe(command => fakeServer.PublishAsync(new TestServiceEvent2())); fakeServer.Requests.Subscribe(request => fakeServer.ReplyAsync(request, new TestServiceResponse2())); serviceBus.Requests.OfType<TestServiceRequest1>().Subscribe(request => { serviceBus.ReplyAsync(request, new TestServiceResponse1()); }); serviceBus.GetResponses(new TestServiceRequest1()).Subscribe(serviceBusMessages.Add); serviceBus.GetResponses(new TestServiceRequest2()).Subscribe(serviceBusMessages.Add); serviceBus.SendAsync(new TestServiceCommand2()); serviceBus.PublishAsync(new TestServiceEvent1()); serviceBus.SendAsync(new TestServiceCommand1()); serviceBus.PublishAsync(new TestEventBelongingToNoService()); Assert.That(exceptions.Count(), Is.EqualTo(0)); Assert.That(localBusMessages.Count(), Is.EqualTo(5)); Assert.That(localBusMessages[0].GetType(), Is.EqualTo(typeof(TestServiceResponse1))); Assert.That(localBusMessages[1].GetType(), Is.EqualTo(typeof(TestServiceRequest1))); Assert.That(localBusMessages[2].GetType(), Is.EqualTo(typeof(TestServiceEvent1))); Assert.That(localBusMessages[3].GetType(), Is.EqualTo(typeof(TestServiceCommand1))); Assert.That(localBusMessages[4].GetType(), Is.EqualTo(typeof(TestEventBelongingToNoService))); Assert.That(serviceBusMessages.Count(), Is.EqualTo(7)); Assert.That(serviceBusMessages[0].GetType(), Is.EqualTo(typeof(TestServiceRequest1))); // locally published Assert.That(serviceBusMessages[1].GetType(), Is.EqualTo(typeof(TestServiceResponse1))); // locally published Assert.That(serviceBusMessages[2].GetType(), Is.EqualTo(typeof(TestServiceResponse2))); Assert.That(serviceBusMessages[3].GetType(), Is.EqualTo(typeof(TestServiceEvent2))); Assert.That(serviceBusMessages[4].GetType(), Is.EqualTo(typeof(TestServiceEvent1))); // locally published Assert.That(serviceBusMessages[5].GetType(), Is.EqualTo(typeof(TestServiceCommand1))); // locally published Assert.That(serviceBusMessages[6].GetType(), Is.EqualTo(typeof(TestEventBelongingToNoService))); // locally published }
public void Setup() { _scheduler = new TestScheduler(); _testObj = new SubjectMessageBus<string>(_scheduler); }
public TestSubjectMessageBusWithScheduler() { _scheduler = new TestScheduler(); _testObj = new SubjectMessageBus <string>(_scheduler); }
public TestSubjectMessageBus() { _testObj = new SubjectMessageBus <string>(); }