public void CreateInstanceResolver_WithNullParamInstanceResolvers_ShouldReturnValidInstanceResolver()
        {
            SingletonLifecycle sut          = createSut();
            IRegistration      registration = createRegistration(sut);
            var constructor = getConstructor();

            Assert.NotNull(sut.CreateInstanceResolver(createFactory(), registration, constructor, null));
        }
        public void CreateInstanceResolver_WithNullConstructor_ShouldThrowArgumentNullException()
        {
            SingletonLifecycle sut          = createSut();
            IRegistration      registration = createRegistration(sut);

            Assert.Throws <ArgumentNullException>(() =>
                                                  sut.CreateInstanceResolver(createFactory(), registration, null, Enumerable.Empty <IInstanceResolver>()));
        }
Example #3
0
        public SingletonLifecycleTester()
        {
            theContext   = MockRepository.GenerateMock <ILifecycleContext>();
            theLifecycle = new SingletonLifecycle();

            theCache = MockRepository.GenerateMock <IObjectCache>();
            theContext.Stub(x => x.Singletons).Return(theCache);
        }
        public SingletonLifecycleTester()
        {
            theContext   = Substitute.For <ILifecycleContext>();
            theLifecycle = new SingletonLifecycle();

            theCache = Substitute.For <IObjectCache>();
            theContext.Singletons.Returns(theCache);
        }
        public void CreateInstanceResolver_WithFactoryThatReturnsNull_ShouldThrowInvalidOperationException()
        {
            SingletonLifecycle sut          = createSut();
            IRegistration      registration = createRegistration(sut);
            var constructor = getConstructor();

            Assert.Throws <InvalidOperationException>(() =>
                                                      sut.CreateInstanceResolver(new NullFactory(), registration, constructor, Enumerable.Empty <IInstanceResolver>()));
        }
        public void SetUp()
        {
            lifecycle = new SingletonLifecycle();

            disposable1 = new StubDisposable();
            disposable2 = new StubDisposable();


            lifecycle.FindCache().Set(typeof(IGateway), new StubInstance("a"), disposable1);
            lifecycle.FindCache().Set(typeof(IGateway), new StubInstance("b"), disposable2);
            lifecycle.FindCache().Set(typeof(IGateway), new StubInstance("c"), new object());


            lifecycle.EjectAll();
        }
Example #7
0
        public void SetUp()
        {
            lifecycle = new SingletonLifecycle();

            disposable1 = new StubDisposable();
            disposable2 = new StubDisposable();

            pipeline = new RootPipelineGraph(new PluginGraph());

            lifecycle.FindCache(pipeline).As <LifecycleObjectCache>().Set(typeof(IGateway), new StubInstance("a"), disposable1);
            lifecycle.FindCache(pipeline).As <LifecycleObjectCache>().Set(typeof(IGateway), new StubInstance("b"), disposable2);
            lifecycle.FindCache(pipeline).As <LifecycleObjectCache>().Set(typeof(IGateway), new StubInstance("c"), new object());


            lifecycle.EjectAll(pipeline);
        }
Example #8
0
        public void TestSingletonLifecycle()
        {
            ILifecycle lifecycle = new SingletonLifecycle();

            lifecycle.Prepare(_initializationData, DummyLogger.Instance);
            Assert.That(LifecycleTestInstance.InstanceCreated, Is.Not.True);

            lifecycle.InitialActivation();
            Assert.That(LifecycleTestInstance.InstanceCreated, Is.True);

            var instance1 = lifecycle.Create(_initializationData);
            var instance2 = lifecycle.Create(_initializationData);

            Assert.That(instance1, Is.Not.Null);
            Assert.That(instance1, Is.SameAs(instance2));

            // Test destruction of singleton instance
            lifecycle.Destroy();
            Assert.That(LifecycleTestInstance.InstanceDestroyed, Is.True);
        }
        public when_the_singleton_Lifecycle_ejects_all()
        {
            lifecycle = new SingletonLifecycle();

            disposable1 = new StubDisposable();
            disposable2 = new StubDisposable();

            pipeline = PipelineGraph.BuildRoot(PluginGraph.CreateRoot());

            lifecycle.FindCache(pipeline)
            .As <LifecycleObjectCache>()
            .Set(typeof(IGateway), new StubInstance("a"), disposable1);
            lifecycle.FindCache(pipeline)
            .As <LifecycleObjectCache>()
            .Set(typeof(IGateway), new StubInstance("b"), disposable2);
            lifecycle.FindCache(pipeline)
            .As <LifecycleObjectCache>()
            .Set(typeof(IGateway), new StubInstance("c"), new object());

            lifecycle.EjectAll(pipeline);
        }
Example #10
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);
        }
 private static IRegistration createRegistration(SingletonLifecycle sut)
 {
     return(sut.CreateRegistration(typeof(IEmailService), typeof(NullEmailService)));
 }
        public void CreateRegistration_WhenRegistering_WithNullImplementationType_ShouldThrowArgumentNullException()
        {
            SingletonLifecycle sut = createSut();

            Assert.Throws <ArgumentNullException>(() => sut.CreateRegistration(typeof(IEmailService), null));
        }
 public HybridHttpSessionLifecycle()
 {
     _http = new HttpSessionLifecycle();
     _nonHttp = new SingletonLifecycle();
 }
 public HybridHttpSessionLifecycle()
 {
     _http    = new HttpSessionLifecycle();
     _nonHttp = new SingletonLifecycle();
 }
Example #15
0
        public DefaultRegistry()
        {
            var clientAdress      = "https://api.spotify.com/";
            var connectionStrings = "";
            var unique            = new SingletonLifecycle();
            var _clientId         = "9bbbfe31194c4df1ad8330dd2692aaa2"; //;ConfigurationManager.AppSettings[""];
            var _clientSecret     = "5eb99108fbd44027b6e257627eec3a0a"; //;ConfigurationManager.AppSettings[""];


            Scan(
                scan =>
            {
                scan.TheCallingAssembly();
                scan.WithDefaultConventions();
                scan.With(new ControllerConvention());
            });
            ;
            For <HttpContextBase>().Use((ctx => new HttpContextWrapper(HttpContext.Current)));
            For <IRestClient>()
            .Use(ctx =>
                 new RestClient(clientAdress));
            For <IRestMethods>()
            .LifecycleIs(unique)
            .Use(ctx =>
                 new RestMethods(
                     ctx.GetInstance <IRestClient>()));
            For <IRestRequestCreator>()
            .Use(ctx =>
                 new RestRequestCreator(_clientId, _clientSecret));

            For <IFormatUtils>().Use <FormatUtils>();

            For <ICacheManagerService>().Use <CacheManagerService>();

            For <IDbContextFactory>()
            .Use(ctx =>
                 new DbContextFactory(connectionStrings));

            For <IProductService>()
            .LifecycleIs(unique)
            .Use(ctx =>
                 new ProductService(
                     ctx.GetInstance <IDbContextFactory>()));


            For <IDataRepository>()
            .LifecycleIs(unique)
            .Use(ctx =>
                 //      new DataRepository(new HttpContextWrapper(HttpContext.Current),
                 new DataRepository(
                     new HttpContextWrapper(HttpContext.Current),
                     ctx.GetInstance <IRestRequestCreator>(),
                     ctx.GetInstance <IRestMethods>(),
                     ctx.GetInstance <IProductService>(),
                     ctx.GetInstance <ICacheManagerService>(),
                     ctx.GetInstance <ITokenService>()
                     ));



            #endregion
        }