public void MethodExcludedByMaskShouldNotBePresent() { CompilerResults.TryLoadCompiledType("Test.Target") .GetType() .GetMethod("ClassMethod", BindingFlags.Instance | BindingFlags.Public) .ShouldBeNull(); }
public void InterceptorCanceledMethodInvocation() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); Assert.True(target.Method() == "Interceptor", "Method() should be intercepted"); Assert.True(target.WasMethodCalled == false, "WasMethodCalled should be false"); }
public override void MainSetup() { base.MainSetup(); target = CompilerResults.TryLoadCompiledType("Test.Target"); Assert.True(null != target, "Failed to load Target"); }
public void MethodWithGenericOutput() { dynamic target = CompilerResults .TryLoadCompiledType("Test.Target"); ((string)target.GenericMethodOutput(5, "HelloWorld")) .ShouldEqual("HelloWorld"); }
public void MethodWithGenericParam() { dynamic target = CompilerResults .TryLoadCompiledType("Test.Target"); ((int)target.GenericMethodParam(5, "HelloWorld")) .ShouldEqual(5); }
public void CanExecuteMixinMethod() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); int getNumber = target.MixinMethod(); getNumber.ShouldEqual(42); }
public void CanCallGetNumberOnChild() { dynamic target = CompilerResults.TryLoadCompiledType("Test.TargetChild"); int number = target.GetNumber(); number.ShouldEqual(1); }
public void MethodThatReturnsGenericChild() { dynamic target = CompilerResults .TryLoadCompiledType("Test.Target"); ((string)target.GetGenericChild <string>().Method("HelloWorld")) .ShouldEqual("HelloWorld"); }
public void MethodThatReturnsChild() { dynamic target = CompilerResults .TryLoadCompiledType("Test.Target"); ((int)target.GetChild().Number) .ShouldEqual(42); }
public void MixinRequiredByInterceptorIsMixedIntoTarget() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); target.AddLogMessage("Test"); Assert.True(target.Messages.Count > 0, "No evidence Mixin method AddLogMessage was called."); }
public void DoNotMixinMethodShouldNotBePresent() { CompilerResults .TryLoadCompiledType("Test.Target") .GetType() .GetMethod("DoNotMixinMethod", BindingFlags.Instance | BindingFlags.Public) .ShouldBeNull(); }
public void InterceptorManipulatedMethodReturnValue() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); Assert.True(target.Method() == "Mixin_Interceptor", "Method() should be intercepted and return value manipulated"); Assert.True(target.WasMethodCalled == true, "WasMethodCalled should be true"); }
public void CanCallProtectedMethod() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Child"); string result = target.ProtectedMethod <int>(42); result.ShouldEqual("42Protected"); }
public void CanCallPublicMethod() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); string result = target.Method <int>(); result.ShouldEqual("Public Method"); }
public void CanCallMethodWithTwoParameters() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); string result = target.PublicMethodWithTwoParameters <string, int>("Hello", 42); result.ShouldEqual("Hello42"); }
public void CanCallMethodWithOneParameter() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); int result = target.PublicMethodWithOneParameter <int>(10); result.ShouldEqual(10); }
public static T TryLoadCompiledType <T>(this CompilerResults compilerResults, params object[] constructorArgs) where T : class { var loadedType = compilerResults.TryLoadCompiledType(typeof(T).FullName, constructorArgs); return(null == loadedType ? null : (T)loadedType); }
public static MemberInfo GetMember(this CompilerResults compilerResults, string typeName, object[] constructorArgs, string memberName, BindingFlags bindingFlags = ReflectionHelper.DefaultBindingFlags) { return(ReflectionHelper.LoadMember( compilerResults.TryLoadCompiledType(typeName, constructorArgs), memberName, bindingFlags)); }
public static void ExecuteVoidMethod(this CompilerResults compilerResults, string typeName, object[] constructorArgs, string methodName, BindingFlags bindingFlags = ReflectionHelper.DefaultBindingFlags, params object[] args) { constructorArgs = constructorArgs ?? new object[0]; ReflectionHelper.ExecuteVoidMethod( compilerResults.TryLoadCompiledType(typeName, constructorArgs), methodName, bindingFlags, args); }
public override void MainSetup() { base.MainSetup(); var targetInstance = CompilerResults.TryLoadCompiledType("Test.Target"); Assert.True(null != targetInstance, "Failed to get Target instance"); TargetType = targetInstance.GetType(); }
public void CanCallMethodWithGenericConstraint() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); var e = new NullReferenceException("Message"); string result = target.PublicMethodWithGenericConstraint <NullReferenceException>(e); result.ShouldEqual(e.Message); }
public void GenericProperty() { dynamic target = CompilerResults .TryLoadCompiledType("Test.Target"); target.GenericProperty = 42; ((int)target.GenericProperty) .ShouldEqual(42); }
public void CanExecuteMethodWithArrays() { dynamic entity = CompilerResults.TryLoadCompiledType("Test.MyEntity"); dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); object result = target.MyEntityMethod(entity); result.ShouldNotBeNull(); }
public void InternalMethodShouldHaveCorrectModifier() { var target = CompilerResults.TryLoadCompiledType("Test.Target"); var method = target.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance) .FirstOrDefault(m => m.Name == "InternalMethod"); Assert.True(null != method, "Couldn't load method definition"); method.IsPublic.ShouldBeFalse(); }
public void ProtectedMethodIsNotAccessible() { var instance = CompilerResults .TryLoadCompiledType("Test.TargetWithoutInitialization"); Assert.True(null != instance, "Failed to load Test.TargetWithoutInitialization"); instance.GetType().GetMethods(ReflectionHelper.DefaultBindingFlags) .Any(method => method.Name == "ProtectedMethod").ShouldBeFalse(); }
public void CanCallTargetMethod() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); Assert.AreEqual( "Mixin1 Target With Shared Requirements", ((string)target.GetName1())); Assert.AreEqual( "Mixin2 Target With Shared Requirements", ((string)target.GetName2())); }
public void CanCallProperty() { var testList = new List <int> { 42 }; dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); target.GenericProperty = testList; Assert.True(target.GenericProperty.Contains(42), "Property get/set failed."); }
public void InterceptorManipulatedMethodReturnValue() { dynamic target = CompilerResults.TryLoadCompiledType("Test.Target"); Assert.True(target.Method() == "Mixin", "Method() should return correct value"); Assert.True(target.Messages.Count > 1, "No evidence Mixin method AddLogMessage was called."); Assert.True(target.Messages.Contains("OnBeforeMethod: Method"), "OnBeforeMethod event was not logged"); Assert.True(target.Messages.Contains("OnAfterMethod: Method"), "OnAfterMethod event was not logged"); }
public static T ExecutePropertyGet <T>( this CompilerResults compilerResults, string typeName, object[] constructorArgs, string propertyName, BindingFlags bindingFlags = ReflectionHelper.DefaultBindingFlags) { constructorArgs = constructorArgs ?? new object[0]; return (ReflectionHelper.ExecutePropertyGet <T>( compilerResults.TryLoadCompiledType(typeName, constructorArgs), propertyName, bindingFlags)); }
public static void ExecutePropertySet <T>( this CompilerResults compilerResults, string typeName, object[] constructorArgs, string propertyName, T value, BindingFlags bindingFlags = ReflectionHelper.DefaultBindingFlags) where T : class { constructorArgs = constructorArgs ?? new object[0]; ReflectionHelper.ExecutePropertySet( compilerResults.TryLoadCompiledType(typeName, constructorArgs), propertyName, value, bindingFlags); }