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); }
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); }
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); }
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); }
public void AddFactory_WithFactory_AddsToFactory() { // Arrange var cache = new SenderCache(requestRouter, monitorCache); // Act cache.AddFactory(factory); // Assert CollectionAssert.Contains(cache.Factories, factory); }
public void AddFactory_WithNullFactory_ThrowsArgumentNullException() { // Arrange var cache = new SenderCache(requestRouter, monitorCache); // Act TestDelegate addFactory = () => cache.AddFactory(null); // Assert Assert.That(addFactory, Throws.ArgumentNullException); }
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); }
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); }
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)); }
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); }
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)); }