예제 #1
0
 private static IocContainer BuildContainerWithRegistration()
 {
     var container = new IocContainer();
       container.RegisterType<IUserRepository, UserRepository>();
       container.RegisterType<IInsuranceRepository, InsuranceRepository>();
       container.RegisterType<IEmailRepository, EmailRepository>();
       container.RegisterType<IDeductibleRepository, DeductibleRepository>();
       container.RegisterType<UserController, UserController>();
       container.RegisterType<DeductibleController, DeductibleController>();
       container.RegisterType<InsuranceController, InsuranceController>();
       IocContainer.Container = container;
       return container;
 }
        public void TestNamedRegisterToType()
        {
            Mock<IRegistrationMap> mockRegistrationMap = new Mock<IRegistrationMap>();
              Mock<PickRegistrationStrategy> mockRegistrationChain = new Mock<PickRegistrationStrategy>();
              Mock<IResolverMap> mockResolverMap = new Mock<IResolverMap>();
              Mock<FindResolverStrategy> mockResolverChain = new Mock<FindResolverStrategy>();
              Mock<ILifetimeManagerMap> mockManagerMap = new Mock<ILifetimeManagerMap>();
              Mock<FindLifetimeManagerStrategy> mockManagerChain = new Mock<FindLifetimeManagerStrategy>();

              IocContainer testContainer = new IocContainer(mockRegistrationMap.Object,
                                                    mockRegistrationChain.Object,
                                                    mockResolverMap.Object,
                                                    mockResolverChain.Object,
                                                    mockManagerMap.Object,
                                                    mockManagerChain.Object);

              Type originalType = typeof(ISimpleInterface);
              Type mappedType = typeof(SimpleInterfaceImpl1);
              string identifier = "identifier";
              testContainer.RegisterType(originalType, mappedType, identifier);
              mockRegistrationMap.Verify(map => map.AddOrUpdate(originalType, identifier, mappedType));
        }
        public void TestNamedGenericLinkToInstance()
        {
            Mock<IRegistrationMap> mockRegistrationMap = new Mock<IRegistrationMap>();
              Mock<PickRegistrationStrategy> mockRegistrationChain = new Mock<PickRegistrationStrategy>();
              Mock<IResolverMap> mockResolverMap = new Mock<IResolverMap>();
              Mock<FindResolverStrategy> mockResolverChain = new Mock<FindResolverStrategy>();
              Mock<ILifetimeManagerMap> mockManagerMap = new Mock<ILifetimeManagerMap>();
              Mock<FindLifetimeManagerStrategy> mockManagerChain = new Mock<FindLifetimeManagerStrategy>();

              IocContainer testContainer = new IocContainer(mockRegistrationMap.Object,
                                                    mockRegistrationChain.Object,
                                                    mockResolverMap.Object,
                                                    mockResolverChain.Object,
                                                    mockManagerMap.Object,
                                                    mockManagerChain.Object);

              Type originalType = typeof(ISimpleInterface);
              Mock<ISimpleInterface> mockedSimpleInterface = new Mock<ISimpleInterface>();
              string identifer = "identifier";
              mockRegistrationChain.Setup(chain => chain.PickRegistration(originalType, identifer)).Returns(mockedSimpleInterface.Object.GetType());
              testContainer.RegisterType<ISimpleInterface>(mockedSimpleInterface.Object, identifer);
              mockRegistrationMap.Verify(map => map.AddOrUpdate(originalType, identifer, mockedSimpleInterface.Object.GetType()));
              Assert.AreEqual(mockedSimpleInterface.Object, testContainer.Resolve<ISimpleInterface>(identifer));
        }
        public void TestDefaultGenericLinkToTypeGenerically()
        {
            Mock<IRegistrationMap> mockRegistrationMap = new Mock<IRegistrationMap>();
              Mock<PickRegistrationStrategy> mockRegistrationChain = new Mock<PickRegistrationStrategy>();
              Mock<IResolverMap> mockResolverMap = new Mock<IResolverMap>();
              Mock<FindResolverStrategy> mockResolverChain = new Mock<FindResolverStrategy>();
              Mock<ILifetimeManagerMap> mockManagerMap = new Mock<ILifetimeManagerMap>();
              Mock<FindLifetimeManagerStrategy> mockManagerChain = new Mock<FindLifetimeManagerStrategy>();

              IocContainer testContainer = new IocContainer(mockRegistrationMap.Object,
                                                    mockRegistrationChain.Object,
                                                    mockResolverMap.Object,
                                                    mockResolverChain.Object,
                                                    mockManagerMap.Object,
                                                    mockManagerChain.Object);

              Type originalType = typeof(ISimpleInterface);
              Type mappedType = typeof(SimpleInterfaceImpl1);
              testContainer.RegisterType<ISimpleInterface, SimpleInterfaceImpl1>();
              mockRegistrationMap.Verify(map => map.AddOrUpdate(originalType, String.Empty, mappedType));
        }