public void TransientLifetimeTest_11_ContainerCanGetInstanceOfUnmappedTypeUsingConstructorInjectionWithValueAndValueFactoryParametersWithImplicitDefaultLifetime() { // Arrange const int testId = 11; IContainerSettings settings = RegisterSettings(testId); IRegistry registry = new Registry(); registry.Register<Car>() .UsingConstructor() .WithValueParameter("Ford") .WithValueParameter("Mustang") .WithValueFactoryParameter<IColorScheme>( () => new ColorScheme("Custom Color Scheme", new BlueColor(), new OrangeColor())) .AsLastParameter(); IContainer container = CreateContainer(settings, registry); // Act Car car = container.GetInstance<Car>(); // Assert Assert.That(car, Is.Not.Null); Assert.That(car.Make, Is.EqualTo("Ford")); Assert.That(car.Model, Is.EqualTo("Mustang")); Assert.That(car.ColorScheme.Name, Is.EqualTo("Custom Color Scheme")); Assert.That(car.ColorScheme.PrimaryColor.Name, Is.EqualTo("Blue")); Assert.That(car.ColorScheme.SecondaryColor.Name, Is.EqualTo("Orange")); }
public override void Prepare() { ContainerSettings settings = new DefaultContainerSettings("Speedioc"); settings.ForceCompile = true; IRegistry registry = new Registry(); registry.Register<Singleton>().As<ISingleton>().WithLifetime(Lifetime.Container).PreCreateInstance(); registry.Register<Transient>().As<ITransient>().WithLifetime(Lifetime.Transient); registry.Register<Combined>().As<ICombined>().WithLifetime(Lifetime.Transient) .UsingConstructor() .WithResolvedParameter<ISingleton>() .WithResolvedParameter<ITransient>() .AsLastParameter(); IContainerBuilder containerBuilder = DefaultContainerBuilderFactory.GetInstance(settings, registry); container = containerBuilder.Build(); }
public void TransientLifetimeTest_12_ContainerCanGetInstanceOfUnmappedTypeUsingValueFieldInjectionWithImplicitDefaultLifetime() { // Arrange const int testId = 12; IContainerSettings settings = RegisterSettings(testId); IRegistry registry = new Registry(); registry.Register<Car>() .WithField<int>("EngineSizeCubicInches").SetTo(5); IContainer container = CreateContainer(settings, registry); // Act Car car = container.GetInstance<Car>(); // Assert Assert.That(car, Is.Not.Null); Assert.That(car.Make, Is.Null); Assert.That(car.Model, Is.Null); Assert.That(car.ColorScheme.Name, Is.EqualTo("White")); Assert.That(car.ColorScheme.PrimaryColor.Name, Is.EqualTo("White")); Assert.That(car.ColorScheme.SecondaryColor.Name, Is.EqualTo("White")); Assert.That(car.EngineSizeCubicInches, Is.EqualTo(5)); }
public void TransientLifetimeTest_8_ContainerCanGetTwoInstancesOfGenericMappedTypeWithTransientLifetimeWithoutInjectionWithImplicitDefaultLifetime() { // Arrange const int testId = 8; IContainerSettings settings = RegisterSettings(testId); IRegistry registry = new Registry(); registry.Register<Car>().As<IVehicle>(); IContainer container = CreateContainer(settings, registry); // Act IVehicle vehicle = container.GetInstance<IVehicle>(); IVehicle vehicle2 = container.GetInstance<IVehicle>(); // Assert Assert.That(vehicle, Is.Not.Null); Assert.That(vehicle, Is.TypeOf<Car>()); Assert.That(vehicle.Make, Is.Null); Assert.That(vehicle.Model, Is.Null); Assert.That(vehicle.ColorScheme.PrimaryColor.Name, Is.EqualTo("White")); Assert.That(vehicle.ColorScheme.SecondaryColor.Name, Is.EqualTo("White")); Assert.That(vehicle2, Is.Not.Null); Assert.That(vehicle2, Is.TypeOf<Car>()); Assert.That(vehicle2.Make, Is.Null); Assert.That(vehicle2.Model, Is.Null); Assert.That(vehicle2.ColorScheme.PrimaryColor.Name, Is.EqualTo("White")); Assert.That(vehicle2.ColorScheme.SecondaryColor.Name, Is.EqualTo("White")); Assert.That(vehicle, Is.Not.SameAs(vehicle2)); }
public void TransientLifetimeTest_4_ContainerCanGetTwoInstancesOfUnmappedTypeWithTransientLifetimeWithoutInjectionWithExplicitLifetime() { // Arrange const int testId = 4; IContainerSettings settings = RegisterSettings(testId); IRegistry registry = new Registry(); registry.Register<Car>().WithLifetime(Lifetime.Transient); IContainer container = CreateContainer(settings, registry); // Act Car car = container.GetInstance<Car>(); Car car2 = container.GetInstance<Car>(); // Assert Assert.That(car, Is.Not.Null); Assert.That(car.Make, Is.Null); Assert.That(car.Model, Is.Null); Assert.That(car.ColorScheme.PrimaryColor.Name, Is.EqualTo("White")); Assert.That(car.ColorScheme.SecondaryColor.Name, Is.EqualTo("White")); Assert.That(car2, Is.Not.Null); Assert.That(car2.Make, Is.Null); Assert.That(car2.Model, Is.Null); Assert.That(car2.ColorScheme.PrimaryColor.Name, Is.EqualTo("White")); Assert.That(car2.ColorScheme.SecondaryColor.Name, Is.EqualTo("White")); Assert.That(car, Is.Not.SameAs(car2)); }
public void TransientLifetimeTest_1_ContainerCanGetInstanceOfUnmappedTypeWithWithoutInjectionWithImplicitDefaultLifetime() { // Arrange const int testId = 1; IContainerSettings settings = RegisterSettings(testId); IRegistry registry = new Registry(); registry.Register<Car>(); IContainer container = CreateContainer(settings, registry); // Act Car car = container.GetInstance<Car>(); // Assert Assert.That(car, Is.Not.Null); Assert.That(car.Make, Is.Null); Assert.That(car.Model, Is.Null); Assert.That(car.ColorScheme.PrimaryColor.Name, Is.EqualTo("White")); Assert.That(car.ColorScheme.SecondaryColor.Name, Is.EqualTo("White")); }