public void IfMethodWithThrowIsWeaved_ThenTheAssemblyShouldBeValid()
        {
            // Arrange
            const string testMethodName = "MethodWithThrowAndReturnValue";
            var          testClassType  = typeof(SpecialOperatorMethods);

            // Act
            WeaveAssemblyMethodAndLoad(testClassType, testMethodName);
            Action call = () => AssemblyLoader.InvokeMethod(testClassType.FullName, testMethodName);

            // Assert
            Weaver.TotalWeavedMethods.Should().Be(1);
            Weaver.TotalWeavedTypes.Should().Be(1);
            call.Should().Throw <TargetInvocationException>()
            .WithInnerException <InvalidOperationException>()
            .WithMessage("This is a test exception");
        }
        public void IfInstanceMethodCallWithTryCatchIsWeaved_ThenTheAssemblyShouldBeValid()
        {
            // Arrange
            const string testMethodName = "InstanceMethodCallWithTryCatch";
            var          testClassType  = typeof(TryCatchMethods);

            // Act
            WeaveAssemblyMethodAndLoad(testClassType, testMethodName);
            Action call = () => AssemblyLoader.InvokeMethod(testClassType.FullName, testMethodName);

            // Assert
            Weaver.TotalWeavedMethods.Should().Be(1);
            Weaver.TotalWeavedTypes.Should().Be(1);
            call.Should().Throw <TargetInvocationException>()
            .WithInnerException <InvalidOperationException>()
            .WithMessage(testMethodName);
        }
示例#3
0
        public void IfMethodWhichEndsWithThrowAndHasMultipleReturns_3_ThenTheAssemblyShouldBeValid()
        {
            // Arrange
            const string testMethodName = "MethodWhichEndsWithThrowAndHasMultipleReturns";
            var          testClassType  = typeof(SpecialMethodBodies);

            // Act
            WeaveAssemblyMethodAndLoad(testClassType, testMethodName);
            Action call = () => AssemblyLoader.InvokeMethod(testClassType.FullName, testMethodName, 3);

            // Assert
            Weaver.TotalWeavedMethods.Should().Be(1);
            Weaver.TotalWeavedTypes.Should().Be(1);
            call.ShouldThrow <TargetInvocationException>()
            .WithInnerException <InvalidOperationException>()
            .WithInnerMessage("This exception is expected");
        }
        public void IfInstanceMethodIsCalled_ThenTheOnMethodBoundaryAspectShouldBeCalled()
        {
            // Arrange
            const string testMethodName = "InstanceMethodCall";

            WeaveAssemblyMethodAndLoad(TestClassType, testMethodName);

            // Act
            Action call = () => AssemblyLoader.InvokeMethod(TestClassType.FullName, testMethodName);

            // Assert
            call.Should().Throw <TargetInvocationException>()
            .WithInnerException <InvalidOperationException>()
            .WithMessage(testMethodName);

            var result = AssemblyLoader.GetLastResult(TestClassType.FullName);

            result.Should().BeOfType <InvalidOperationException>();
        }
        protected object Run(string methodName)
        {
            object result;
            var    method = ClosedClassType.GetMethod(methodName);

            if (method.IsGenericMethod)
            {
                var generics = method.GetGenericArguments();
                if (generics.Length == 1)
                {
                    result = AssemblyLoader.InvokeGenericMethod(ClosedClassType.TypeInfo(), methodName, new Type[] { typeof(MethodDisposable) }, Args);
                }
                else
                {
                    result = AssemblyLoader.InvokeGenericMethod(ClosedClassType.TypeInfo(), methodName, new Type[] { typeof(MethodDisposable), typeof(List <MethodDisposable[]>) }, Args);
                }
            }
            else
            {
                result = AssemblyLoader.InvokeMethod(ClosedClassType.TypeInfo(), methodName, Args);
            }

            return(result);
        }