public void Should_ignore_a_response_that_was_not_for_us() { var pongReceived = new FutureMessage <PongMessage>(); var pingReceived = new FutureMessage <PingMessage>(); var badResponse = new FutureMessage <PongMessage>(); LocalBus.SubscribeHandler <PongMessage>(pongReceived.Set); RemoteBus.SubscribeContextHandler <PingMessage>(x => { pingReceived.Set(x.Message); RemoteBus.Publish(new PongMessage { TransactionId = x.Message.TransactionId }); }); LocalBus.ShouldHaveSubscriptionFor <PingMessage>(); var ping = new PingMessage(); TimeSpan timeout = 8.Seconds(); Assert.Throws <RequestTimeoutException>(() => { RemoteBus.Endpoint.SendRequest(ping, LocalBus, x => { x.Handle <PongMessage>(badResponse.Set); x.SetTimeout(timeout); }); }); pingReceived.IsAvailable(timeout).ShouldBeTrue("The ping was not received"); pongReceived.IsAvailable(timeout).ShouldBeTrue("The pong was not received"); badResponse.IsAvailable(2.Seconds()).ShouldBeFalse("Should not have received a response"); }
public void The_message_should_be_delivered_to_a_remote_subscriber_with_a_reply() { ManualResetEvent _updateEvent = new ManualResetEvent(false); Action <UpdateMessage> handler = msg => { _updateEvent.Set(); RemoteBus.Publish(new UpdateAcceptedMessage()); }; ManualResetEvent _repliedEvent = new ManualResetEvent(false); RemoteBus.Subscribe(handler); LocalBus.Subscribe <UpdateAcceptedMessage>( delegate { _repliedEvent.Set(); }); UpdateMessage um = new UpdateMessage(); LocalBus.Publish(um); Assert.That(_updateEvent.WaitOne(TimeSpan.FromSeconds(3), true), Is.True, "Timeout expired waiting for message"); Assert.That(_repliedEvent.WaitOne(TimeSpan.FromSeconds(3), true), Is.True, "NO response message received"); }
public void Should_have_received_b() { var message = new B(); RemoteBus.Publish(message); TestConsumerBase <B> .OnlyOneShouldHaveReceivedMessage(message, 8.Seconds()); }
public void A_message_is_published() { RemoteBus.Publish(new A { StringA = "ValueA", StringB = "ValueB", }); }
public void A_message_should_only_reach_the_consumer_if_the_filter_passes_it_forward() { MessageFilter <RequestMessage> filter = new MessageFilter <RequestMessage>(delegate { return(false); }, _consumer); LocalBus.Subscribe(filter); RemoteBus.Publish(_message); Assert.That(_passed.WaitOne(TimeSpan.FromSeconds(1), true), Is.False, "Timeout waiting for message handler to be called"); }
public void Should_call_the_ack_method_upon_delivery() { RemoteBus.Publish(new A { StringA = "ValueA", }); _received.WaitUntilCompleted(8.Seconds()).ShouldBeTrue(); }
public void A_state_machine_based_saga_should_automatically_wire_up_subscriptions() { RemoteBus.Subscribe <AutoStateMachineSaga>(); PipelineViewer.Trace(RemoteBus.InboundPipeline); PipelineViewer.Trace(RemoteBus.OutboundPipeline); Assert.AreEqual(0, _repository.Where(x => true).Count()); RemoteBus.Publish(new RegisterUser(_transactionId, _username, _password, _displayName, _email)); for (int i = 0; i < 20; i++) { if (_repository.Where(x => true).Count() == 1) { break; } Thread.Sleep(100); } Assert.AreEqual(1, _repository.Where(x => true).Count()); foreach (AutoStateMachineSaga saga in _repository.Where(x => true)) { saga.CurrentState.ShouldEqual(AutoStateMachineSaga.WaitingForEmailValidation); } _repository .Where(x => x.CorrelationId == _transactionId) .Select(x => x.CurrentState) .First() .ShouldEqual(AutoStateMachineSaga.WaitingForEmailValidation); RemoteBus.Publish(new UserValidated(_transactionId)); for (int i = 0; i < 20; i++) { if (_repository.Where(x => x.CorrelationId == _transactionId).Select(x => x.CurrentState).First() == AutoStateMachineSaga.Completed) { break; } Thread.Sleep(100); } _repository .Where(x => x.CorrelationId == _transactionId) .Select(x => x.CurrentState) .First() .ShouldEqual(AutoStateMachineSaga.Completed); }
public void Should_be_possible() { LocalBus.HasSubscription <IBusinessCommand>(8.Seconds()).Any().ShouldBeTrue(); RemoteBus.HasSubscription <ISecureCommand <IBusinessCommand> >(8.Seconds()).Any().ShouldBeTrue(); RemoteBus.Publish(new BusinessCommand { SqlText = "DROP TABLE [Users]", }); CommandHandler.CommandReceived.IsAvailable(8.Seconds()).ShouldBeTrue(); }
protected override void EstablishContext() { base.EstablishContext(); var sagaRepository = SetupSagaRepository <RegisterUserSaga>(ObjectBuilder); // this just shows that you can easily respond to the message RemoteBus.Subscribe <SendUserVerificationEmail>( x => RemoteBus.Publish(new UserVerificationEmailSent(x.CorrelationId, x.Email))); RemoteBus.Subscribe <RegisterUserSaga>(); }
public void A_consumer_object_should_receive_the_message() { FutureMessage <PingMessage> fm = new FutureMessage <PingMessage>(); PingHandler handler = new PingHandler(fm); LocalBus.Subscribe(handler); int old = PingHandler.Pinged; RemoteBus.Publish(new PingMessage()); fm.IsAvailable(1.Seconds()); Assert.That(PingHandler.Pinged, Is.GreaterThan(old)); }
public void A_consumer_type_should_be_created_to_receive_the_message() { var fm = new FutureMessage <PingMessage>(); LocalBus.SubscribeConsumer <PingHandler>(() => new PingHandler(fm)); RemoteBus.ShouldHaveSubscriptionFor <PingMessage>(); int old = PingHandler.Pinged; RemoteBus.Publish(new PingMessage()); fm.IsAvailable(1.Seconds()); Assert.That(PingHandler.Pinged, Is.GreaterThan(old)); }
public void Subscring_to_an_endpoint_should_accept_and_dispatch_messages() { FutureMessage <PingMessage> fm = new FutureMessage <PingMessage>(); bool workDid = false; LocalBus.Subscribe <PingMessage>( (msg) => { workDid = true; fm.Set(msg); }, delegate { return(true); }); RemoteBus.Publish(_message); fm.IsAvailable(1.Seconds()); Assert.That(workDid, Is.True, "Lazy Test!"); }
public void Should_be_possible() { RemoteBus.HasSubscription <ISecureCommand>(8.Seconds()).Any().ShouldBeTrue(); RemoteBus.Publish(new CommandAndCredentials { SqlText = "DROP TABLE [Users]", Username = "******", Password = "******", }); CommandHandler.CredentialsReceived.IsAvailable(8.Seconds()).ShouldBeTrue(); }
public void The_message_should_be_delivered_to_a_remote_subscriber() { var updated = new Future <UpdateMessage>(); LocalBus.SubscribeHandler <UpdateMessage>(updated.Complete); RemoteBus.HasSubscription <UpdateMessage>().Count().ShouldBeGreaterThan(0); var um = new UpdateMessage(); RemoteBus.Publish(um); updated.WaitUntilCompleted(8.Seconds()).ShouldBeTrue("Update not received"); }
protected override void EstablishContext() { base.EstablishContext(); _repository = SetupSagaRepository <AutoStateMachineSaga>(ObjectBuilder); // this just shows that you can easily respond to the message RemoteBus.Subscribe <SendUserVerificationEmail>( x => RemoteBus.Publish(new UserVerificationEmailSent(x.CorrelationId, x.Email))); _transactionId = CombGuid.Generate(); _username = "******"; _password = "******"; _email = "*****@*****.**"; _displayName = "Joe Blow"; }
public void A_consumer_type_should_be_created_to_receive_the_message() { FutureMessage <PingMessage> fm = new FutureMessage <PingMessage>(); PingHandler ph = new PingHandler(fm); ObjectBuilder.Stub(x => x.GetInstance <PingHandler>()).Return(ph); ObjectBuilder.Stub(x => x.GetInstance <PingHandler>(new Hashtable())).IgnoreArguments().Return(ph); LocalBus.Subscribe <PingHandler>(); int old = PingHandler.Pinged; RemoteBus.Publish(new PingMessage()); fm.IsAvailable(1.Seconds()); Assert.That(PingHandler.Pinged, Is.GreaterThan(old)); }
internal void MoveTo(Point p, Panel container, bool useAnimation = true) { p = AdjustPosition(p, container); if (useAnimation) { AnimateTo(p); } else { TeleportTo(p); } RemoteBus.Publish(new RemoteEvent(RemoteEventType.MoveMenuTo, new MoveToPayload() { Animate = useAnimation, X = p.X, Y = p.Y }), this); }
public void It_should_not_rollback_a_send_if_an_exception_is_thrown() { var consumer = new TestMessageConsumer <PongMessage>(); LocalBus.Subscribe(consumer); var message = new PingMessage(); var response = new PongMessage(message.CorrelationId); RemoteBus.Subscribe <PingMessage>(m => { RemoteBus.Publish(response); throw new ApplicationException("Boing!"); }); LocalBus.Publish(message); consumer.ShouldHaveReceivedMessage(response, _timeout); }
public void Any_type_of_send_should_be_supported() { RemoteBus.Subscribe <PingMessage>(x => RemoteBus.Publish(new PongMessage(x.CorrelationId))); PingMessage ping = new PingMessage(); FutureMessage <PongMessage> ponged = new FutureMessage <PongMessage>(); LocalBus.MakeRequest(bus => RemoteBus.Endpoint.Send(ping, context => context.SendResponseTo(bus))) .When <PongMessage>().RelatedTo(ping.CorrelationId).IsReceived(pong => { Assert.AreEqual(ping.CorrelationId, pong.CorrelationId); ponged.Set(pong); }) .TimeoutAfter(5.Seconds()) .Send(); Assert.IsTrue(ponged.IsAvailable(1.Seconds()), "No response received"); }
protected override void EstablishContext() { base.EstablishContext(); InMemorySagaRepository <RegisterUserSaga> sagaRepository = SetupSagaRepository <RegisterUserSaga>(); // this just shows that you can easily respond to the message RemoteBus.SubscribeHandler <SendUserVerificationEmail>( x => { RemoteBus.ShouldHaveSubscriptionFor <UserVerificationEmailSent>(); RemoteBus.Publish(new UserVerificationEmailSent(x.CorrelationId, x.Email)); }); RemoteBus.SubscribeSaga(sagaRepository); LocalBus.ShouldHaveSubscriptionFor <RegisterUser>(); LocalBus.ShouldHaveSubscriptionFor <UserVerificationEmailSent>(); LocalBus.ShouldHaveSubscriptionFor <UserValidated>(); }
public void Echo_reply_should_work() { var echoConsumer = new TestMessageConsumer <PingMessage>(); RemoteBus.Subscribe(echoConsumer); var replyConsumer = new TestMessageConsumer <PongMessage>(); LocalBus.Subscribe(replyConsumer); var echoMessage = new PingMessage(); LocalBus.Publish(echoMessage); echoConsumer.ShouldHaveReceivedMessage(echoMessage, _timeout); PongMessage replyMessage = new PongMessage(echoMessage.CorrelationId); RemoteBus.Publish(replyMessage); replyConsumer.ShouldHaveReceivedMessage(replyMessage, _timeout); }
protected override void EstablishContext() { base.EstablishContext(); var sagaRepository = new InMemorySagaRepository <ClaimRequestSaga>(); //these subscriptions are to replace the Timeout Service RemoteBus.SubscribeHandler <ScheduleTimeout>( x => { RemoteBus.ShouldHaveSubscriptionFor <TimeoutScheduled>(); RemoteBus.Publish(new TimeoutScheduled { CorrelationId = x.CorrelationId, TimeoutAt = x.TimeoutAt }); }); RemoteBus.SubscribeHandler <CancelTimeout>( x => { RemoteBus.ShouldHaveSubscriptionFor <TimeoutCancelled>(); RemoteBus.Publish(new TimeoutCancelled { CorrelationId = x.CorrelationId }); } ); //RemoteBus.SubscribeHandler<ClaimRequestCreatedPendingVerificationEvent>(x => // { // Debug.WriteLine("Claim Created Pending Verification event received."); // }); RemoteBus.SubscribeSaga(sagaRepository); //event messages that the Saga is subscribed to LocalBus.ShouldHaveSubscriptionFor <ClaimRequestCreatedPendingVerificationEvent>(); LocalBus.ShouldHaveSubscriptionFor <CardUseVerifiedEvent>(); LocalBus.ShouldHaveSubscriptionFor <TimeoutExpired>(); }