public void SendAndReceiveWithTopicsCorrectly() { //Arrange IEventMessage receivedMessage = null; AutoResetEvent flag = new AutoResetEvent(false); var sender = _context.CreateMessageSender(); var receiver = _context.CreateMessageReceiver("TestQueue", new List <string>() { "test" }); receiver.DeclareQueue(); var message = new EventMessage("test", "TestMessage"); //Act sender.SendMessage(message); receiver.StartReceivingMessages(eventMessage => { receivedMessage = eventMessage; flag.Set(); }); flag.WaitOne(); //Assert Assert.IsNotNull(receivedMessage); Assert.AreEqual("TestMessage", receivedMessage.Message); }
public void CreateMessageSender_WithBusContextDisposed_ThrowsObjectDisposedException() { // Arrange var connectionMock = new Mock <IConnection>(); var context = new RabbitMQBusContext(connectionMock.Object, "TestExchange3"); context.Dispose(); // Act & Assert Assert.ThrowsException <ObjectDisposedException>(() => { context.CreateMessageSender(); }); }
public void CreateMessageSenderCreatesRabbitMQMessageSender() { Mock <IModel> channelMock = new Mock <IModel>(); Mock <IConnection> connectionMock = new Mock <IConnection>(MockBehavior.Strict); connectionMock.Setup(conn => conn.CreateModel()).Returns(channelMock.Object); var target = new RabbitMQBusContext(connectionMock.Object, "My.Test.ExchangeName"); // Act var sender = target.CreateMessageSender(); // Assert Assert.IsInstanceOfType(sender, typeof(RabbitMQMessageSender)); connectionMock.Verify(conn => conn.CreateModel()); }
public void CreateMessageSender_ReturnsMessageSenderWithCorrectProperties() { // Arrange var channelMock = new Mock <IModel>(MockBehavior.Strict); var connectionMock = new Mock <IConnection>(MockBehavior.Strict); connectionMock.Setup(c => c.CreateModel()) .Returns(channelMock.Object); var context = new RabbitMQBusContext(connectionMock.Object, "TestExchange3"); // Act RabbitMQMessageSender sender = (RabbitMQMessageSender)context.CreateMessageSender(); // Assert Assert.AreEqual("TestExchange3", sender.ExchangeName); IModel channel = TestHelper.GetPrivateProperty <IModel>(sender, "Channel"); Assert.AreEqual(channelMock.Object, channel); }