示例#1
0
        public void TestMethodDefaultMethod3()
        {
            List <string>    methodsCalled = new List <string>();
            BeethovenFactory factory       = new BeethovenFactory();
            ITestMethods     test          = factory.Generate <ITestMethods>(
                new DefaultMethod((methodInfo, _) => methodsCalled.Add(methodInfo.Name)));

            test.Simple();
            test.ReturnValue();
            test.WithParameters("as", "wefewf");
            test.WithParameters("", null, 5);
            string b = "";

            test.OutAndRef(out string a, ref b, 5);
            int value = 0;

            test.Ref(ref value);
            test.GetMain("klkl", "kklklklkk");
            test.NoReturnValue("", "");
            CollectionAssert.AreEquivalent(new[]
            {
                "Simple",
                "ReturnValue",
                "WithParameters",
                "WithParameters",
                "OutAndRef",
                "Ref",
                "GetMain",
                "NoReturnValue"
            },
                                           methodsCalled);
        }
        public void MethodRefInvalid()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestMethods     test    = factory.Generate <ITestMethods>(new InvalidSignature());
            int value = 5;

            test.Ref(ref value);
            Assert.Fail();
        }
示例#3
0
        public void MethodRefTest()
        {
            OutAndRefImplementation obj     = new OutAndRefImplementation();
            BeethovenFactory        factory = new BeethovenFactory();
            ITestMethods            test    = factory.Generate <ITestMethods>(obj);
            int value = 4;

            test.Ref(ref value);
            Assert.AreEqual(5, value);
        }
示例#4
0
        public void TestMethodDefaultMethod4()
        {
            BeethovenFactory factory = new BeethovenFactory();
            ITestMethods     test    = factory.Generate <ITestMethods>(
                new DefaultMethod((methodInfo, parameters) =>
            {
                Type intRefType = typeof(int).MakeByRefType();
                ParameterInfo[] parameterInfos = methodInfo.GetParameters();
                foreach (ParameterInfo parameterInfo in parameterInfos.Where(info => info.ParameterType == intRefType))
                {
                    parameters[parameterInfo.Position] = 5;
                }
            }));
            string b = "";

            test.OutAndRef(out string a, ref b, 5);
            int value = 0;

            test.Ref(ref value);
            Assert.AreEqual(5, value);
        }