Esempio n. 1
0
        public void Scan_SampleAssemblyWithCompositionRoot_CallsComposeMethodOnce()
        {
            var containerMock   = new ContainerMock(new MockContext <IServiceContainer>());
            var assemblyScanner = new AssemblyScanner(new ConcreteTypeExtractor(), new CompositionRootTypeExtractor(), new CompositionRootExecutor(containerMock));

            SampleCompositionRoot.CallCount = 0;
            assemblyScanner.Scan(typeof(SampleCompositionRoot).Assembly, containerMock);
            Assert.AreEqual(1, SampleCompositionRoot.CallCount);
        }
Esempio n. 2
0
        public void ScanUsingPredicate_SampleAssemblyWithCompositionRoot_DoesNotCallCompositionRoot()
        {
            var containerMock   = new ContainerMock(new MockContext <IServiceContainer>());
            var assemblyScanner = new AssemblyScanner(new ConcreteTypeExtractor(), new CompositionRootTypeExtractor(), new CompositionRootExecutor(containerMock));

            SampleCompositionRoot.CallCount = 0;
            assemblyScanner.Scan(typeof(SampleCompositionRoot).Assembly, containerMock, () => null, (s, t) => true);
            Assert.AreEqual(0, SampleCompositionRoot.CallCount);
        }
Esempio n. 3
0
        private MockContext <IServiceContainer> GetContainerMock(Func <ILifetime> lifetimeFactory, Func <Type, Type, bool> shouldRegister)
        {
            var mockContext     = new MockContext <IServiceContainer>();
            var containerMock   = new ContainerMock(mockContext);
            var assemblyScanner = new AssemblyScanner(new ConcreteTypeExtractor(), new CompositionRootTypeExtractor(), new CompositionRootExecutor(containerMock));

            assemblyScanner.Scan(typeof(IFoo).Assembly, containerMock, lifetimeFactory, shouldRegister);
            return(mockContext);
        }
Esempio n. 4
0
        public void Execute_CompositionRootType_IsCreatedAndExecuted()
        {
            CompositionRootMock compositionRootMock = new CompositionRootMock();
            var serviceContainerMock = new ContainerMock();
            var executor             = new CompositionRootExecutor(serviceContainerMock, (t) => compositionRootMock);

            executor.Execute(typeof(CompositionRootMock));
            compositionRootMock.Assert(c => c.Compose(The <IServiceContainer> .IsAnyValue), Invoked.Once);
        }
Esempio n. 5
0
        public void Execute_Composition_IsExecutedOnlyOnce()
        {
            CompositionRootMock compositionRootMock = new CompositionRootMock();
            var serviceContainerMock = new ContainerMock();
            var executor             = new CompositionRootExecutor(serviceContainerMock, (t) => compositionRootMock);

            executor.Execute(compositionRootMock);
            executor.Execute(compositionRootMock);
            compositionRootMock.Assert(c => c.Compose(The <IServiceContainer> .IsAnyValue), Invoked.Once);
        }
        public void Execute_CompositionRootType_IsCreatedAndExecutedOnlyOnce()
        {
            SampleCompositionRoot.CallCount = 0;
            var serviceContainerMock = new ContainerMock(new MockContext <IServiceContainer>());
            var executor             = new CompositionRootExecutor(serviceContainerMock);

            executor.Execute(typeof(SampleCompositionRoot));
            executor.Execute(typeof(SampleCompositionRoot));
            Assert.AreEqual(1, SampleCompositionRoot.CallCount);
        }
Esempio n. 7
0
        public void Register_Assembly_RegistersConcreteTypeWithBaseclass()
        {
            var mockContext   = new MockContext <IServiceContainer>();
            var containerMock = new ContainerMock(mockContext);

            AssemblyScanner assemblyScanner = new AssemblyScanner(new ConcreteTypeExtractor(), new CompositionRootTypeExtractor(), new CompositionRootExecutor(containerMock));

            assemblyScanner.Scan(typeof(IFoo).Assembly, containerMock, () => null, (s, t) => true);

            mockContext.Assert(r => r.Register(typeof(Foo), typeof(ConcreteFooWithBaseClass), "ConcreteFooWithBaseClass", null));
        }
        public void ScanUsingPredicate_SampleAssemblyWithCompositionRoot_DoesNotCallCompositionRoot()
        {
            var compositionRootMock = new CompositionRootMock();
            var containerMock       = new ContainerMock();
            var assemblyScanner     = new AssemblyScanner(new ConcreteTypeExtractor(),
                                                          new CompositionRootTypeExtractor(new CompositionRootAttributeExtractor()),
                                                          new CompositionRootExecutor(containerMock, t => compositionRootMock), new GenericArgumentMapper());

            assemblyScanner.Scan(typeof(AssemblyScannerTests).GetTypeInfo().Assembly, containerMock, () => null, (s, t) => true);

            compositionRootMock.Assert(c => c.Compose(containerMock), Invoked.Never);
        }
        private MockContext <IServiceContainer> GetContainerMock(Func <ILifetime> lifetimeFactory, Func <Type, Type, bool> shouldRegister)
        {
            var containerMock       = new ContainerMock();
            var compositionRootMock = new CompositionRootMock();

            var compositionRootTypeExtractorMock = new TypeExtractorMock();

            compositionRootTypeExtractorMock.Arrange(c => c.Execute(The <Assembly> .IsAnyValue)).Returns(Type.EmptyTypes);

            var assemblyScanner = new AssemblyScanner(new ConcreteTypeExtractor(), compositionRootTypeExtractorMock, new CompositionRootExecutor(containerMock, t => compositionRootMock), new GenericArgumentMapper());

            assemblyScanner.Scan(typeof(IFoo).GetTypeInfo().Assembly, containerMock, lifetimeFactory, shouldRegister);
            return(containerMock);
        }
        private MockContext <IServiceContainer> GetContainerMock(Type type)
        {
            var compositionRootExtractorMock = new TypeExtractorMock();

            compositionRootExtractorMock.Arrange(c => c.Execute(The <Assembly> .IsAnyValue)).Returns(Type.EmptyTypes);
            var concreteTypeExtractorMock = new TypeExtractorMock();

            concreteTypeExtractorMock.Arrange(c => c.Execute(The <Assembly> .IsAnyValue)).Returns(new Type[] { type });
            var scanner = new AssemblyScanner(concreteTypeExtractorMock, compositionRootExtractorMock, null,
                                              new GenericArgumentMapper());
            var containerMock = new ContainerMock();

            scanner.Scan(typeof(IFoo).GetTypeInfo().Assembly, containerMock, () => null, (st, ip) => true);
            return(containerMock);
        }
        public void Scan_SampleAssemblyWithCompositionRoot_CallsComposeMethodOnce()
        {
            var compositionRootMock          = new CompositionRootMock();
            var containerMock                = new ContainerMock();
            var compositionRootExtractorMock = new TypeExtractorMock();

            compositionRootExtractorMock.Arrange(c => c.Execute(The <Assembly> .IsAnyValue)).Returns(new [] { typeof(CompositionRootMock) });
            var assemblyScanner = new AssemblyScanner(new ConcreteTypeExtractor(),
                                                      compositionRootExtractorMock,
                                                      new CompositionRootExecutor(containerMock, t => compositionRootMock), new GenericArgumentMapper());

            assemblyScanner.Scan(typeof(AssemblyScannerTests).GetTypeInfo().Assembly, containerMock);

            compositionRootMock.Assert(c => c.Compose(containerMock), Invoked.Once);
        }