public void Given_WhenDependencyIsRegisteredViaHandlerAndDependencyIsResolvedTwice_ThenResolvedDependenciesAreDifferent()
        {
            var container = new ExtendedSimpleContainerAdapter(new ExtendedSimpleContainer());

            container.RegisterHandler <ITestDependency>(() => new TestDependency());
            var dependencyOne = container.Resolve <ITestDependency>();
            var dependencyTwo = container.Resolve <ITestDependency>();

            dependencyOne.Should().NotBeSameAs(dependencyTwo);
        }
Exemple #2
0
        void RegisterTransientDifferentContractAndImplementationWithDependencyCreator_ReturnsTwoDifferentObjectsForTwoResolutions()
        {
            var container = new ExtendedSimpleContainerAdapter();

            container.RegisterTransient <ITestDependency, TestDependencyA>(() => new TestDependencyA());

            var firstResolution  = container.Resolve <ITestDependency>();
            var secondResolution = container.Resolve <ITestDependency>();

            firstResolution.Should().NotBeSameAs(secondResolution);
        }
Exemple #3
0
        void RegisterTransientExplicitTypesWithDependencyCreator_ReturnsTwoDifferentObjectsForTwoResolutions()
        {
            var container = new ExtendedSimpleContainerAdapter();

            container.RegisterTransient(typeof(ITestDependency), typeof(TestDependencyA), () => new TestDependencyA());

            var firstResolution  = container.Resolve <ITestDependency>();
            var secondResolution = container.Resolve <ITestDependency>();

            firstResolution.Should().NotBeSameAs(secondResolution);
        }
        void RegisterSingletonSameType_ReturnsSameObjectsForTwoResolutions()
        {
            var container = new ExtendedSimpleContainerAdapter();

            container.RegisterSingleton <TestDependencyA>();

            var firstResolution  = container.Resolve <TestDependencyA>();
            var secondResolution = container.Resolve <TestDependencyA>();

            firstResolution.Should().BeSameAs(secondResolution);
        }
        void RegisterSingletonWithDependencyCreator_ReturnsSameObjectsForTwoResolutions()
        {
            var container = new ExtendedSimpleContainerAdapter();

            container.RegisterSingleton <ITestDependency>(() => new TestDependencyA());

            var firstResolution  = container.Resolve <ITestDependency>();
            var secondResolution = container.Resolve <ITestDependency>();

            firstResolution.Should().BeSameAs(secondResolution);
        }
        public void Given_WhenDependencyIsRegisteredViaHandlerAndDependencyIsResolved_ThenResolvedDependencyIsNotNull()
        {
            var container = new ExtendedSimpleContainerAdapter(new ExtendedSimpleContainer());

            container.RegisterHandler <ITestDependency>(() => new TestDependency());
            TestLifetimeScopeProvider.Current = new TestObject();
            var dependency = container.Resolve <ITestDependency>();

            dependency.Should().NotBeNull();
        }
        GivenThereIsCompositionModuleWithConcreteDependencyRegistration_WhenBootstrapperWithConcreteContainerIsUsedAndDependencyIsResolvedFromAdapter_ResolvedDependencyIsValid
            ()
        {
            var            container    = new ExtendedSimpleContainer();
            var            adapter      = new ExtendedSimpleContainerAdapter(container);
            IInitializable bootstrapper = new TestConcreteBootstrapper(container, c => adapter);

            bootstrapper.Initialize();

            var dependency = adapter.Resolve <IConcreteDependency>();

            dependency.Should().NotBeNull();
        }
        public void MultipleImplementationAreRegisteredByTypeAsParameter_ResolvedCollectionContainsAllImplementations()
        {
            var adapter = new ExtendedSimpleContainerAdapter();

            adapter.RegisterCollection(typeof(ITestDependency), new[] { typeof(TestDependencyA), typeof(TestDependencyB) });

            var collection = adapter.Resolve <IEnumerable <ITestDependency> >().ToArray();

            var firstItem  = collection.First();
            var secondItem = collection.Last();

            firstItem.Should().BeOfType <TestDependencyA>();
            secondItem.Should().BeOfType <TestDependencyB>();
        }
        public void MultipleImplementationAreRegisteredByInstance_ResolvedCollectionContainsAllImplementations()
        {
            var adapter   = new ExtendedSimpleContainerAdapter();
            var instanceA = new TestDependencyA();
            var instanceB = new TestDependencyB();

            adapter.RegisterCollection(new ITestDependency[] { instanceA, instanceB });

            var collection = adapter.Resolve <IEnumerable <ITestDependency> >().ToArray();

            var firstItem  = collection.First();
            var secondItem = collection.Last();

            firstItem.Should().BeSameAs(instanceA);
            secondItem.Should().BeSameAs(instanceB);
        }