Example #1
0
        public void AddFactory_WithFactoryAlreadyRegistered_DoesNothing()
        {
            // Arrange
            var cache = new SenderCache(requestRouter, monitorCache);

            cache.AddFactory(factory);

            // Act
            cache.AddFactory(factory);

            // Assert
            Assert.That(cache.Factories.Count, Is.EqualTo(1));
            mockMonitorCache.Verify(m => m.AddMonitor(It.IsIn(senderMonitor)), Times.Once);
        }
Example #2
0
        public Builder WithTransport <TTransport>()
            where TTransport : ITransportConfig
        {
            var transport = Activator.CreateInstance <TTransport>();

            if (null != transport.SenderFactory)
            {
                SenderCache.AddFactory(transport.SenderFactory);
            }

            if (null != transport.ReceiverFactory)
            {
                ReceiverCache.AddFactory(transport.ReceiverFactory);
            }

            if (null != transport.PublisherFactory)
            {
                PublisherCache.AddFactory(transport.PublisherFactory);
            }

            if (null != transport.SubscriberFactory)
            {
                SubscriberCache.AddFactory(transport.SubscriberFactory);
            }

            return(this);
        }
Example #3
0
        public Builder WithTransport <TTransport>(TTransport transport, Action <ITransportSetup> config)
            where TTransport : ITransportConfig
        {
            if (null != transport.SenderFactory)
            {
                SenderCache.AddFactory(transport.SenderFactory);
            }

            if (null != transport.ReceiverFactory)
            {
                ReceiverCache.AddFactory(transport.ReceiverFactory);
            }

            if (null != transport.PublisherFactory)
            {
                PublisherCache.AddFactory(transport.PublisherFactory);
            }

            if (null != transport.SubscriberFactory)
            {
                SubscriberCache.AddFactory(transport.SubscriberFactory);
            }

            config(transport.Configurer);

            return(this);
        }
Example #4
0
        public void AddFactory_WithFactory_AddsSenderMonitorToMonitorCache()
        {
            // Arrange
            var cache = new SenderCache(requestRouter, monitorCache);

            // Act
            cache.AddFactory(factory);

            // Assert
            mockMonitorCache.Verify(m => m.AddMonitor(It.IsIn(senderMonitor)), Times.Once);
        }
Example #5
0
        public void AddFactory_WithFactory_AddsToFactory()
        {
            // Arrange
            var cache = new SenderCache(requestRouter, monitorCache);

            // Act
            cache.AddFactory(factory);

            // Assert
            CollectionAssert.Contains(cache.Factories, factory);
        }
Example #6
0
        public void AddFactory_WithNullFactory_ThrowsArgumentNullException()
        {
            // Arrange
            var cache = new SenderCache(requestRouter, monitorCache);

            // Act
            TestDelegate addFactory = () => cache.AddFactory(null);

            // Assert
            Assert.That(addFactory, Throws.ArgumentNullException);
        }
Example #7
0
        public void SenderFor_WithNoPreresolvedSender_AddsMonitorToMonitorCache()
        {
            // Arrange
            var cache = new SenderCache(requestRouter, monitorCache);

            cache.AddFactory(factory);

            // Act
            var resolvedSender = cache.SenderFor <object>();

            // Assert
            mockMonitorCache.Verify(m => m.AddMonitor(It.IsIn(senderMonitor)), Times.Once);
        }
Example #8
0
        public void SenderFor_WhenCalledTwice_CallsFactoryOnce()
        {
            // Arrange
            var cache = new SenderCache(requestRouter, monitorCache);

            cache.AddFactory(factory);

            // Act
            var sender1 = cache.SenderFor <object>();
            var sender2 = cache.SenderFor <object>();

            // Assert
            mockFactory.Verify(m => m.CreateSender(It.IsIn(address)), Times.Once);
        }
Example #9
0
        public void SenderFor_WhenCalledTwice_ReturnsTheSameInstance()
        {
            // Arrange
            var cache = new SenderCache(requestRouter, monitorCache);

            cache.AddFactory(factory);

            // Act
            var sender1 = cache.SenderFor <object>();
            var sender2 = cache.SenderFor <object>();

            // Assert
            Assert.That(sender1, Is.SameAs(sender2));
        }
Example #10
0
        public void SetupMirroredResponse <TMessage>(SenderCache senderCache, TMessage response) where TMessage : class
        {
            mockSender
            .Setup(m => m.SendAndReceive(It.IsAny <object>(), It.IsAny <TimeSpan>()))
            .ReturnsAsync(response);

            var senderRouting = SenderRouting.For <ISender>(address);

            mockRequestRouter
            .Setup(m => m.RoutingFor <object>(out senderRouting))
            .Returns(true);

            mockFactory
            .Setup(m => m.CreateSender(It.IsAny <IAddress>()))
            .Returns(sender);

            senderCache.AddFactory(factory);
        }
Example #11
0
        public void SenderFor_WithRoutingAndFactory_ReturnsSender()
        {
            // Arrange
            var cache         = new SenderCache(requestRouter, monitorCache);
            var senderRouting = SenderRouting.For <ISender>(address);

            mockRequestRouter
            .Setup(m => m.RoutingFor <object>(out senderRouting))
            .Returns(true);

            mockFactory
            .Setup(m => m.CreateSender(It.IsAny <IAddress>()))
            .Returns(sender);

            cache.AddFactory(factory);

            // Act
            var resolvedSender = cache.SenderFor <object>();

            // Assert
            Assert.That(resolvedSender, Is.EqualTo(sender));
        }