Beispiel #1
0
        public void AddFactory_WithFactoryAlreadyAdded_DoesNothing()
        {
            // Arrange
            var cache = new ReceiverCache(monitorCache);

            cache.AddFactory(receiverFactory);

            // Act
            cache.AddFactory(receiverFactory);

            // Assert
            CollectionAssert.Contains(cache.ReceiverFactories, receiverFactory);
            Assert.That(cache.ReceiverFactories.Count, Is.EqualTo(1));
            mockMonitorCache.Verify(m => m.AddMonitor(It.IsIn(receiverMonitor)), Times.Once);
        }
Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #4
0
        public void AddFactory_WithNullFactory_ThrowsArgumentNullExecption()
        {
            // Arrange
            var cache = new ReceiverCache(monitorCache);

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

            // Assert
            Assert.That(addFactory, Throws.ArgumentNullException);
        }
Beispiel #5
0
        public void AddFactory_WithFactory_AddsMonitorToMonitorCache()
        {
            // Arrange
            var cache = new ReceiverCache(monitorCache);

            // Act
            cache.AddFactory(receiverFactory);

            // Assert
            mockMonitorCache.Verify(m => m.AddMonitor(It.IsIn(receiverMonitor)), Times.Once);
        }
Beispiel #6
0
        public void AddFactory_WithFactory_AddsToFactoryCollection()
        {
            // Arrange
            var cache = new ReceiverCache(monitorCache);

            // Act
            cache.AddFactory(receiverFactory);

            // Assert
            CollectionAssert.Contains(cache.ReceiverFactories, receiverFactory);
            Assert.That(cache.ReceiverFactories.Count, Is.EqualTo(1));
        }
Beispiel #7
0
        public void AddReceiver_WithFactory_CallsFactoryCreateReceiver()
        {
            // Arrange
            var cache = new ReceiverCache(monitorCache);

            cache.AddFactory(receiverFactory);

            // Act
            cache.AddReceiver <IReceiver>(address);

            // Assert
            mockReceiverFactory.Verify(m => m.CreateReceiver(It.IsIn(address)), Times.Once);
        }
Beispiel #8
0
        public void AddReceiver_WithExistingReceiverForAddress_ThrowsInvalidOperationException()
        {
            // Arrange
            var address = TcpAddress.Wildcard(5555);
            var cache   = new ReceiverCache(monitorCache);

            cache.AddFactory(receiverFactory);
            cache.AddReceiver <IReceiver>(address);

            // Act
            TestDelegate addReceiver = () => cache.AddReceiver <IReceiver>(address);

            // Assert
            Assert.That(addReceiver, Throws.InvalidOperationException);
        }