Exemplo n.º 1
0
        public void TestParamsLengthZero()
        {
            var obj = new MyTestClass();
            // Check that passing no parameters to the 'params' parameter (empty array) works
            var result = ClrFacade.CallInstanceMethod(obj, "UniqueNameStrStrParams", new[] { "", "" });

            // However, if it means that there are more than one candidate methods:
            Assert.Throws <AmbiguousMatchException>(() => { ClrFacade.CallInstanceMethod(obj, "StringSameNameParams", new[] { "" }); });
        }
Exemplo n.º 2
0
        public void TestOptionalParametersMethodInvocation()
        {
            // TODO tighter checks. Start with: it does not bomb...
            var obj = new MyTestClass();

            ClrFacade.CallInstanceMethod(obj, "OptionalInt", new object[] { });
            ClrFacade.CallInstanceMethod(obj, "OptionalInt", new object[] { 3 });

            ClrFacade.CallInstanceMethod(obj, "IntOptionalInt", new object[] { 3 });
            ClrFacade.CallInstanceMethod(obj, "IntOptionalInt", new object[] { 3, 5 });

            ClrFacade.CallInstanceMethod(obj, "DoubleOptionalInt", new object[] { 3.0 });
            ClrFacade.CallInstanceMethod(obj, "DoubleOptionalInt", new object[] { 3.0, 5 });

            ClrFacade.CallInstanceMethod(obj, "DoubleOptionalIntDoubleString", new object[] { 3.0, 5, 4.5, "blah" });
            ClrFacade.CallInstanceMethod(obj, "DoubleOptionalIntDoubleString", new object[] { 3.0, 5, 4.5 });
            ClrFacade.CallInstanceMethod(obj, "DoubleOptionalIntDoubleString", new object[] { 3.0, 5 });
            ClrFacade.CallInstanceMethod(obj, "DoubleOptionalIntDoubleString", new object[] { 3.0 });

            Assert.Equal("LevelOneClass", ClrFacade.CallInstanceMethod(obj, "OptionalArgsMatch", new object[] { new LevelOneClass() }));
            Assert.Equal("LevelTwoClass", ClrFacade.CallInstanceMethod(obj, "OptionalArgsMatch", new object[] { new LevelTwoClass() }));
            Assert.Equal("IMyInterface", ClrFacade.CallInstanceMethod(obj, "OptionalArgsMatch", new object[] { new OtherLevelOneClass() }));
        }