public void SamopalDISeeCommentsIntTest08() { var di = new SamopalDI(); di.BindExample <IClass5>(100500, (args) => new Class5((string)args[0])); // here is the source of problems // IClass3 is binding to example 1, not to Default, // and IClass2 isn't get IClass3 instance by correct delegate di.BindExample <IClass2, Class2>(1456); di.BindExample <IClass3, Class3>(3334445); di.BindExample <IClass4>(1, (args) => { IClass5 c5 = di.GetExample <IClass5>(100500, args); return(new Class4(c5)); }); di.BindExample <IClass1>(-100600, (args) => { IClass2 c2 = di.GetExample <IClass2>(1456); IClass4 c4 = di.GetExample <IClass4>(1, args); return(new Class1(c2, c4)); }); object[] arrayOfArgs = new object[] { "Hello, Test!" }; Assert.ThrowsException <ArgumentException>(() => di.GetExample <IClass1>(-100600, arrayOfArgs)); }
public void SamopalDISeeCommentsIntTest02() { var di = new SamopalDI(); di.BindDefault <IClass3, Class3>(); di.BindExample <IClass2>(1, (args) => new Class2(di.GetDefault <IClass3>())); IClass2 class2WithClass3 = di.GetExample <IClass2>(1, null); di.BindDefault <IClass3, AnotherClass3>(); di.BindExample <IClass2>(1, (args) => new AnotherClass2(di.GetDefault <IClass3>())); IClass2 class2WithAnotherClass3 = di.GetExample <IClass2>(1, null); }
public void SamopalDISeeCommentsIntTest01() { var di = new SamopalDI(); // There wasn't Default Bind Assert.ThrowsException <ArgumentException>(() => di.GetDefault <IClass1>()); // And there wasn't Example 1 Bind Assert.ThrowsException <ArgumentException>(() => di.GetExample <IClass1>(1)); }
public void SamopalDISeeCommentsIntTest09() { var di = new SamopalDI(); di.BindExample <IClass5>(100500, (args) => new Class5((string)args[0])); // now we'll get IClass4 example instance by correct delegate di.BindExample <IClass2>(1456, (args) => { IClass3 class3 = di.GetExample <IClass3>(3334445); return(new Class2(class3)); }); di.BindExample <IClass3, Class3>(3334445); di.BindExample <IClass4>(1, (args) => { IClass5 c5 = di.GetExample <IClass5>(100500, args); return(new Class4(c5)); }); di.BindExample <IClass1>(-100600, (args) => { IClass2 c2 = di.GetExample <IClass2>(1456); IClass4 c4 = di.GetExample <IClass4>(1, args); return(new Class1(c2, c4)); }); object[] arrayOfArgs = new object[] { "Hello, Test!" }; Type expected = typeof(Class1); IClass1 variable = di.GetExample <IClass1>(-100600, arrayOfArgs); Type actual = variable.GetType(); Assert.AreEqual(expected, actual); Assert.AreEqual("Hello, Test!", variable.Class4.Class5.SomeString); Assert.IsNotNull(variable.Class2.Class3); }