Example #1
0
        public void WhenGettingServiceWithOverrideThenReturnsOverride()
       {
           ProcessorConfiguration config = new ProcessorConfiguration();
           HandlerServices services = new HandlerServices(config.Services);

           ICommandHandlerTypeResolver newLocalService = new Mock<ICommandHandlerTypeResolver>().Object;
           services.Replace(typeof(ICommandHandlerTypeResolver), newLocalService);

           // Act            
           ICommandHandlerTypeResolver localVal = (ICommandHandlerTypeResolver)services.GetService(typeof(ICommandHandlerTypeResolver));
           ICommandHandlerTypeResolver globalVal = (ICommandHandlerTypeResolver)config.Services.GetService(typeof(ICommandHandlerTypeResolver));

           // Assert
           // Local handler didn't override, should get same value as global case.
           Assert.Same(localVal, newLocalService);
           Assert.NotSame(localVal, globalVal);
       }
Example #2
0
       public void WhenGettingServiceWithDependencyInjectionThenReturnsFromDependencyInjection()
       {
           // Setting on Handler config overrides the DI container. 
           ProcessorConfiguration config = new ProcessorConfiguration();

           ICommandHandlerTypeResolver newDiService = new Mock<ICommandHandlerTypeResolver>().Object;
           var mockDependencyResolver = new Mock<IDependencyResolver>();
           mockDependencyResolver.Setup(dr => dr.GetService(typeof(ICommandHandlerTypeResolver))).Returns(newDiService);
           config.DependencyResolver = mockDependencyResolver.Object;

           HandlerServices services = new HandlerServices(config.Services);

           ICommandHandlerTypeResolver newLocalService = new Mock<ICommandHandlerTypeResolver>().Object;
           services.Replace(typeof(ICommandHandlerTypeResolver), newLocalService);

           // Act            
           ICommandHandlerTypeResolver localVal = (ICommandHandlerTypeResolver)services.GetService(typeof(ICommandHandlerTypeResolver));
           ICommandHandlerTypeResolver globalVal = (ICommandHandlerTypeResolver)config.Services.GetService(typeof(ICommandHandlerTypeResolver));

           // Assert
           // Local handler didn't override, should get same value as global case.            
           Assert.Same(newDiService, globalVal); // asking the config will give back the DI service
           Assert.Same(newLocalService, localVal); // but asking locally will get back the local service.
       }
Example #3
0
       public void WhenSettingOverrideToNullThenReturnsNull()
       {
           ProcessorConfiguration config = new ProcessorConfiguration();
           ServicesContainer global = config.Services;

           HandlerServices services = new HandlerServices(global);

           // Act
           // Setting to null is not the same as clear. Clear() means fall through to global config. 
           services.Replace(typeof(ICommandHandlerTypeResolver), null);

           // Assert
           ICommandHandlerTypeResolver localVal = (ICommandHandlerTypeResolver)services.GetService(typeof(ICommandHandlerTypeResolver));

           Assert.Null(localVal);
       }
Example #4
0
       public void WhenClearingOverridedServiceThenReturnsOriginal()
       {
           ProcessorConfiguration config = new ProcessorConfiguration();
           ServicesContainer global = config.Services;

           HandlerServices services = new HandlerServices(global);
           ICommandHandlerTypeResolver newLocalService = new Mock<ICommandHandlerTypeResolver>().Object;
           services.Replace(typeof(ICommandHandlerTypeResolver), newLocalService);

           // Act
           services.Clear(typeof(ICommandHandlerTypeResolver));

           // Assert
           ICommandHandlerTypeResolver localVal = (ICommandHandlerTypeResolver)services.GetService(typeof(ICommandHandlerTypeResolver));
           ICommandHandlerTypeResolver globalVal = (ICommandHandlerTypeResolver)global.GetService(typeof(ICommandHandlerTypeResolver));

           Assert.Same(globalVal, localVal);
       }