예제 #1
0
        private TaskResult Start(IRemoteTaskServer server, TaskExecutionNode node, MSTestTask test)
        {
            var fixture = (MSTestFixtureTask)node.Parent.RemoteTask;

            object instance = fixture.Instance;
            Type   type     = instance.GetType();

            MethodInfo testMI = type.GetMethod(test.TestMethod, new Type[0]);

            if (testMI == null)
            {
                server.TaskError(test, string.Format("Cannot find test  method '{0}'", test.TestMethod));
                return(TaskResult.Error);
            }

            if (IsIgnored(testMI) && !test.Explicitly)
            {
                server.TaskFinished(test, null, TaskResult.Skipped);
                return(TaskResult.Skipped);
            }

            if (myTestSetUp != null)
            {
                server.TaskProgress(test, "Setting up...");

                try
                {
                    if (myTestSetUp.GetParameters().Length == 1)
                    {
                        var testContext = new object[] { null };
                        TaskExecutor.Invoke(fixture.Instance, myTestSetUp, testContext);
                    }
                    else
                    {
                        TaskExecutor.Invoke(fixture.Instance, myTestSetUp);
                    }
                }
                catch (TargetInvocationException e)
                {
                    Exception exception = e.InnerException ?? e;

                    string message;
                    Server.TaskException(test, TaskExecutor.ConvertExceptions(exception, out message));
                    Server.TaskFinished(test, message, TaskResult.Exception);
                    return(TaskResult.Exception);
                }
            }

            return(TaskResult.Success);
        }
예제 #2
0
        private TaskResult Finish(IRemoteTaskServer server, TaskExecutionNode node, MSTestTask test)
        {
            var fixture = (MSTestFixtureTask)node.Parent.RemoteTask;

            if (myTestTearDown != null)
            {
                server.TaskProgress(test, "Tearing down...");
                try
                {
                    TaskExecutor.Invoke(fixture.Instance, myTestTearDown);
                }
                catch (TargetInvocationException e)
                {
                    Exception exception = e.InnerException ?? e;

                    string message;
                    Server.TaskException(test, TaskExecutor.ConvertExceptions(exception, out message));
                    Server.TaskFinished(test, message, TaskResult.Exception);
                    return(TaskResult.Exception);
                }
            }
            server.TaskProgress(test, "");
            return(TaskResult.Success);
        }
예제 #3
0
        private static TaskResult Execute(IRemoteTaskServer server, TaskExecutionNode node, MSTestTask test)
        {
            var    fixture  = (MSTestFixtureTask)node.Parent.RemoteTask;
            object instance = fixture.Instance;
            Type   type     = instance.GetType();

            MethodInfo testMI = type.GetMethod(test.TestMethod, new Type[0]);

            if (testMI == null)
            {
                server.TaskError(test, string.Format("Cannot find test  method '{0}'", test.TestMethod));
                return(TaskResult.Error);
            }
            server.TaskProgress(test, "");

            string expectedExceptionType;

            GetExpectedException(testMI, out expectedExceptionType);

            Exception exception = null;

            try
            {
                TaskExecutor.Invoke(instance, testMI);
            }
            catch (TargetInvocationException e)
            {
                exception = e.InnerException ?? e;
            }
//            if (exception != null && exception.GetType().FullName == "csUnit.IgnoreException")
//            {
//                server.TaskFinished(test, exception.Message, TaskResult.Skipped);
//                return TaskResult.Skipped;
//            }
            if (expectedExceptionType != null && exception == null)
            {
                // failed, exception expected but not thrown
                server.TaskError(test, string.Format("Expected exception '{0}' was not thrown", expectedExceptionType));
                return(TaskResult.Error);
            }
            if (expectedExceptionType != null && expectedExceptionType == exception.GetType().FullName)
            {
                return(TaskResult.Success);
            }
            if (exception != null)
            {
                if (exception.GetType().FullName == "Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException")
                {
                    exception = new MSTestExceptionAdapter(exception);
                }
                throw new TargetInvocationException(exception);
            }

            return(TaskResult.Success);
        }