private IAdvancedBus CreateAdvancedBusMock(Action <ExchangeStub> exchangeCreated, Action <ExchangeStub, ExchangeStub> exchangeBound, Func <Type, string> nameExchange) { var advancedBus = Substitute.For <IAdvancedBus>(); advancedBus.ExchangeDeclare(null, null, false, true, false, false, null) .ReturnsForAnyArgs(mi => { var exchange = new ExchangeStub { Name = (string)mi[0] }; exchangeCreated(exchange); return(exchange); }); advancedBus.Bind(Arg.Any <IExchange>(), Arg.Any <IExchange>(), Arg.Is("#")) .Returns(mi => { var source = (ExchangeStub)mi[0]; var destination = (ExchangeStub)mi[1]; exchangeBound(source, destination); return(Substitute.For <IBinding>()); }); var conventions = Substitute.For <IConventions>(); conventions.ExchangeNamingConvention = t => nameExchange(t); var container = Substitute.For <IContainer>(); container.Resolve <IConventions>().Returns(conventions); advancedBus.Container.Returns(container); return(advancedBus); }
private IAdvancedBus CreateAdvancedBusMock( Action<ExchangeStub> exchangeCreated, Action<ExchangeStub, ExchangeStub> exchangeBound, Func<Type,string> nameExchange ) { var advancedBus = MockRepository.GenerateStub<IAdvancedBus>(); advancedBus.Stub( b => b.ExchangeDeclare( null, null, false, true, false, false, null ) ) .IgnoreArguments() .WhenCalled( mi => { var exchange = new ExchangeStub {Name = (string) mi.Arguments[ 0 ]}; exchangeCreated( exchange ); mi.ReturnValue = exchange; } ); advancedBus.Stub( b => b.Bind( Arg<IExchange>.Is.Anything, Arg<IExchange>.Is.Anything, Arg<string>.Is.Equal( "#" ) ) ) .Return( null ) .WhenCalled( mi => { var source = (ExchangeStub) mi.Arguments[ 0 ]; var destination = (ExchangeStub) mi.Arguments[ 1 ]; exchangeBound( source, destination ); mi.ReturnValue = MockRepository.GenerateStub<IBinding>(); } ); var conventions = MockRepository.GenerateStub<IConventions>(); conventions.ExchangeNamingConvention = t => nameExchange( t ); var container = MockRepository.GenerateStub<IContainer>(); container.Stub( c => c.Resolve<IConventions>() ).Return( conventions ); advancedBus.Stub( b => b.Container ).Return( container ); return advancedBus; }
public void When_declaring_exchanges_for_versioned_message_exchange_per_version_created_and_bound_to_superceding_version() { var exchanges = new List <ExchangeStub>(); var advancedBus = Substitute.For <IAdvancedBus>(); advancedBus.ExchangeDeclare(null, null, false, true, false, false, null) .ReturnsForAnyArgs(mi => { var exchange = new ExchangeStub { Name = (string)mi[0] }; exchanges.Add(exchange); return(exchange); }); advancedBus.Bind(Arg.Any <IExchange>(), Arg.Any <IExchange>(), Arg.Is("#")) .Returns(mi => { var source = (ExchangeStub)mi[0]; var destination = (ExchangeStub)mi[1]; source.BoundTo = destination; return(Substitute.For <IBinding>()); }); var conventions = Substitute.For <IConventions>(); conventions.ExchangeNamingConvention = t => t.Name; var publishExchangeStrategy = new VersionedExchangeDeclareStrategy(conventions, advancedBus); publishExchangeStrategy.DeclareExchange(typeof(MyMessageV2), ExchangeType.Topic); Assert.Equal(2, exchanges.Count); //, "Two exchanges should have been created" ); Assert.Equal("MyMessage", exchanges[0].Name); //, "Superseded message exchange should been created first" ); Assert.Equal("MyMessageV2", exchanges[1].Name); //, "Superseding message exchange should been created second" ); Assert.Equal(exchanges[0], exchanges[1].BoundTo); //, "Superseding message exchange should route message to superseded exchange" ); Assert.Null(exchanges[0].BoundTo); //, "Superseded message exchange should route messages anywhere" ); }
private IAdvancedBus CreateAdvancedBusMock(Action <ExchangeStub> exchangeCreated, Action <ExchangeStub, ExchangeStub> exchangeBound, Func <Type, string> nameExchange) { var advancedBus = MockRepository.GenerateStub <IAdvancedBus>(); advancedBus.Stub(b => b.ExchangeDeclareAsync(null, null, false, true, false, false, null)) .IgnoreArguments() .Return(null) .WhenCalled(mi => { var exchange = new ExchangeStub { Name = (string)mi.Arguments[0] }; exchangeCreated(exchange); mi.ReturnValue = TaskHelpers.FromResult <IExchange>(exchange); }); advancedBus.Stub(b => b.BindAsync(Arg <IExchange> .Is.Anything, Arg <IExchange> .Is.Anything, Arg <string> .Is.Equal("#"))) .Return(null) .WhenCalled(mi => { var source = (ExchangeStub)mi.Arguments[0]; var destination = (ExchangeStub)mi.Arguments[1]; exchangeBound(source, destination); mi.ReturnValue = TaskHelpers.FromResult(MockRepository.GenerateStub <IBinding>()); }); var conventions = MockRepository.GenerateStub <IConventions>(); conventions.ExchangeNamingConvention = t => nameExchange(t); var container = MockRepository.GenerateStub <IContainer>(); container.Stub(c => c.Resolve <IConventions>()).Return(conventions); advancedBus.Stub(b => b.Container).Return(container); return(advancedBus); }
public void When_declaring_exchanges_for_unversioned_message_one_exchange_created() { var exchanges = new List <ExchangeStub>(); IAdvancedBus ret; var advancedBus = Substitute.For <IAdvancedBus>(); advancedBus.ExchangeDeclare(null, null, false, true, false, false, null) .ReturnsForAnyArgs(mi => { var exchange = new ExchangeStub { Name = (string)mi[0] }; exchanges.Add(exchange); return(exchange); }); advancedBus.Bind(Arg.Any <IExchange>(), Arg.Any <IExchange>(), Arg.Is("#")) .Returns(mi => { var source = (ExchangeStub)mi[0]; var destination = (ExchangeStub)mi[1]; source.BoundTo = destination; return(Substitute.For <IBinding>()); }); var conventions = Substitute.For <IConventions>(); conventions.ExchangeNamingConvention = t => t.Name; var publishExchangeStrategy = new VersionedPublishExchangeDeclareStrategy(conventions, advancedBus); publishExchangeStrategy.DeclareExchange(typeof(MyMessage), ExchangeType.Topic); Assert.Equal(1, exchanges.Count); //, "Single exchange should have been created" ); Assert.Equal("MyMessage", exchanges[0].Name); //, "Exchange should have used naming convection to name the exchange" ); Assert.Null(exchanges[0].BoundTo); // "Unversioned message should not create any exchange to exchange bindings" ); }
private void BindExchanges(ExchangeStub source, ExchangeStub destination) { source.BoundTo = destination; }
private void BindExchanges( ExchangeStub source, ExchangeStub destination ) { source.BoundTo = destination; }