private static unsafe void TypedPointerFieldTest(DynamicInvoker reader, DynamicInvoker writer) { var obj = new MyClass() { TypedPointerField = (byte *)new IntPtr(42) }; Equal(new IntPtr(42), new IntPtr(Pointer.Unbox(reader.Invoke(obj)))); Null(writer.Invoke(obj, Pointer.Box(new IntPtr(56).ToPointer(), typeof(byte *)))); Equal(new IntPtr(56), new IntPtr(Pointer.Unbox(reader.Invoke(obj)))); }
private static void ValueTypeFieldTest(DynamicInvoker reader, DynamicInvoker writer) { var obj = new MyClass(); Null(writer.Invoke(obj, 42)); Equal(42, reader.Invoke(obj)); }
private static void ObjectFieldTest(DynamicInvoker reader, DynamicInvoker writer) { var obj = new MyClass(); Null(writer.Invoke(obj, "Hello, world")); Equal("Hello, world", reader.Invoke(obj)); }
public void InvokeUsingSingleIntParameter() { object sample = new Sample <int>(); var invoker = new DynamicInvoker(sample.GetType()); invoker.Invoke(sample, "ReturnHashCode", 35) .Should().Be(35.GetHashCode()); }
public void MatchMethodTest() { var testGenerator = new TestGenerator(); var invoker = new DynamicInvoker( testGenerator ); var typeProperty = new TypeProperty { Name = "TypeProperty1", Type = typeof(int) }; var navigationProperty1 = new NavigationProperty { Name = "Property1", Property = typeProperty, IsCollection = true }; var navigationProperty2 = new NavigationProperty { Name = "Property2", Property = typeProperty, IsCollection = false }; invoker.Invoke<object>( "DefineProperty", navigationProperty1 ); invoker.Invoke<object>( "DefineProperty", navigationProperty2 ); Assert.That( testGenerator.TypeDefinePropertyCalls, Is.EqualTo( 0 ) ); Assert.That( testGenerator.NavigationDefinePropertyCalls, Is.EqualTo( 2 ) ); Assert.That( testGenerator.NavigationListDefinePropertyCalls, Is.EqualTo( 1 ) ); Assert.That( testGenerator.NavigationNotListDefinePropertyCalls, Is.EqualTo( 1 ) ); }
public void InvokeUsingTwoParametersAndOverloadedMethodsPassingNullToSecondParameter() { var expected = 35.GetHashCode(); object sample = new Sample <int>(); var invoker = new DynamicInvoker(sample.GetType()); invoker.Invoke(sample, "ReturnHashCode", 35, null) .Should().Be(expected); }
public void InvokeMethodWithOutParameterAndReferenceType() { object sample = new Sample <string>(); object[] args = new[] { null, "asd" }; var invoker = new DynamicInvoker(sample.GetType()); invoker.Invoke(sample, "SetValue", args).Should().Be(null); args.Should().Have.SameSequenceAs("asd", "asd"); }
public void InvokeVoidMethodRespectsCounterEffects() { object sample = new Sample <string>(); var invoker = new DynamicInvoker(sample.GetType()); invoker.Invoke(sample, "SetFlag", "true") .Should().Be(null); sample.Should().Be.OfType <Sample <string> >() .And.Value.Flag.Should().Be("true"); }
private static void EmptyAndNullParametersTestHelper( DynamicInvoker dynamicInvoker, string parameters ) { var callStatement = new CallStatement( Helper.EmptyPosition, "Name", parameters ); var invokeCodeWriter = dynamicInvoker.Invoke<CodeWriter>( "GenerateInvoke", callStatement ); Assert.IsNotNull( invokeCodeWriter ); var invokeText = invokeCodeWriter.ToString().Replace( " ", "" ); Assert.That( invokeText, Is.EqualTo( "this.Invoke(\"Name\")" ) ); }
public void SimpleInvokeTest() { var testGenerator = new TestGenerator(); var invoker = new DynamicInvoker( testGenerator ); var typeProperty = new TypeProperty { Name = "Property1", Type = typeof(int) }; invoker.Invoke<object>( "DefineProperty", typeProperty ); Assert.That( testGenerator.TypeDefinePropertyCalls, Is.EqualTo( 1 ) ); Assert.That( testGenerator.NavigationDefinePropertyCalls, Is.EqualTo( 0 ) ); testGenerator.TypeDefinePropertyCalls = 0; var navigationProperty = new ComplexProperty { Name = "Property2", Type = typeof(string) }; invoker.Invoke<object>( "DefineProperty", navigationProperty ); Assert.That( testGenerator.TypeDefinePropertyCalls, Is.EqualTo( 0 ) ); Assert.That( testGenerator.ComplexDefinePropertyCalls, Is.EqualTo( 1 ) ); }
public void SimpleTest() { var generator = new Generator(); var dynamicInvoker = new DynamicInvoker( generator ); var callStatement = new CallStatement( Helper.EmptyPosition, "Name", "param1, param2" ); var invokeCodeWriter = dynamicInvoker.Invoke<CodeWriter>( "GenerateInvoke", callStatement ); Assert.IsNotNull( invokeCodeWriter ); var invokeText = invokeCodeWriter.ToString().Replace( " ", "" ); Assert.That( invokeText, Is.EqualTo( "this.Invoke(\"Name\",param1,param2)" ) ); }