public void GenerateField_ShouldGetValue() { var factory = new DynamicMethodFactory(); var instance = new TestClass() { FieldTest = 3 }; var member = typeof(TestClass).GetField(nameof(TestClass.FieldTest)); var getRequest = DynamicMethodRequest.MakeGetterRequest(member); var getMethod = factory.GetFunction <int>(getRequest); var methodFunc = (Func <TestClass, int>)getMethod.Invoker; var result = methodFunc(instance); Assert.That(result, Is.EqualTo(instance.FieldTest)); }
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)); }