Beispiel #1
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 #2
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 #3
0
        public void AddReceiver_WithNoMatchingFactory_ThrowsMissingFactoryException()
        {
            // Arrange
            var cache = new ReceiverCache(monitorCache);

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

            // Assert
            Assert.That(addReceiver, Throws.TypeOf <MissingFactoryException>());
        }
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 AddReceiver_WithNullAddress_ThrowsArgumentNullException()
        {
            // Arrange
            var cache = new ReceiverCache(monitorCache);

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

            // Assert
            Assert.That(addReceiver, Throws.ArgumentNullException);
        }
Beispiel #6
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 #7
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 #8
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 #9
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);
        }
Beispiel #10
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 #11
0
        public Builder(string name)
        {
            this.name          = name;
            TopicRouter        = new TopicRouter();
            MonitorCache       = new MonitorCache();
            RequestRouter      = new RequestRouter();
            PackageFactory     = new PackageFactory();
            TopicDispatcher    = new TopicDispatcher();
            RequestDispatcher  = new RequestDispatcher();
            SubscriptionsCache = new SubscriptionsCache();
            SerializerCache    = new SerializerCache();

            SenderCache     = new SenderCache(RequestRouter, MonitorCache);
            ReceiverCache   = new ReceiverCache(MonitorCache);
            PublisherCache  = new PublisherCache(MonitorCache);
            SubscriberCache = new SubscriberCache(TopicRouter, MonitorCache, SubscriptionsCache);
        }
Beispiel #12
0
 public Builder WithReceiver <TReceiver>(IAddress address)
     where TReceiver : IReceiver
 {
     ReceiverCache.AddReceiver <TReceiver>(address);
     return(this);
 }