public void SendShouldSendCommandUsingSpecifiedEndpoint()
        {
            // Arrange
            var mockConfiguration       = new Mock <IConfiguration>();
            var mockProducer            = new Mock <IProducer>();
            var mockContainer           = new Mock <IBusContainer>();
            var mockProessManagerFinder = new Mock <IProcessManagerFinder>();
            var mockSendMessagePipeline = new Mock <ISendMessagePipeline>();

            mockConfiguration.Setup(x => x.GetSendMessagePipeline()).Returns(mockSendMessagePipeline.Object);
            mockConfiguration.Setup(x => x.GetContainer()).Returns(mockContainer.Object);
            mockConfiguration.Setup(x => x.GetProcessManagerFinder()).Returns(mockProessManagerFinder.Object);
            mockConfiguration.Setup(x => x.GetProducer()).Returns(mockProducer.Object);
            mockConfiguration.SetupGet(x => x.TransportSettings).Returns(new TransportSettings());

            var message = new FakeMessage1(Guid.NewGuid())
            {
                Username = "******"
            };

            const string endPoint = "MyEndPoint";

            mockProducer.Setup(x => x.Send(endPoint, typeof(FakeMessage1), It.IsAny <byte[]>(), null));

            // Act
            var bus = new ServiceConnect.Bus(mockConfiguration.Object);

            bus.Send(endPoint, message, null);

            // Assert

            mockSendMessagePipeline.Verify(x => x.ExecuteSendMessagePipeline(typeof(FakeMessage1), It.IsAny <byte[]>(), It.IsAny <Dictionary <string, string> >(), endPoint), Times.Once);
        }
        public void SendWithEndPointShouldGetProducerFromContainer()
        {
            // Arrange
            var mockConfiguration       = new Mock <IConfiguration>();
            var mockProducer            = new Mock <IProducer>();
            var mockContainer           = new Mock <IBusContainer>();
            var mockProessManagerFinder = new Mock <IProcessManagerFinder>();
            var mockSendMessagePipeline = new Mock <ISendMessagePipeline>();

            mockConfiguration.Setup(x => x.GetSendMessagePipeline()).Returns(mockSendMessagePipeline.Object);
            mockConfiguration.Setup(x => x.GetContainer()).Returns(mockContainer.Object);
            mockConfiguration.Setup(x => x.GetProcessManagerFinder()).Returns(mockProessManagerFinder.Object);
            mockConfiguration.Setup(x => x.GetProducer()).Returns(mockProducer.Object);
            mockConfiguration.SetupGet(x => x.TransportSettings).Returns(new TransportSettings());

            // Act
            var bus = new ServiceConnect.Bus(mockConfiguration.Object);

            bus.Send("EndPoint", new FakeMessage1(Guid.NewGuid()), null);

            // Assert
            mockConfiguration.Verify(x => x.GetProducer(), Times.Once());
        }
        public void SendShouldSendCommandUsingSpecifiedEndpoints()
        {
            // Arrange
            var mockConfiguration = new Mock<IConfiguration>();
            var mockProducer = new Mock<IProducer>();
            var mockContainer = new Mock<IBusContainer>();
            var mockProessManagerFinder = new Mock<IProcessManagerFinder>();

            mockConfiguration.Setup(x => x.GetContainer()).Returns(mockContainer.Object);
            mockConfiguration.Setup(x => x.GetProcessManagerFinder()).Returns(mockProessManagerFinder.Object);
            mockConfiguration.Setup(x => x.GetProducer()).Returns(mockProducer.Object);
            mockConfiguration.SetupGet(x => x.TransportSettings).Returns(new TransportSettings());

            var message = new FakeMessage1(Guid.NewGuid())
            {
                Username = "******"
            };

            List<string> endPoints = new List<string> { "MyEndPoint1", "MyEndPoint2" };

            foreach (string endPoint in endPoints)
            {
                mockProducer.Setup(x => x.Send(endPoint, typeof(FakeMessage1), It.IsAny<byte[]>(), null));
            }

            // Act
            var bus = new ServiceConnect.Bus(mockConfiguration.Object);
            bus.Send(endPoints, message, null);

            // Assert
            foreach (string endPoint in endPoints)
            {
                mockProducer.Verify(x => x.Send(endPoint, typeof(FakeMessage1), It.IsAny<byte[]>(), null), Times.Once);
            }
        }
        public void SendShouldSendCommand()
        {
            // Arrange
            var mockConfiguration = new Mock<IConfiguration>();
            var mockProducer = new Mock<IProducer>();
            var mockContainer = new Mock<IBusContainer>();
            var mockProessManagerFinder = new Mock<IProcessManagerFinder>();

            mockConfiguration.Setup(x => x.GetContainer()).Returns(mockContainer.Object);
            mockConfiguration.Setup(x => x.GetProcessManagerFinder()).Returns(mockProessManagerFinder.Object);
            mockConfiguration.Setup(x => x.GetProducer()).Returns(mockProducer.Object);
            mockConfiguration.SetupGet(x => x.TransportSettings).Returns(new TransportSettings());

            var message = new FakeMessage1(Guid.NewGuid())
            {
                Username = "******"
            };

            mockProducer.Setup(x => x.Send(typeof(FakeMessage1), It.IsAny<byte[]>(), null));

            // Act
            var bus = new ServiceConnect.Bus(mockConfiguration.Object);
            bus.Send(message, null);

            // Assert
            mockProducer.Verify(x => x.Send(typeof(FakeMessage1), It.IsAny<byte[]>(), null), Times.Once);
        }
        public void SendShouldGetProducerFromContainer()
        {
            // Arrange
            var mockConfiguration = new Mock<IConfiguration>();
            var mockProducer = new Mock<IProducer>();
            var mockContainer = new Mock<IBusContainer>();
            var mockProessManagerFinder = new Mock<IProcessManagerFinder>();

            mockConfiguration.Setup(x => x.GetContainer()).Returns(mockContainer.Object);
            mockConfiguration.Setup(x => x.GetProcessManagerFinder()).Returns(mockProessManagerFinder.Object);
            mockConfiguration.Setup(x => x.GetProducer()).Returns(mockProducer.Object);
            mockConfiguration.SetupGet(x => x.TransportSettings).Returns(new TransportSettings());

            // Act
            var bus = new ServiceConnect.Bus(mockConfiguration.Object);
            bus.Send(new FakeMessage1(Guid.NewGuid()), null);

            // Assert
            mockConfiguration.Verify(x => x.GetProducer(), Times.Once());
        }