Пример #1
0
        public void Should_TransientService_Override_When_Using_IsDefault()
        {
            using (IIocManager iocManager = CastleWindsorIocManagerTests.CreateTestIocManager())
            {
                //Arrange
                iocManager.Registrar.RegisterTransient <IMyService, MyImpl1>();
                iocManager.Registrar.RegisterTransient <IMyService, MyImpl2>(isDefault: true);

                //Act
                var service     = iocManager.Resolver.Resolve <IMyService>();
                var allServices = iocManager.Resolver.ResolveAll <IMyService>();

                //Assert
                service.ShouldBeOfType <MyImpl2>();
                allServices.Length.ShouldBe(2);
                allServices.Any(s => s.GetType() == typeof(MyImpl1)).ShouldBeTrue();
                allServices.Any(s => s.GetType() == typeof(MyImpl2)).ShouldBeTrue();
            }
        }
Пример #2
0
        public void Should_PerThreadService_Get_Default_Service()
        {
            using (IIocManager iocManager = CastleWindsorIocManagerTests.CreateTestIocManager())
            {
                //Arrange
                iocManager.Registrar.RegisterPerThread <IMyService, MyImpl1>();
                iocManager.Registrar.RegisterPerThread <IMyService, MyImpl2>(isDefault: true);
                iocManager.Registrar.RegisterPerThread <IMyService, MyImpl3>();

                //Act
                var service     = iocManager.Resolver.Resolve <IMyService>();
                var allServices = iocManager.Resolver.ResolveAll <IMyService>();

                //Assert
                service.ShouldBeOfType <MyImpl2>();
                allServices.Length.ShouldBe(3);
                allServices.Any(s => s.GetType() == typeof(MyImpl1)).ShouldBeTrue();
                allServices.Any(s => s.GetType() == typeof(MyImpl2)).ShouldBeTrue();
                allServices.Any(s => s.GetType() == typeof(MyImpl3)).ShouldBeTrue();
            }
        }
Пример #3
0
        public void Should_SingletonService_Not_Override_As_Default()
        {
            using (IIocManager iocManager = CastleWindsorIocManagerTests.CreateTestIocManager())
            {
                //Arrange
                iocManager.Registrar.RegisterSingleton <IMyService, MyImpl1>();
                iocManager.Registrar.RegisterSingleton <IMyService, MyImpl2>();
                iocManager.Registrar.RegisterSingleton <IMyService, MyImpl3>();

                //Act
                var service     = iocManager.Resolver.Resolve <IMyService>();
                var allServices = iocManager.Resolver.ResolveAll <IMyService>();

                //Assert
                service.ShouldBeOfType <MyImpl1>();
                allServices.Length.ShouldBe(3);
                allServices.Any(s => s.GetType() == typeof(MyImpl1)).ShouldBeTrue();
                allServices.Any(s => s.GetType() == typeof(MyImpl2)).ShouldBeTrue();
                allServices.Any(s => s.GetType() == typeof(MyImpl3)).ShouldBeTrue();
            }
        }