예제 #1
0
        public void Resolve_SingleNestedDependency_NestedDependencyType()
        {
            var dependencies = new DependencyConfiguration();

            dependencies.RegisterTransient <IService, ServiceImplWithNesting1>();
            dependencies.RegisterTransient <IRepository, RepositoryImpl>();
            var provider = new DependencyProvider(dependencies);
            ServiceImplWithNesting1 service = provider.Resolve <IService>();
            Type expectedType = typeof(RepositoryImpl);
            Type receivedType = service._rep.GetType();

            Assert.AreEqual(expectedType, receivedType, ":-(");
        }
예제 #2
0
        public void Resolve_SingletonNestedDelendencyForMultipleDependencies_CommonNestedDependencyReference()
        {
            var dependencies = new DependencyConfiguration();

            dependencies.RegisterTransient <IService, ServiceImplWithNesting1>();
            dependencies.RegisterTransient <IService2, ServiceImplWithNesting2>();
            dependencies.RegisterSingleton <IRepository, RepositoryImplSingleton>();
            var provider = new DependencyProvider(dependencies);
            ServiceImplWithNesting1 service1 = provider.Resolve <IService>();
            ServiceImplWithNesting2 service2 = provider.Resolve <IService2>();
            Type service1NestedTypeype       = service1._rep.GetType();
            Type service2NestedTypeype       = service2._rep.GetType();

            Assert.AreEqual(service1NestedTypeype, service2NestedTypeype);
        }
예제 #3
0
        public void Resolve_UnregistredAbstractionType_ExceptionMessage()
        {
            var    dependencies    = new DependencyConfiguration();
            var    provider        = new DependencyProvider(dependencies);
            string expectedMessage = "Type IService has not been registered.";
            string receivedMessage = "";

            try
            {
                ServiceImplWithNesting1 service = provider.Resolve <IService>();
            }
            catch (UnregisteredAbstractionTypeException e)
            {
                receivedMessage = e.Message;
            }
            Assert.AreEqual(expectedMessage, receivedMessage);
        }