public void CtorFindPrivateParameterNegativeLike() { var target = new CtorPrivateParamlessTestFixture(null); const BindingFlags bflags = BindingFlags.NonPublic | BindingFlags.Instance; // when given an other than a string[] or a type[] // should not match any ctor where // all arg name type pairs cannot be mapped // to a specific parameter uniquely in the type ctor //or null is passed TestFind(target, new { arg1 = typeof(string), nothere = typeof(string) }, bflags, true); TestFind(target, new { arg2 = typeof(string), nothere = typeof(string) }, bflags, true); TestFind(target, null as object, bflags, true); // when given a type[ ] // should not match any ctor where // all passed types cannot be mapped // to a specific parameter uniquely in the type ctor TestFind(target, new[] { typeof(int) }, bflags, true); TestFind(target, new[] { typeof(int), typeof(string) }, bflags, true); TestFind(target, new[] { typeof(int), typeof(int) }, bflags, true); // when given a string[ ] // should not match any ctors with parameters // that cannot be mapped uniquely by name to passed string[] TestFind(target, new[] { "arg", "arg1" }, bflags, true); TestFind(target, new[] { "arg", "arg2" }, bflags, true); TestFind(target, new[] { "narg1", "narg2" }, bflags, true); }
public void CtorFindPrivateParameterPositiveEq() { var target = new CtorPrivateParamlessTestFixture(null); const BindingFlags bflags = BindingFlags.NonPublic | BindingFlags.Instance; //should match when exists parameterless ctor TestFind(target, new { }, bflags, true); }
public void CtorFindPrivateParameterNegativeEq() { var target = new CtorPrivateParamlessTestFixture(null); const BindingFlags bflags = BindingFlags.NonPublic | BindingFlags.Instance; // should not match when binding strings do not match TestFind(target, new { arg = typeof(string) }, bflags, true); // should not match unless exist ctor exact match between arg name and arg type in query object TestFind(target, new { arg1 = typeof(string), arg = typeof(string) }, bflags, false); TestFind(target, new { arg = typeof(string), arg2 = typeof(string) }, bflags, false); TestFind(target, new { arg = typeof(int), arg2 = typeof(string) }, bflags, false); TestFind(target, new { arg1 = typeof(int), arg2 = typeof(int) }, bflags, false); TestFind(target, new { arg = typeof(int), arg1 = typeof(string), arg2 = typeof(string) }, bflags, false); TestFind(target, new { shouldnotfind1 = typeof(string), shouldnotfind2 = typeof(string) }, bflags, false); }
public void HasParameterlessPositive() { var ctorParamlessTestTarget1 = new CtorParamlessTestFixture(); var ctorParamlessTestTarget2 = new CtorSingleAndParamless(); var ctorParamlessTestTarget3 = new CtorDoubleAndParamless(); var ctorParamlessTestTarget4 = new CtorDoubleAndSingleAndParamless(); object[] testArgs = { ctorParamlessTestTarget1, ctorParamlessTestTarget2, ctorParamlessTestTarget3, ctorParamlessTestTarget4 }; foreach (var testArg in testArgs) { Assert.IsTrue(_.Object.Constructor.HasParameterless(testArg)); } Type[] testTypeArgs = { typeof(CtorParamlessTestFixture), typeof(CtorSingleAndParamless), typeof(CtorDoubleAndParamless), typeof(CtorDoubleAndSingleAndParamless) }; foreach (var testTypeArg in testTypeArgs) { Assert.IsTrue(_.Object.Constructor.HasParameterless(testTypeArg)); } var privateParamless = new CtorPrivateParamlessTestFixture(null); var staticParamless = new CtorStaticParamlessTestFixture(null); bool[] testBindingFlagsObjectResults = { _.Object.Constructor.HasParameterless(privateParamless, BindingFlags.NonPublic | BindingFlags.Instance), _.Object.Constructor.HasParameterless(staticParamless, BindingFlags.NonPublic | BindingFlags.Static) }; foreach (bool result in testBindingFlagsObjectResults) { Assert.IsTrue(result); } }
public void CtorFindPrivateParameterPositiveLike() { var target = new CtorPrivateParamlessTestFixture(null); const BindingFlags bflags = BindingFlags.NonPublic | BindingFlags.Instance; //should match all ctor where at least one param name and type matching query obj //matches empty TestFind(target, new { }, bflags, true); //should match all ctor where at least one param type matches a type in query obj //or if empty match parameterless //matches parameterless TestFind(target, new Type[] { }, bflags, true); //when given an array of strings should match ctors with parameters that contain matching names //or if empty match parameterless //matches empty param TestFind(target, new string[] { }, bflags, true); }