Пример #1
0
        public void GenerateField_ShouldSetValue()
        {
            var factory  = new DynamicMethodFactory();
            var instance = new TestClass();
            var member   = typeof(TestClass).GetField(nameof(TestClass.FieldTest));

            var setRequest = DynamicMethodRequest.MakeSetterRequest(member);
            var setMethod  = factory.GetAction(setRequest);
            var methodFunc = (Action <TestClass, int>)setMethod.Invoker;

            methodFunc(instance, 3);
            Assert.That(instance.FieldTest, Is.EqualTo(3));
        }
Пример #2
0
        public void GenerateField_ShouldBeBidirectional(TestCaseData <FieldInfo> testCase)
        {
            var factory        = new DynamicMethodFactory();
            var expectedResult = testCase.Args.Last();

            var setRequest = DynamicMethodRequest.MakeSetterRequest(testCase.Method);
            var setMethod  = factory.GetAction(setRequest);
            var setArgs    = TestCaseHelper.GetArgs(testCase.Args, testCase.Instance);

            setMethod.Invoke(setArgs);

            var getRequest = DynamicMethodRequest.MakeGetterRequest(testCase.Method);
            var getMethod  = factory.GetFunction <int>(getRequest);
            var getArgs    = TestCaseHelper.GetArgs(null, testCase.Instance);
            var result     = getMethod.Invoke(getArgs);

            Assert.That(result, Is.EqualTo(expectedResult));
        }