public void RabbitMQBinding_TransactionalDispatching_ExceptionIfTransactionalChannelUsedOutOfTheTransactionScope() { IOneWayService channel = _channelFactory.CreateChannel(); Data data = new Data { Id = 1, Name = "Rabbit" }; A.CallTo(() => _errorProcessorFake.Say(A<Data>._)).DoesNothing(); A.CallTo(() => _processorFake.Say(A<Data>.Ignored)).Invokes(() => _ev.Set()); using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew)) { channel.Say(data); // Complete the transaction transaction.Complete(); } bool wait = _ev.Wait(TimeSpan.FromSeconds(10)); Assert.IsTrue(wait, "Service were not being invoked"); // Same channel instance can't be used outsode transaction scope channel.Say(new Data()); Assert.Fail("Same channel instance can't be used outsode transaction scope"); }
public void RabbitMQBinding_NonTransactionalDuplexWithPredefinedCallbackQueueDelivery() { IDuplexService channel = _channelFactory.CreateChannel(); Data data = new Data { Id = 1, Name = "Rabbit" }; A.CallTo(_errorProcessorFake).DoesNothing(); A.CallTo(() => _callbackFake.Say(A<Data>.Ignored)).Invokes(() => _ev.Set()); channel.Say(data); bool wait = _ev.Wait(TimeSpan.FromSeconds(10)); Assert.IsTrue(wait, "Callback were not being invoked"); A.CallTo(() => _processorFake.Say(A<Data>._)).WhenArgumentsMatch(collection => { data.ShouldBeEquivalentTo(collection[0]); return true; }).MustHaveHappened(Repeated.Like(i => i == 1)); A.CallTo(() => _callbackFake.Say(A<Data>._)).WhenArgumentsMatch(collection => { _replyData.ShouldBeEquivalentTo(collection[0]); return true; }).MustHaveHappened(Repeated.Like(i => i == 1)); }
public void RabbitMQBinding_TransactionalConsumption() { IOneWayService channel = _channelFactory.CreateChannel(); Data data = new Data { Id = 1, Name = "Rabbit" }; A.CallTo(() => _errorProcessorFake.Say(A<Data>._)).Throws(() => new Exception("Error while processing data")).Once(); A.CallTo(() => _processorFake.Say(A<Data>.Ignored)).Invokes(() => _ev.Set()); channel.Say(data); bool wait = _ev.Wait(TimeSpan.FromSeconds(10)); Assert.IsTrue(wait, "Service were not being invoked"); A.CallTo(() => _processorFake.Say(A<Data>._)).WhenArgumentsMatch(collection => { data.ShouldBeEquivalentTo(collection[0]); return true; }).MustHaveHappened(); }
public void Say(Data data) { _process.Say(data); IDuplexService callbackChannel = OperationContext.Current.GetCallbackChannel<IDuplexService>(); callbackChannel.Say(_replyData); }
public void RabbitMQBinding_TransactionalDispatching_MessagesCommited() { IOneWayService channel = _channelFactory.CreateChannel(); Data data = new Data { Id = 1, Name = "Rabbit" }; A.CallTo(() => _errorProcessorFake.Say(A<Data>._)).DoesNothing(); A.CallTo(() => _processorFake.Say(A<Data>.Ignored)).Invokes(() => _ev.Set()); using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.RequiresNew)) { channel.Say(data); // Complete the transaction transaction.Complete(); } bool wait = _ev.Wait(TimeSpan.FromSeconds(10)); Assert.IsTrue(wait, "Service were not being invoked"); A.CallTo(() => _processorFake.Say(A<Data>._)).WhenArgumentsMatch(collection => { data.ShouldBeEquivalentTo(collection[0]); return true; }).MustHaveHappened(); }
public void RabbitMQBinding_TransactionalDispatching_MessagesRollbacked() { IOneWayService channel = _channelFactory.CreateChannel(); Data data = new Data { Id = 1, Name = "Rabbit" }; A.CallTo(() => _errorProcessorFake.Say(A<Data>._)).DoesNothing(); A.CallTo(() => _processorFake.Say(A<Data>.Ignored)).Invokes(() => _ev.Set()); using (new TransactionScope(TransactionScopeOption.RequiresNew)) { channel.Say(data); channel.Say(data); // Do not call transaction complete } bool wait = _ev.Wait(TimeSpan.FromSeconds(10)); Assert.IsFalse(wait, "Service should not be invoked"); A.CallTo(() => _processorFake.Say(A<Data>._)).MustNotHaveHappened(); }
public void Say2(Data data) { _errorProcessor.Say(data); }
public void TestInitialize() { _replyData = new Data { Id = 2, Name = "Reply" }; _host = new ServiceHost(new DuplexService(_processorFake, _replyData)); const string serviceAddress = "amqp://localhost/myDuplexQueue?routingKey=DuplexService"; ServiceEndpoint endpoint = _host.AddServiceEndpoint(typeof (IDuplexService), new RabbitMQBinding { AutoBindExchange = "amq.direct", // If not null, queue will be automatically binded to the exchange using provided routingKey (if any) ExactlyOnce = false, // Non-transactional consumption, OneWayOnly = false, // Use False only if calback communication required //TTL = 1000, // Message time to leave in miliseconds //PersistentDelivery = true // If true, every message will be written to disk on rabbitMQ broker side before dispatching to the destination(s) }, serviceAddress); // Required behaviour for duplex comunication endpoint.Behaviors.Add(new ReplyToBehavior()); _host.Open(); const string clientAddress = "amqp://localhost/amq.direct?routingKey=DuplexService"; _channelFactory = new DuplexChannelFactory<IDuplexService>(new InstanceContext(_callbackFake), new RabbitMQBinding { OneWayOnly = false, AutoBindExchange = "amq.direct", ReplyToExchange = new Uri("amqp://localhost/amq.direct?routingKey=DuplexCallbackService"), ReplyToQueue = "myCallBackQueue?routingKey=DuplexCallbackService" }, clientAddress); _channelFactory.Open(); }
public DuplexService(IDuplexService process, Data replyData) { _process = process; _replyData = replyData; }