public TransientLifecycleTester()
        {
            theContext   = Substitute.For <ILifecycleContext>();
            theLifecycle = new TransientLifecycle();

            theCache = Substitute.For <ITransientTracking>();
            theContext.Transients.Returns(theCache);
        }
        public TransientLifecycleTester()
        {
            theContext   = MockRepository.GenerateMock <ILifecycleContext>();
            theLifecycle = new TransientLifecycle();

            theCache = MockRepository.GenerateMock <ITransientTracking>();
            theContext.Stub(x => x.Transients).Return(theCache);
        }
Exemplo n.º 3
0
        public void CreateInstanceResolver_WithNullParamInstanceResolvers_ShouldReturnValidInstanceResolver()
        {
            TransientLifecycle sut          = createSut();
            IRegistration      registration = createRegistration(sut);
            var constructor = getConstructor();

            Assert.NotNull(sut.CreateInstanceResolver(createFactory(), registration, constructor, null));
        }
Exemplo n.º 4
0
        public void CreateInstanceResolver_WithNullConstructor_ShouldThrowArgumentNullException()
        {
            TransientLifecycle sut          = createSut();
            IRegistration      registration = createRegistration(sut);

            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.CreateInstanceResolver(createFactory(), registration, null, Enumerable.Empty <IInstanceResolver>()));
        }
Exemplo n.º 5
0
        public void SetUp()
        {
            theContext   = MockRepository.GenerateMock <ILifecycleContext>();
            theLifecycle = new TransientLifecycle();

            theCache = MockRepository.GenerateMock <IObjectCache>();
            theContext.Stub(x => x.Transients).Return(theCache);
        }
Exemplo n.º 6
0
        public void CreateInstanceResolver_WithFactoryThatReturnsNull_ShouldThrowInvalidOperationException()
        {
            TransientLifecycle sut          = createSut();
            IRegistration      registration = createRegistration(sut);
            var constructor = getConstructor();

            Assert.Throws <InvalidOperationException>(() =>
                                                      sut.CreateInstanceResolver(new NullFactory(), registration, constructor, Enumerable.Empty <IInstanceResolver>()));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Initialize the IoC container for Dependency Injection.
        /// </summary>
        public static void InitializeIoCcontainer()
        {
            ObjectFactory.Initialize(c =>
            {
                ILifecycle lifecycle = new TransientLifecycle();
                c.For <ILifecycle>().Use(lifecycle);

                c.For <IBillStatementRepository>().LifecycleIs(lifecycle).Use <BillStatementRepository>();
                c.For <ICustomerRepository>().LifecycleIs(lifecycle).Use <CustomerRepository>();
                c.For <IEmailRepository>().LifecycleIs(lifecycle).Use <EmailRepository>();
                c.For <IReportRepository>().LifecycleIs(lifecycle).Use <ReportRepository>();
            });
        }
Exemplo n.º 8
0
        private ILifecycle GetLifecycle(RegistrationLifestyle lifestyle)
        {
            ILifecycle lifecycle = null;

            switch (lifestyle)
            {
            case RegistrationLifestyle.Singleton:
                lifecycle = new SingletonLifecycle();
                break;

            case RegistrationLifestyle.SingletonPerScope:
                lifecycle = new ContainerLifecycle();
                break;

            case RegistrationLifestyle.SingletonPerObjectGraph:
            case RegistrationLifestyle.Transient:
                lifecycle = new TransientLifecycle();
                break;
            }

            return(lifecycle);
        }
Exemplo n.º 9
0
 private static IRegistration createRegistration(TransientLifecycle sut)
 {
     return(sut.CreateRegistration(typeof(IEmailService), typeof(NullEmailService)));
 }
Exemplo n.º 10
0
        public void CreateRegistration_WhenRegistering_WithNullImplementationType_ShouldThrowArgumentNullException()
        {
            TransientLifecycle sut = createSut();

            Assert.Throws <ArgumentNullException>(() => sut.CreateRegistration(typeof(IEmailService), null));
        }