Beispiel #1
0
        public void ConcretionClassWithMultipleConstructorsIsRegisteredCorrectly()
        {
            // arrange
            var sut = new ContainerSetup();
            var act = new Action(() => sut.RetrieveConcretionClassesRequiringRegistration(true));

            // act
            // assert
            act.Should().NotThrow <Exception>();
        }
Beispiel #2
0
        public void RegistrationOfDisposableConcretionClassDoesNotThrowAnException()
        {
            // arrange
            var sut = new ContainerSetup();
            var act = new Action(() => sut.RetrieveConcretionClassesRequiringRegistration(true));

            // act
            // assert
            act.Should().NotThrow <Exception>();
        }
Beispiel #3
0
        public void ConcretionClassWithMultipleConstructorsIsRegisteredCorrectly()
        {
            // arrange
            var serviceCollection = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            var sut = new ContainerSetup(serviceCollection);
            var act = new Action(() => sut.RetrieveConcretionClassesRequiringRegistration(true));

            // act
            // assert
            act.Should().NotThrow <Exception>();
        }
Beispiel #4
0
        public void ConcretionClassesCorrectlyApplyReuse()
        {
            // arrange
            var sut = new ContainerSetup();

            // act
            sut.RetrieveConcretionClassesRequiringRegistration(true);

            // assert
            var resolvedClasses = sut.ResolveMany <ITestInterfaceDummy>().ToList();
            var secondResolve   = sut.ResolveMany <ITestInterfaceDummy>().ToList();

            resolvedClasses.Should().BeEquivalentTo(secondResolve);
        }
Beispiel #5
0
        public void ConcretionClassesAreResolvedCorrectly()
        {
            // arrange
            var sut = new ContainerSetup();

            // act
            sut.RetrieveConcretionClassesRequiringRegistration(true);

            // assert
            var resolvedClass = sut.ResolveMany <BaseClassDummy>().ToList();

            resolvedClass.Count.Should().Be(1);
            resolvedClass.First().GetType().Should().Be(typeof(InheritorClassDummy));
        }
Beispiel #6
0
        public void ConcretionClassesFromInterfaceAreCorrectlyResolved()
        {
            // arrange
            var sut = new ContainerSetup();

            // act
            sut.RetrieveConcretionClassesRequiringRegistration(true);

            // assert
            var resolvedClasses = sut.ResolveMany <ITestInterfaceDummy>().ToList();

            resolvedClasses.Count.Should().Be(2);
            resolvedClasses.Should().Contain(x => x.GetType() == typeof(ImplementationClassDummy));
            resolvedClasses.Should().Contain(x => x.GetType() == typeof(ImplmentationClassTooDummy));
        }
Beispiel #7
0
        public void ConcretionClassesCorrectlyApplyReuse()
        {
            // arrange
            var serviceCollection = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            var sut = new ContainerSetup(serviceCollection);

            // act
            sut.RetrieveConcretionClassesRequiringRegistration(true);

            // assert
            var services        = serviceCollection.BuildServiceProvider();
            var resolvedClasses = ((IEnumerable <ITestInterfaceDummy>)services.GetService(typeof(IEnumerable <ITestInterfaceDummy>))).ToList();
            var secondResolve   = ((IEnumerable <ITestInterfaceDummy>)services.GetService(typeof(IEnumerable <ITestInterfaceDummy>))).ToList();

            resolvedClasses.Should().BeEquivalentTo(secondResolve);
        }
Beispiel #8
0
        public void ConcretionClassesAreResolvedCorrectly()
        {
            // arrange
            var serviceCollection = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            var sut = new ContainerSetup(serviceCollection);

            // act
            sut.RetrieveConcretionClassesRequiringRegistration(true);

            // assert
            var services      = serviceCollection.BuildServiceProvider();
            var resolvedClass = ((IEnumerable <BaseClassDummy>)services.GetService(typeof(IEnumerable <BaseClassDummy>))).ToList();

            resolvedClass.Count.Should().Be(1);
            resolvedClass.First().GetType().Should().Be(typeof(InheritorClassDummy));
        }
Beispiel #9
0
        public void MultiTypeRegistrationSingletonsWorkCorrectly()
        {
            // arrange
            var sut = new ContainerSetup();

            // act
            sut.RetrieveConcretionClassesRequiringRegistration(true);

            // assert
            var resolvedClasses        = sut.ResolveMany <ITestInterfaceDummy>().ToList();
            var interfaceResolvedClass =
                resolvedClasses.FirstOrDefault(t => t.GetType() == typeof(ImplementationClassDummy));
            var directlyResolvedClass = sut.Resolve <ImplementationClassDummy>();

            interfaceResolvedClass.Should().Be(directlyResolvedClass);
        }
Beispiel #10
0
        public void MultiTypeRegistrationSingletonsWorkCorrectly()
        {
            // arrange
            var serviceCollection = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            var sut = new ContainerSetup(serviceCollection);

            // act
            sut.RetrieveConcretionClassesRequiringRegistration(true);

            // assert
            var services               = serviceCollection.BuildServiceProvider();
            var resolvedClasses        = ((IEnumerable <ITestInterfaceDummy>)services.GetService(typeof(IEnumerable <ITestInterfaceDummy>))).ToList();
            var interfaceResolvedClass = resolvedClasses.FirstOrDefault(t => t.GetType() == typeof(ImplementationClassDummy));
            var directlyResolvedClass  = services.GetService(typeof(ImplementationClassDummy));

            interfaceResolvedClass.Should().Be(directlyResolvedClass);
        }
Beispiel #11
0
        public void ConcretionClassesFromInterfaceAreCorrectlyResolved()
        {
            // arrange
            var serviceCollection = new Microsoft.Extensions.DependencyInjection.ServiceCollection();
            var sut = new ContainerSetup(serviceCollection);

            // act
            sut.RetrieveConcretionClassesRequiringRegistration(true);

            // assert
            var services        = serviceCollection.BuildServiceProvider();
            var resolvedClasses = ((IEnumerable <ITestInterfaceDummy>)services.GetService(typeof(IEnumerable <ITestInterfaceDummy>))).ToList();

            resolvedClasses.Count.Should().Be(2);
            resolvedClasses.Should().Contain(x => x.GetType() == typeof(ImplementationClassDummy));
            resolvedClasses.Should().Contain(x => x.GetType() == typeof(ImplementationClassTooDummy));
        }