refactor: reducing code duplication, CreateInstance takes parameters

This commit is contained in:
Chris Cameron
2018-04-05 13:42:08 -04:00
parent 9d034872cb
commit 6a7f5a74af
2 changed files with 38 additions and 58 deletions

View File

@@ -34,23 +34,12 @@ namespace ICD.Common.Utils.Tests
}
}
[TestCase("test", 10)]
[TestCase(null, 0)]
public void InstantiateTest(string param1, int param2)
{
TestClass result = ReflectionUtils.Instantiate(typeof(TestClass), param1, param2) as TestClass;
Assert.NotNull(result);
Assert.AreEqual(param1, result.Param1);
Assert.AreEqual(param2, result.Param2);
}
[Test]
public void MatchesConstructorParametersTest()
{
Assert.Throws<ArgumentNullException>(() => ReflectionUtils.MatchesConstructorParameters(null, new object[] { "test", 10 }));
ConstructorInfo constructor = typeof(TestClass).GetConstructor(new Type[] {typeof(string), typeof(int)});
ConstructorInfo constructor = typeof(TestClass).GetConstructor(new[] {typeof(string), typeof(int)});
Assert.IsTrue(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {"test", 10}));
Assert.IsTrue(ReflectionUtils.MatchesConstructorParameters(constructor, new object[] {null, 10}));
@@ -114,6 +103,17 @@ namespace ICD.Common.Utils.Tests
Assert.NotNull(output);
}
[TestCase("test", 10)]
[TestCase(null, 0)]
public void CreateInstanceTest(string param1, int param2)
{
TestClass result = ReflectionUtils.CreateInstance(typeof(TestClass), param1, param2) as TestClass;
Assert.NotNull(result);
Assert.AreEqual(param1, result.Param1);
Assert.AreEqual(param2, result.Param2);
}
[Test]
public void GetCustomAttributesTest()
{