public void ShouldRespectArgumentOrder() { TestFactory test; object obj = RuntimeTypeFactory <ITestFactory> .CreateInstance(node_, "a1", 0, 2); Assert.That(obj, Is.AssignableTo <TestFactory>()); test = (TestFactory)obj; Assert.That(test.Arg, Is.EqualTo(0)); Assert.That(test.StringArg, Is.EqualTo("a1")); Assert.That(test.Arg3, Is.EqualTo(2)); obj = RuntimeTypeFactory <ITestFactory> .CreateInstanceFallback(node_, "a2", 10, 3); Assert.That(obj, Is.AssignableTo <TestFactory>()); test = (TestFactory)obj; Assert.That(test.Arg, Is.EqualTo(10)); Assert.That(test.StringArg, Is.EqualTo("a2")); Assert.That(test.Arg3, Is.EqualTo(3)); obj = RuntimeTypeFactory <ITestFactory> .CreateInstanceNoException(node_, "a3", 20, 4); Assert.That(obj, Is.AssignableTo <TestFactory>()); test = (TestFactory)obj; Assert.That(test.Arg, Is.EqualTo(20)); Assert.That(test.StringArg, Is.EqualTo("a3")); Assert.That(test.Arg3, Is.EqualTo(4)); }
public void ShouldMatchUnorderedListofParameters() { TestFactory test; object obj = RuntimeTypeFactory <ITestFactory> .CreateInstance(node_, "a1", 0); Assert.That(obj, Is.AssignableTo <TestFactory>()); test = (TestFactory)obj; Assert.That(test.Arg, Is.EqualTo(0)); Assert.That(test.StringArg, Is.EqualTo("a1")); obj = RuntimeTypeFactory <ITestFactory> .CreateInstanceFallback(node_, "a2", 10); Assert.That(obj, Is.AssignableTo <TestFactory>()); test = (TestFactory)obj; Assert.That(test.Arg, Is.EqualTo(10)); Assert.That(test.StringArg, Is.EqualTo("a2")); obj = RuntimeTypeFactory <ITestFactory> .CreateInstanceNoException(node_, "a3", 20); Assert.That(obj, Is.AssignableTo <TestFactory>()); test = (TestFactory)obj; Assert.That(test.Arg, Is.EqualTo(20)); Assert.That(test.StringArg, Is.EqualTo("a3")); }
public void ShouldDiscardNonDeclaredParameters() { var base_type = new BaseType(); try { object obj = RuntimeTypeFactory <ITestFactory> .CreateInstance(node_, base_type, string.Empty); } catch { Assert.Fail("Non declared parameters should be discarded"); } }
public void ShouldRecognizeDerivedTypes() { var base_type = new BaseType(); try { object obj = RuntimeTypeFactory <ITestFactory> .CreateInstance(node_, base_type); } catch { Assert.Fail( "Derived type should be accepted as argument for base type parameter"); } }
public void ShouldCreateInstanceForDefaultConstructor() { object obj = RuntimeTypeFactory <ITestFactory> .CreateInstance(node_); Assert.That(obj, Is.AssignableTo <TestFactory>()); obj = RuntimeTypeFactory <ITestFactory> .CreateInstanceFallback(node_); Assert.That(obj, Is.AssignableTo <TestFactory>()); obj = RuntimeTypeFactory <ITestFactory> .CreateInstanceNoException(node_); Assert.That(obj, Is.AssignableTo <TestFactory>()); }
public void ShouldCreateInstanceForNonDefaultConstructor() { object obj = RuntimeTypeFactory <ITestFactory> .CreateInstance(node_, 0); Assert.That(obj, Is.AssignableTo <TestFactory>()); Assert.That(((TestFactory)obj).Arg, Is.EqualTo(0)); obj = RuntimeTypeFactory <ITestFactory> .CreateInstanceFallback(node_, 10); Assert.That(obj, Is.AssignableTo <TestFactory>()); Assert.That(((TestFactory)obj).Arg, Is.EqualTo(10)); obj = RuntimeTypeFactory <ITestFactory> .CreateInstanceNoException(node_, 20); Assert.That(obj, Is.AssignableTo <TestFactory>()); Assert.That(((TestFactory)obj).Arg, Is.EqualTo(20)); }
public void ShouldThrowExceptionWhenTypeLoadFail() { Assert.That(() => RuntimeTypeFactory <TestFactory> .CreateInstance(node_, string.Empty), Throws.Exception); }