public void Constructor_DefaultServicesInContainer() { // Arrange var config = new ProcessorConfiguration(); // Act var defaultServices = new DefaultServices(config); // Assert Assert.IsType(typeof(DefaultCommandHandlerSelector), defaultServices.GetService(typeof(ICommandHandlerSelector))); Assert.IsType(typeof(DefaultCommandHandlerActivator), defaultServices.GetService(typeof(ICommandHandlerActivator))); Assert.IsType(typeof(DefaultCommandHandlerTypeResolver), defaultServices.GetService(typeof(ICommandHandlerTypeResolver))); Assert.IsType(typeof(DefaultAssembliesResolver), defaultServices.GetService(typeof(IAssembliesResolver))); Assert.IsType(typeof(DefaultInterceptionProvider), defaultServices.GetService(typeof(IInterceptionProvider))); object[] filterProviders = defaultServices.GetServices(typeof(IFilterProvider)).ToArray(); Assert.Equal(2, filterProviders.Length); Assert.IsType(typeof(ConfigurationFilterProvider), filterProviders[0]); Assert.IsType(typeof(HandlerFilterProvider), filterProviders[1]); Assert.IsType(typeof(DefaultCommandValidator), defaultServices.GetService(typeof(ICommandValidator))); object[] interceptors = defaultServices.GetServices(typeof(IInterceptor)).ToArray(); Assert.Equal(0, interceptors.Length); }
public void Constructor_DefaultServicesInContainer() { // Arrange var config = new ProcessorConfiguration(); // Act var defaultServices = new DefaultServices(config); // Assert Assert.IsType(typeof(DefaultCommandHandlerSelector), defaultServices.GetService(typeof(ICommandHandlerSelector))); Assert.IsType(typeof(DefaultCommandHandlerActivator), defaultServices.GetService(typeof(ICommandHandlerActivator))); Assert.IsType(typeof(DefaultCommandHandlerTypeResolver), defaultServices.GetService(typeof(ICommandHandlerTypeResolver))); Assert.IsType(typeof(DefaultAssembliesResolver), defaultServices.GetService(typeof(IAssembliesResolver))); Assert.IsType(typeof(DefaultInterceptionProvider), defaultServices.GetService(typeof(IInterceptionProvider))); object[] filterProviders = defaultServices.GetServices(typeof(IFilterProvider)).ToArray(); Assert.Equal(2, filterProviders.Length); Assert.IsType(typeof(ConfigurationFilterProvider), filterProviders[0]); Assert.IsType(typeof(HandlerFilterProvider), filterProviders[1]); Assert.IsType(typeof(DefaultCommandValidator), defaultServices.GetService(typeof(ICommandValidator))); object[] interceptors = defaultServices.GetServices(typeof(IInterceptor)).ToArray(); Assert.Equal(0, interceptors.Length); }
public void GetServices_GuardClauses() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); // Act & assert ExceptionAssert.ThrowsArgumentNull(() => defaultServices.GetServices(serviceType: null), "serviceType"); ExceptionAssert.ThrowsArgument(() => defaultServices.GetServices(typeof(object)), "serviceType"); }
public void AddRange_SkipsNullObjects() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); IEnumerable <object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider)); // Act defaultServices.AddRange(typeof(IFilterProvider), new object[] { null }); // Assert IEnumerable <object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider)); Assert.Equal(servicesBefore.ToArray(), servicesAfter.ToArray()); }
public void Add_AddsServiceToEndOfServicesList() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider = new Mock<IFilterProvider>().Object; IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider)); // Act defaultServices.Add(typeof(IFilterProvider), filterProvider); // Assert IEnumerable<object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider)); Assert.Equal(servicesBefore.Concat(new[] { filterProvider }).ToArray(), servicesAfter.ToArray()); }
public void AddRange_AddsServicesToEndOfServicesList() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider = new Mock <IFilterProvider>().Object; IEnumerable <object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider)); // Act defaultServices.AddRange(typeof(IFilterProvider), new[] { filterProvider }); // Assert IEnumerable <object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider)); Assert.Equal(servicesBefore.Concat(new[] { filterProvider }).ToArray(), servicesAfter.ToArray()); }
public void GetServices_CachesResultFromDependencyInjectionContainer() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var mockDependencyResolver = new Mock <IDependencyResolver>(); config.DependencyResolver = mockDependencyResolver.Object; // Act defaultServices.GetServices(typeof(IFilterProvider)); defaultServices.GetServices(typeof(IFilterProvider)); // Assert mockDependencyResolver.Verify(dr => dr.GetServices(typeof(IFilterProvider)), Times.Once()); }
public void GetServices_PrependsServiceInDependencyInjectionContainer() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); IEnumerable <object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider)); var filterProvider = new Mock <IFilterProvider>().Object; var mockDependencyResolver = new Mock <IDependencyResolver>(); mockDependencyResolver.Setup(dr => dr.GetServices(typeof(IFilterProvider))).Returns(new[] { filterProvider }); config.DependencyResolver = mockDependencyResolver.Object; // Act IEnumerable <object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider)); // Assert Assert.Equal(new[] { filterProvider }.Concat(servicesBefore).ToArray(), servicesAfter.ToArray()); }
private static IEnumerable <TService> GetServices <TService>(this DefaultServices services) { if (services == null) { throw Error.ArgumentNull("services"); } return(services.GetServices(typeof(TService)).Cast <TService>()); }
private void GetServices_CachesResultFromDependencyInjectionContainer_Impl(IDependencyResolver resolver) { DependencyResolverWrapper rw = new DependencyResolverWrapper(resolver, allowBeginScope: true); // Arrange HttpConfiguration config = new HttpConfiguration(); DefaultServices defaultServices = new DefaultServices(config); config.DependencyResolver = rw; // Act Object a = defaultServices.GetServices(typeof(IFilterProvider)); Object b = defaultServices.GetServices(typeof(IFilterProvider)); _ = a.ShouldNotBeNull(); _ = b.ShouldNotBeNull(); // Assert rw.GetServicesCalls.Count.ShouldBe(1); // mockDependencyResolver.Verify(dr => dr.GetServices(typeof(IFilterProvider)), Times.Once()); }
public void Clear_RemovesAllServices() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); // Act defaultServices.Clear(typeof(IFilterProvider)); // Assert Assert.Equal(0, defaultServices.GetServices(typeof(IFilterProvider)).Count()); }
public void GetServices_ReturnsEmptyEnumerationWhenServiceListEmpty() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); defaultServices.Clear(typeof(IFilterProvider)); // Act IEnumerable <object> services = defaultServices.GetServices(typeof(IFilterProvider)); // Assert Assert.Equal(0, services.Count()); }
public void ReplaceRange_ReplacesAllValuesWithTheGivenServices() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider1 = new Mock <IFilterProvider>().Object; var filterProvider2 = new Mock <IFilterProvider>().Object; // Act defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 }); // Assert Assert.Equal(new[] { filterProvider1, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider))); }
private void GetServices_PrependsServiceInDependencyInjectionContainer_Impl(IDependencyResolver resolver, IFilterProvider filterProviderInstance) { // Arrange HttpConfiguration config = new HttpConfiguration(); DefaultServices defaultServices = new DefaultServices(config); IEnumerable <object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider)); // var mockDependencyResolver = new Mock<IDependencyResolver>(); // mockDependencyResolver.Setup(dr => dr.GetServices(typeof(IFilterProvider))).Returns(new[] { filterProvider }); config.DependencyResolver = resolver; // Act IEnumerable <object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider)); // Assert Enumerable .SequenceEqual( new Object[] { filterProviderInstance }.Concat(servicesBefore), servicesAfter ) .ShouldBeTrue(); }
public void RemoteAt_RemovesService() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider1 = new Mock <IFilterProvider>().Object; var filterProvider2 = new Mock <IFilterProvider>().Object; defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 }); // Act defaultServices.RemoveAt(typeof(IFilterProvider), 1); // Assert Assert.Equal(new[] { filterProvider1 }, defaultServices.GetServices(typeof(IFilterProvider))); }
public void RemoveAll_SuccessfulMatch() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider1 = new Mock <IFilterProvider>().Object; var filterProvider2 = new Mock <IFilterProvider>().Object; defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 }); // Act defaultServices.RemoveAll(typeof(IFilterProvider), _ => true); // Assert Assert.Equal(0, defaultServices.GetServices(typeof(IFilterProvider)).Count()); }
public void Remove_ObjectNotFound() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider1 = new Mock <IFilterProvider>().Object; var filterProvider2 = new Mock <IFilterProvider>().Object; var notPresentFilterProvider = new Mock <IFilterProvider>().Object; defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 }); // Act defaultServices.Remove(typeof(IFilterProvider), notPresentFilterProvider); // Assert Assert.Equal(new[] { filterProvider1, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider))); }
public void GetServices_ReturnsEmptyEnumerationWhenServiceListEmpty() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); defaultServices.Clear(typeof(IFilterProvider)); // Act IEnumerable<object> services = defaultServices.GetServices(typeof(IFilterProvider)); // Assert Assert.Equal(0, services.Count()); }
public void GetServices_GuardClauses() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); // Act & assert ExceptionAssert.ThrowsArgumentNull(() => defaultServices.GetServices(serviceType: null), "serviceType"); ExceptionAssert.ThrowsArgument(() => defaultServices.GetServices(typeof(object)), "serviceType"); }
public void ReplaceRange_ReplacesAllValuesWithTheGivenServices() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider1 = new Mock<IFilterProvider>().Object; var filterProvider2 = new Mock<IFilterProvider>().Object; // Act defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 }); // Assert Assert.Equal(new[] { filterProvider1, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider))); }
public void RemoveAll_SuccessfulMatch() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider1 = new Mock<IFilterProvider>().Object; var filterProvider2 = new Mock<IFilterProvider>().Object; defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 }); // Act defaultServices.RemoveAll(typeof(IFilterProvider), _ => true); // Assert Assert.Equal(0, defaultServices.GetServices(typeof(IFilterProvider)).Count()); }
public void InsertRange_AddsElementAtTheRequestedLocation() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider1 = new Mock<IFilterProvider>().Object; var filterProvider2 = new Mock<IFilterProvider>().Object; var newFilterProvider1 = new Mock<IFilterProvider>().Object; var newFilterProvider2 = new Mock<IFilterProvider>().Object; defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 }); // Act defaultServices.InsertRange(typeof(IFilterProvider), 1, new[] { newFilterProvider1, newFilterProvider2 }); // Assert Assert.Equal(new[] { filterProvider1, newFilterProvider1, newFilterProvider2, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider))); }
public static IEnumerable <ModelValidatorProvider> GetModelValidatorProviders(this DefaultServices services) { return(services.GetServices <ModelValidatorProvider>()); }
public void GetServices_PrependsServiceInDependencyInjectionContainer() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider)); var filterProvider = new Mock<IFilterProvider>().Object; var mockDependencyResolver = new Mock<IDependencyResolver>(); mockDependencyResolver.Setup(dr => dr.GetServices(typeof(IFilterProvider))).Returns(new[] { filterProvider }); config.DependencyResolver = mockDependencyResolver.Object; // Act IEnumerable<object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider)); // Assert Assert.Equal(new[] { filterProvider }.Concat(servicesBefore).ToArray(), servicesAfter.ToArray()); }
public void GetServices_CachesResultFromDependencyInjectionContainer() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var mockDependencyResolver = new Mock<IDependencyResolver>(); config.DependencyResolver = mockDependencyResolver.Object; // Act defaultServices.GetServices(typeof(IFilterProvider)); defaultServices.GetServices(typeof(IFilterProvider)); // Assert mockDependencyResolver.Verify(dr => dr.GetServices(typeof(IFilterProvider)), Times.Once()); }
/// <summary> /// Get ValueProviderFactories. The order of returned providers is the priority order that we search the factories. /// </summary> public static IEnumerable <ValueProviderFactory> GetValueProviderFactories(this DefaultServices services) { return(services.GetServices <ValueProviderFactory>()); }
public void Remove_ObjectNotFound() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider1 = new Mock<IFilterProvider>().Object; var filterProvider2 = new Mock<IFilterProvider>().Object; var notPresentFilterProvider = new Mock<IFilterProvider>().Object; defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 }); // Act defaultServices.Remove(typeof(IFilterProvider), notPresentFilterProvider); // Assert Assert.Equal(new[] { filterProvider1, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider))); }
public static IEnumerable <IFilterProvider> GetFilterProviders(this DefaultServices services) { return(services.GetServices <IFilterProvider>()); }
public void RemoteAt_RemovesService() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider1 = new Mock<IFilterProvider>().Object; var filterProvider2 = new Mock<IFilterProvider>().Object; defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 }); // Act defaultServices.RemoveAt(typeof(IFilterProvider), 1); // Assert Assert.Equal(new[] { filterProvider1 }, defaultServices.GetServices(typeof(IFilterProvider))); }
public void AddRange_SkipsNullObjects() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); IEnumerable<object> servicesBefore = defaultServices.GetServices(typeof(IFilterProvider)); // Act defaultServices.AddRange(typeof(IFilterProvider), new object[] { null }); // Assert IEnumerable<object> servicesAfter = defaultServices.GetServices(typeof(IFilterProvider)); Assert.Equal(servicesBefore.ToArray(), servicesAfter.ToArray()); }
public void Clear_RemovesAllServices() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); // Act defaultServices.Clear(typeof(IFilterProvider)); // Assert Assert.Equal(0, defaultServices.GetServices(typeof(IFilterProvider)).Count()); }
public void InsertRange_AddsElementAtTheRequestedLocation() { // Arrange var config = new ProcessorConfiguration(); var defaultServices = new DefaultServices(config); var filterProvider1 = new Mock <IFilterProvider>().Object; var filterProvider2 = new Mock <IFilterProvider>().Object; var newFilterProvider1 = new Mock <IFilterProvider>().Object; var newFilterProvider2 = new Mock <IFilterProvider>().Object; defaultServices.ReplaceRange(typeof(IFilterProvider), new[] { filterProvider1, filterProvider2 }); // Act defaultServices.InsertRange(typeof(IFilterProvider), 1, new[] { newFilterProvider1, newFilterProvider2 }); // Assert Assert.Equal(new[] { filterProvider1, newFilterProvider1, newFilterProvider2, filterProvider2 }, defaultServices.GetServices(typeof(IFilterProvider))); }