Ejemplo n.º 1
0
        public void AddDependenciesThrowsIfInvalidRegisterAsType()
        {
            IEnumerable <Assembly> thisAssembly = new[] { GetType().Assembly };

            System.Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");

            Assert.ThrowsException <NotSupportedException>(() => {
                DependencyInjectionRegistrar.AddDependencies(Mock.Of <IServiceCollection>(), new DependencyInjectionEntry[] {
                    new (typeof(TestDependency), new DependencyInjectionAttribute()
                    {
                        RegisterAs = typeof(string)
                    })
                }, new DependencyInjectionMiddleware[] { });
            });
Ejemplo n.º 2
0
        public void AddDependenciesCallsMiddleware()
        {
            IEnumerable <Assembly> thisAssembly = new[] { GetType().Assembly };

            System.Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "Development");

            var mockMiddleware = new Mock <DependencyInjectionMiddleware>();

            var dependencies = new DependencyInjectionEntry[] {
                new (typeof(TestDependency), new DependencyInjectionAttribute()),
                new (typeof(TestDependency2), new DependencyInjectionAttribute()),
            };

            DependencyInjectionRegistrar.AddDependencies(
                Mock.Of <IServiceCollection>(),
                dependencies,
                new[] { mockMiddleware.Object as DependencyInjectionMiddleware }
                );

            mockMiddleware.Verify(m => m.BeforeEach(It.IsAny <DependencyInjectionEntry>()), Times.Exactly(dependencies.Count()));
        }