public void MessagePublisherCallsBasicPublish() { // Arrange var connectionMock = new Mock <IConnection>(); var contextMock = new Mock <IBusContext <IConnection> >(); var modelMock = new Mock <IModel>(); contextMock.SetupGet(e => e.Connection).Returns(connectionMock.Object); connectionMock.Setup(e => e.CreateModel()).Returns(modelMock.Object); modelMock.Setup(e => e.CreateBasicProperties()).Returns(new BasicProperties()); var publisher = new RabbitMqMessagePublisher(contextMock.Object); var message = new EventMessage(); // Act publisher.SendMessage(message); // Assert modelMock.Verify(e => e.BasicPublish(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <IBasicProperties>(), It.IsAny <byte[]>())); }
public void SetUp() { routingTopology = new ConventionalRoutingTopology(); receivedMessages = new BlockingCollection <TransportMessage>(); var config = new ConnectionConfiguration(); config.ParseHosts("localhost:5672"); var selectionStrategy = new DefaultClusterHostSelectionStrategy <ConnectionFactoryInfo>(); var connectionFactory = new ConnectionFactoryWrapper(config, selectionStrategy); connectionManager = new RabbitMqConnectionManager(connectionFactory, config); unitOfWork = new RabbitMqUnitOfWork { ConnectionManager = connectionManager, UsePublisherConfirms = true, MaxWaitTimeForConfirms = TimeSpan.FromSeconds(10) }; sender = new RabbitMqMessageSender { UnitOfWork = unitOfWork, RoutingTopology = routingTopology }; dequeueStrategy = new RabbitMqDequeueStrategy { ConnectionManager = connectionManager, PurgeOnStartup = true }; MakeSureQueueAndExchangeExists(ReceiverQueue); MessagePublisher = new RabbitMqMessagePublisher { UnitOfWork = unitOfWork, RoutingTopology = routingTopology }; subscriptionManager = new RabbitMqSubscriptionManager { ConnectionManager = connectionManager, EndpointQueueName = ReceiverQueue, RoutingTopology = routingTopology }; dequeueStrategy.Init(Address.Parse(ReceiverQueue), TransactionSettings.Default, m => { receivedMessages.Add(m); return(true); }, (s, exception) => { }); dequeueStrategy.Start(MaximumConcurrency); }
public void SetUp() { routingTopology = new ConventionalRoutingTopology(true); receivedMessages = new BlockingCollection <TransportMessage>(); var config = new ConnectionConfiguration(); config.ParseHosts("localhost:5672"); var connectionFactory = new RabbitMqConnectionFactory(config); connectionManager = new RabbitMqConnectionManager(connectionFactory, config); publishChannel = connectionManager.GetPublishConnection().CreateModel(); var channelProvider = new FakeChannelProvider(publishChannel); sender = new RabbitMqMessageSender(routingTopology, channelProvider, new IncomingContext(null, null)); dequeueStrategy = new RabbitMqDequeueStrategy(connectionManager, new RepeatedFailuresOverTimeCircuitBreaker("UnitTest", TimeSpan.FromMinutes(2), e => {}), new ReceiveOptions(s => SecondaryReceiveSettings.Enabled(CallbackQueue, 1), new MessageConverter(), 1, 1000, false, "Unit test")); MakeSureQueueAndExchangeExists(ReceiverQueue); MessagePublisher = new RabbitMqMessagePublisher { ChannelProvider = channelProvider, RoutingTopology = routingTopology }; subscriptionManager = new RabbitMqSubscriptionManager { ConnectionManager = connectionManager, EndpointQueueName = ReceiverQueue, RoutingTopology = routingTopology }; dequeueStrategy.Init(Address.Parse(ReceiverQueue), new TransactionSettings(true, TimeSpan.FromSeconds(30), IsolationLevel.ReadCommitted, 5, false, false), m => { receivedMessages.Add(m); return(true); }, (s, exception) => { }); dequeueStrategy.Start(MaximumConcurrency); }
public void SetUp() { var routingTopology = new ConventionalRoutingTopology(); receivedMessages = new BlockingCollection<TransportMessage>(); var config = new ConnectionConfiguration(); config.ParseHosts("localhost:5672"); var selectionStrategy = new DefaultClusterHostSelectionStrategy<ConnectionFactoryInfo>(); var connectionFactory = new ConnectionFactoryWrapper(config, selectionStrategy); connectionManager = new RabbitMqConnectionManager(connectionFactory, config); unitOfWork = new RabbitMqUnitOfWork { ConnectionManager = connectionManager,UsePublisherConfirms = true,MaxWaitTimeForConfirms = TimeSpan.FromSeconds(10) }; sender = new RabbitMqMessageSender { UnitOfWork = unitOfWork, RoutingTopology = routingTopology }; dequeueStrategy = new RabbitMqDequeueStrategy { ConnectionManager = connectionManager, PurgeOnStartup = true }; MakeSureQueueExists(MYRECEIVEQUEUE); DeleteExchange(MYRECEIVEQUEUE); MakeSureExchangeExists(ExchangeNameConvention(Address.Parse(MYRECEIVEQUEUE),null)); MessagePublisher = new RabbitMqMessagePublisher { UnitOfWork = unitOfWork, RoutingTopology = routingTopology }; subscriptionManager = new RabbitMqSubscriptionManager { ConnectionManager = connectionManager, EndpointQueueName = MYRECEIVEQUEUE, RoutingTopology = routingTopology }; dequeueStrategy.Init(Address.Parse(MYRECEIVEQUEUE), TransactionSettings.Default, (m) => { receivedMessages.Add(m); return true; }, (s, exception) => { }); dequeueStrategy.Start(1); }
public void MessagePublisherCreatesChannel() { // Arrange Mock <IConnection> connectionMock = new Mock <IConnection>(); Mock <IBusContext <IConnection> > contextMock = new Mock <IBusContext <IConnection> >(); Mock <IModel> modelMock = new Mock <IModel>(); contextMock.SetupGet(e => e.Connection).Returns(connectionMock.Object); connectionMock.Setup(e => e.CreateModel()).Returns(modelMock.Object); modelMock.Setup(e => e.CreateBasicProperties()).Returns(new BasicProperties()); var publisher = new RabbitMqMessagePublisher(contextMock.Object); var message = new EventMessage(); // Act publisher.SendMessage(message); // Assert connectionMock.Setup(e => e.CreateModel()); }
public void MessagePublisherCallsBasicPublishWithExpectedValues(string exchange, string routingKey, string type, string body) { // Arrange byte[] bodyBytes = Encoding.Unicode.GetBytes(body); var connectionMock = new Mock <IConnection>(); var contextMock = new Mock <IBusContext <IConnection> >(); var modelMock = new Mock <IModel>(); contextMock.SetupGet(e => e.Connection).Returns(connectionMock.Object); contextMock.SetupGet(e => e.ExchangeName).Returns(exchange); connectionMock.Setup(e => e.CreateModel()).Returns(modelMock.Object); modelMock.Setup(e => e.CreateBasicProperties()).Returns(new BasicProperties()); var publisher = new RabbitMqMessagePublisher(contextMock.Object); Guid guid = Guid.NewGuid(); var message = new EventMessage { Body = bodyBytes, EventType = type, CorrelationId = guid, Topic = routingKey }; // Act publisher.SendMessage(message); // Assert modelMock.Verify(e => e.BasicPublish(exchange, routingKey, false, It.Is <IBasicProperties>(p => p.Type == type && p.CorrelationId == guid.ToString() && message.Timestamp.Equals(p.Timestamp.UnixTime)), bodyBytes) ); }