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 ShouldUseDefaultConstructorWhenMatchIsNotFound() { object obj = RuntimeTypeFactory <ITestFactory> .CreateInstanceFallback(node_, string.Empty); Assert.That(obj, Is.AssignableTo <TestFactory>()); Assert.That(((TestFactory)obj).Arg, Is.EqualTo(-1)); }
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)); }