Example #1
0
        public void UseCorrelation_AddsAllServices()
        {
            var hostBuilder = new Mock <IWebHostBuilder>();

            Action <IServiceCollection> configActionPassed = null;

            hostBuilder
            .Setup(b => b.ConfigureServices(It.IsAny <Action <IServiceCollection> >()))
            .Callback <Action <IServiceCollection> >((configAction) =>
            {
                configActionPassed = configAction;
            });

            hostBuilder.Object.PropagateIstioHeaders();

            var serviceCollection = new MockServiceCollection();

            configActionPassed(serviceCollection);

            Assert.Equal(5, serviceCollection.Count);
            Assert.Equal(1, serviceCollection.Count(d => d.ServiceType == typeof(IstioHeadersFetcherMiddleware) && d.Lifetime == ServiceLifetime.Transient));
            Assert.Equal(1, serviceCollection.Count(d => d.ServiceType == typeof(HeadersPropagationDelegatingHandler) && d.Lifetime == ServiceLifetime.Transient));
            Assert.Equal(1, serviceCollection.Count(d => d.ServiceType == typeof(IIstioHeadersHolder) && d.ImplementationType == typeof(IstioHeadersHolder) && d.Lifetime == ServiceLifetime.Scoped));
            Assert.Equal(1, serviceCollection.Count(d => d.ServiceType == typeof(IStartupFilter) && d.ImplementationType == typeof(IstioHeadersFetcherMiddlewareStartupFilter) && d.Lifetime == ServiceLifetime.Singleton));
            Assert.Equal(1, serviceCollection.Count(d => d.ServiceType == typeof(IHttpMessageHandlerBuilderFilter) && d.ImplementationType == typeof(HeadersPropagationMessageHandlerBuilderFilter) && d.Lifetime == ServiceLifetime.Singleton));
        }
        public void RegisterGlobalServicesRegistersIFindCustomerService()
        {
            TestableModuleInitializer module            = new TestableModuleInitializer();
            MockServiceCollection     serviceCollection = new MockServiceCollection();

            module.TestAddGlobalServices(serviceCollection);

            Assert.IsTrue(serviceCollection.RegistedServices.ContainsKey(typeof(IFindCustomerService)));
        }
        public void RegisterModuleServicesRegistrersOneServiceThatIsIAccountServiceAgent()
        {
            TestableEFTModuleInitializer module            = new TestableEFTModuleInitializer();
            MockServiceCollection        serviceCollection = new MockServiceCollection();

            module.TestAddModuleServices(serviceCollection);

            Assert.AreEqual(1, serviceCollection.RegistedServices.Keys.Count);
            Assert.IsTrue(serviceCollection.RegistedServices.ContainsKey(typeof(IAccountServiceAgent)));
        }
        public void ConfigureShouldNotThrowExceptionIfAuthorizationServicesIsNotLoaded()
        {
            MockServiceCollection collection = new MockServiceCollection();

            TestableModuleInitializer module = new TestableModuleInitializer();
            module.Configure(collection, ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));

            MockAuthorizationRulesService authRulesServices =
                (MockAuthorizationRulesService)collection.Get<IAuthorizationRulesService>();

            Assert.IsNull(authRulesServices);
        }
    public void RegisterTransient_ExpectSourceServices(bool isNotNull)
    {
        var mockServices   = MockServiceCollection.CreateMock();
        var sourceServices = mockServices.Object;

        RecordType regService = isNotNull ? PlusFifteenIdSomeStringNameRecord : null !;
        var        registrar  = DependencyRegistrar.Create(sourceServices, _ => regService);

        var actualServices = registrar.RegisterTransient();

        Assert.Same(sourceServices, actualServices);
    }
Example #6
0
    public void ToRegistrar_DependencyIsNull_ExpectArgumentNullException()
    {
        var mockServices   = MockServiceCollection.CreateMock();
        var sourceServices = mockServices.Object;

        Dependency <RefType> dependency = null !;

        var ex = Assert.Throws <ArgumentNullException>(
            () => _ = dependency.ToRegistrar(sourceServices));

        Assert.Equal("dependency", ex.ParamName);
    }
        public void ConfigureShouldRegisterAuthorizationRules()
        {
            MockServiceCollection collection = new MockServiceCollection();
            collection.Add(typeof(IAuthorizationRulesService), new MockAuthorizationRulesService());

            TestableModuleInitializer module = new TestableModuleInitializer();
            module.Configure(collection, ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None));

            MockAuthorizationRulesService authRulesServices =
                (MockAuthorizationRulesService)collection.Get<IAuthorizationRulesService>();

            Assert.AreEqual(1, authRulesServices.RegisteredAuthorizationRules.Count);
            Assert.IsTrue(authRulesServices.RegisteredAuthorizationRules.ContainsKey("Default.aspx"));
            Assert.AreEqual("MockRule01", authRulesServices.RegisteredAuthorizationRules["Default.aspx"]);
        }
        public void AddRequireServicesToCollection()
        {
            // Arrange
            var services = new MockServiceCollection();

            // Act
            services.AddCorrelationId();

            // Assert
            services.Count.Should().Be(1);
            ServiceDescriptor serviceDescriptor = services[0];

            serviceDescriptor.ImplementationType.Should().Be(typeof(CorrelationContextAccessor));
            serviceDescriptor.ServiceType.Should().Be(typeof(ICorrelationContextAccessor));
            serviceDescriptor.Lifetime.Should().Be(ServiceLifetime.Singleton);
        }
        public void RegisterModuleServicesRegistersIProductService()
        {
            TestableModuleInitializer module = new TestableModuleInitializer();
            MockServiceCollection serviceCollection = new MockServiceCollection();

            module.TestAddModuleServices(serviceCollection);

            Assert.IsTrue(serviceCollection.RegistedServices.ContainsKey(typeof(IProductService)));
        }
        public void RegisterModuleServicesRegistersIBusinessPresentationConverterForOrders()
        {
            TestableModuleInitializer module = new TestableModuleInitializer();
            MockServiceCollection serviceCollection = new MockServiceCollection();

            module.TestAddModuleServices(serviceCollection);

            Assert.IsTrue(serviceCollection.RegistedServices.ContainsKey(typeof(IBusinessPresentationConverter<Order, OrderInfo>)));
        }
        public void RegisterGlobalServicesRegistersNoServices()
        {
            TestableModuleInitializer module = new TestableModuleInitializer();
            MockServiceCollection serviceCollection = new MockServiceCollection();

            module.TestAddGlobalServices(serviceCollection);

            Assert.AreEqual(0, serviceCollection.RegistedServices.Count);
        }
        public void RegisterGlobalServicesRegistersIFindCustomerService()
        {
            TestableModuleInitializer module = new TestableModuleInitializer();
            MockServiceCollection serviceCollection = new MockServiceCollection();

            module.TestAddGlobalServices(serviceCollection);

            Assert.IsTrue(serviceCollection.RegistedServices.ContainsKey(typeof(IFindCustomerService)));
        }