public void TestBindWhenIntoByInstance() { var instance1 = new MockClassSimple(); var instance2 = new MockClassVerySimple(); var container = new InjectionContainer(); container.Bind <IMockInterface>().To <MockIClassWithAttributes>().WhenIntoInstance(instance1); container.Bind <IMockInterface>().To <MockIClassWithoutAttributes>().WhenIntoInstance(instance2); container.Inject(instance1); container.Inject(instance2); Assert.AreEqual(typeof(MockIClassWithAttributes), instance1.field.GetType()); Assert.AreEqual(typeof(MockIClassWithoutAttributes), instance2.field.GetType()); }
public void TestBindAsIdentifierWhenIntoByInstance() { var instance1 = new MockClassVerySimple(); var instance2 = new MockClassSimple(); var container = new InjectionContainer(); container.Bind<IMockInterface>() .To<MockIClassWithAttributes>().WhenIntoInstance(instance1); container.Bind<IMockInterface>() .To<MockIClassWithoutAttributes>().WhenIntoInstance(instance2).As("singleton"); container.Bind<IMockInterface>() .To<MockIClass>().WhenInto<MockClassSimple>().WhenIntoInstance(instance2).As("test"); container.Inject(instance1); container.Inject(instance2); Assert.AreEqual(typeof(MockIClassWithAttributes), instance1.field.GetType()); Assert.IsNull(instance2.field); Assert.AreEqual(typeof(MockIClassWithoutAttributes), instance2.property.GetType()); }
public void TestBindAsIdentifierWhenIntoByInstance() { var instance1 = new MockClassVerySimple(); var instance2 = new MockClassSimple(); var container = new InjectionContainer(); container.Bind <IMockInterface>() .To <MockIClassWithAttributes>().WhenIntoInstance(instance1); container.Bind <IMockInterface>() .To <MockIClassWithoutAttributes>().WhenIntoInstance(instance2).As("singleton"); container.Bind <IMockInterface>() .To <MockIClass>().WhenInto <MockClassSimple>().WhenIntoInstance(instance2).As("test"); container.Inject(instance1); container.Inject(instance2); Assert.AreEqual(typeof(MockIClassWithAttributes), instance1.field.GetType()); Assert.IsNull(instance2.field); Assert.AreEqual(typeof(MockIClassWithoutAttributes), instance2.property.GetType()); }
public void Inject_SomeClass_Correct() { //Arrange var container = new InjectionContainer(); someClass_c c = new someClass_c(); //Act container.Inject(c); //Assert Assert.AreEqual( true, c.b != null); }
public void TestBindWhenComplexConditionField() { var instance1 = new MockClassVerySimple(); var instance2 = new MockClassSimple(); var instance3 = new MockClassSimple(); var container = new InjectionContainer(); container.Bind <IMockInterface>().To <MockIClass>().When(context => context.member.Equals(InjectionMember.Field) && context.parentInstance.Equals(instance3) ); container.Inject(instance1); container.Inject(instance2); container.Inject(instance3); Assert.IsNull(instance1.field); Assert.IsNull(instance2.field); Assert.IsNull(instance2.property); Assert.AreEqual(typeof(MockIClass), instance3.field.GetType()); Assert.IsNull(instance3.property); }
public void TestBindWhenComplexCondition() { var instance1 = new MockClassVerySimple(); var instance2 = new MockClassSimple(); var instance3 = new MockClassSimple(); var container = new InjectionContainer(); container.Bind<IMockInterface>().To<MockIClass>().When(context => context.member.Equals(InjectionMember.Field) && context.parentInstance.Equals(instance3) ); container.Inject(instance1); container.Inject(instance2); container.Inject(instance3); Assert.IsNull(instance1.field); Assert.IsNull(instance2.field); Assert.IsNull(instance2.property); Assert.AreEqual(typeof(MockIClass), instance3.field.GetType()); Assert.IsNull(instance3.property); }
public void TestBindWhenIntoByInstance() { var instance1 = new MockClassSimple(); var instance2 = new MockClassVerySimple(); var container = new InjectionContainer(); container.Bind<IMockInterface>().To<MockIClassWithAttributes>().WhenIntoInstance(instance1); container.Bind<IMockInterface>().To<MockIClassWithoutAttributes>().WhenIntoInstance(instance2); container.Inject(instance1); container.Inject(instance2); Assert.AreEqual(typeof(MockIClassWithAttributes), instance1.field.GetType()); Assert.AreEqual(typeof(MockIClassWithoutAttributes), instance2.field.GetType()); }