Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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"));
        }
Exemplo n.º 3
0
        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");
            }
        }
Exemplo n.º 4
0
        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");
            }
        }
Exemplo n.º 5
0
        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>());
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
 public void ShouldThrowExceptionWhenTypeLoadFail()
 {
     Assert.That(() => RuntimeTypeFactory <TestFactory>
                 .CreateInstance(node_, string.Empty), Throws.Exception);
 }