public virtual void WhenRegisterFactorySingleton_ShouldGetLevel2Properly() { // Arrange IIoCContainer target = this.CreateTarget(); RegisterTestObjectContext registration = new RegisterTestObjectContext() { Container = target, Settings = new RegisterLevelContext[] { new RegisterLevelContext() { UseFactory = false, Settings = IocRegisterSettings.None }, new RegisterLevelContext() { UseFactory = true, Settings = IocRegisterSettings.Singleton }, new RegisterLevelContext() { UseFactory = false, Settings = IocRegisterSettings.None } } }; this.Register(registration); // Act ILevel2 actual1 = target.Resolve <ILevel2>(); ILevel2 actual2 = target.Resolve <ILevel2>(); // Assert actual1.Should().BeSameAs(actual2); this.AssertProperObjectTree(actual1, registration); }
public virtual void WhenRegisterAsSingleton_ShouldCreateOnce() { // Arrange IIoCContainer target = this.CreateTarget(); RegisterTestObjectContext registration = new RegisterTestObjectContext() { Container = target, Settings = new RegisterLevelContext[] { new RegisterLevelContext() { UseFactory = false, Settings = IocRegisterSettings.Singleton }, new RegisterLevelContext() { UseFactory = false, Settings = IocRegisterSettings.None }, new RegisterLevelContext() { UseFactory = false, Settings = IocRegisterSettings.None } } }; this.Register(registration); // Act ILevel1 actual1Level1 = target.Resolve <ILevel1>(); ILevel1 actual2Level1 = target.Resolve <ILevel1>(); ILevel2 actual1Level2 = target.Resolve <ILevel2>(); ILevel2 actual2Level2 = target.Resolve <ILevel2>(); ILevel3 actual1Level3 = target.Resolve <ILevel3>(); ILevel3 actual2Level3 = target.Resolve <ILevel3>(); // Assert actual1Level1.Should().BeSameAs(actual2Level1); actual1Level2.Should().NotBeSameAs(actual2Level2); actual1Level3.Should().NotBeSameAs(actual2Level3); }