public void ForDependencyOverrideByInstanceAndWithoutTypeRestriction_AllWheelsAreResolvedToMyInstance() { const string WheelName = "My Wheel"; var myWheel = new DefaultWheel() { Name = WheelName }; // But you would normally use OnType. var car = container.Resolve <ICar>(new DependencyOverride <IWheel>(myWheel)); Assert.AreEqual(WheelName, car.FirstWheel.Name); Assert.AreEqual(WheelName, car.SecondWheel.Name); Assert.AreEqual(WheelName, car.ThirdWheel.Name); Assert.AreEqual(WheelName, car.FourthWheel.Name); Assert.AreEqual(WheelName, car.Trailer.FirstWheel.Name); Assert.AreEqual(WheelName, car.Trailer.SecondWheel.Name); Assert.AreSame(myWheel, car.FirstWheel); Assert.AreSame(myWheel, car.SecondWheel); Assert.AreSame(myWheel, car.ThirdWheel); Assert.AreSame(myWheel, car.FourthWheel); Assert.AreSame(myWheel, car.Trailer.FirstWheel); Assert.AreSame(myWheel, car.Trailer.SecondWheel); }
public void ForDependencyOverrideByInstanceAndWithoutTypeRestriction_AllWheelsAreResolvedToMyInstance() { const string WheelName = "My Wheel"; var myWheel = new DefaultWheel() { Name = WheelName }; // But you would normally use OnType. var car = container.Resolve<ICar>(new DependencyOverride<IWheel>(myWheel)); Assert.AreEqual(WheelName, car.FirstWheel.Name); Assert.AreEqual(WheelName, car.SecondWheel.Name); Assert.AreEqual(WheelName, car.ThirdWheel.Name); Assert.AreEqual(WheelName, car.FourthWheel.Name); Assert.AreEqual(WheelName, car.Trailer.FirstWheel.Name); Assert.AreEqual(WheelName, car.Trailer.SecondWheel.Name); Assert.AreSame(myWheel, car.FirstWheel); Assert.AreSame(myWheel, car.SecondWheel); Assert.AreSame(myWheel, car.ThirdWheel); Assert.AreSame(myWheel, car.FourthWheel); Assert.AreSame(myWheel, car.Trailer.FirstWheel); Assert.AreSame(myWheel, car.Trailer.SecondWheel); }
public void ForParameterOverrideByInstanceAndWithoutTypeRestriction_AllWheelsWithSameNameAreOverridden() { const string WheelName = "My Wheel"; var myWheel = new DefaultWheel() { Name = WheelName }; // But you would normally use OnType. var car = container.Resolve <ICar>(new ParameterOverride("firstWheel", myWheel)); Assert.AreEqual(WheelName, car.FirstWheel.Name); Assert.AreEqual(Names.DefaultWheelName, car.SecondWheel.Name); Assert.AreEqual(Names.DefaultWheelName, car.ThirdWheel.Name); Assert.AreEqual(Names.DefaultWheelName, car.FourthWheel.Name); Assert.AreEqual(WheelName, car.Trailer.FirstWheel.Name); Assert.AreEqual(Names.DefaultWheelName, car.Trailer.SecondWheel.Name); Assert.AreSame(myWheel, car.FirstWheel); Assert.AreSame(myWheel, car.Trailer.FirstWheel); AssertAllDifferentObjects(car.SecondWheel, car.ThirdWheel, car.FourthWheel, car.Trailer.SecondWheel); }
public void ForParameterOverrideByInstanceAndWithoutTypeRestriction_AllWheelsWithSameNameAreOverridden() { const string WheelName = "My Wheel"; var myWheel = new DefaultWheel() { Name = WheelName }; // But you would normally use OnType. var car = container.Resolve<ICar>(new ParameterOverride("firstWheel", myWheel)); Assert.AreEqual(WheelName, car.FirstWheel.Name); Assert.AreEqual(Names.DefaultWheelName, car.SecondWheel.Name); Assert.AreEqual(Names.DefaultWheelName, car.ThirdWheel.Name); Assert.AreEqual(Names.DefaultWheelName, car.FourthWheel.Name); Assert.AreEqual(WheelName, car.Trailer.FirstWheel.Name); Assert.AreEqual(Names.DefaultWheelName, car.Trailer.SecondWheel.Name); Assert.AreSame(myWheel, car.FirstWheel); Assert.AreSame(myWheel, car.Trailer.FirstWheel); AssertAllDifferentObjects(car.SecondWheel, car.ThirdWheel, car.FourthWheel, car.Trailer.SecondWheel); }