private static TestCommand BuildTestCommand(TestMethod test)
        {
            var command = (TestCommand) new TestMethodCommand(test);

            command = new UnityLogCheckDelegatingCommand(command);
            foreach (var wrapper in test.Method.GetCustomAttributes <IWrapTestMethod>(true))
            {
                command = wrapper.Wrap(command);
                if (command == null)
                {
                    var message = string.Format("IWrapTestMethod implementation '{0}' returned null as command.", wrapper.GetType().FullName);
                    return(new FailCommand(test, ResultState.Failure, message));
                }
            }

            command = new TestTools.TestActionCommand(command);
            command = new TestTools.SetUpTearDownCommand(command);
            command = new ImmediateEnumerableCommand(command);
            foreach (var wrapper in test.Method.GetCustomAttributes <IWrapSetUpTearDown>(true))
            {
                command = wrapper.Wrap(command);
                if (command == null)
                {
                    var message = string.Format("IWrapSetUpTearDown implementation '{0}' returned null as command.", wrapper.GetType().FullName);
                    return(new FailCommand(test, ResultState.Failure, message));
                }
            }

            command = new EnumerableSetUpTearDownCommand(command);
            command = new OuterUnityTestActionCommand(command);

            IApplyToContext[] changes = test.Method.GetCustomAttributes <IApplyToContext>(true);
            if (changes.Length > 0)
            {
                command = new EnumerableApplyChangesToContextCommand(command, changes);
            }

            return(command);
        }
示例#2
0
        public static TestCommand BuildTestCommand(TestMethod test, ITestFilter filter)
        {
            if (test.RunState != RunState.Runnable &&
                !(test.RunState == RunState.Explicit && filter.IsExplicitMatch(test)))
            {
                return(new SkipCommand(test));
            }

            var testReturnsIEnumerator = test.Method.ReturnType.Type == typeof(IEnumerator);

            TestCommand command;

            if (!testReturnsIEnumerator)
            {
                command = new UnityTestMethodCommand(test);
            }
            else
            {
                command = new EnumerableTestMethodCommand(test);
            }

            command = new UnityLogCheckDelegatingCommand(command);
            foreach (var wrapper in test.Method.GetCustomAttributes <IWrapTestMethod>(true))
            {
                command = wrapper.Wrap(command);
                if (command == null)
                {
                    var message = String.Format("IWrapTestMethod implementation '{0}' returned null as command.",
                                                wrapper.GetType().FullName);
                    return(new FailCommand(test, ResultState.Failure, message));
                }

                if (testReturnsIEnumerator && !(command is IEnumerableTestMethodCommand))
                {
                    command = TryReplaceWithEnumerableCommand(command);
                    if (command != null)
                    {
                        continue;
                    }

                    var message = String.Format("'{0}' is not supported on {1} as it does not handle returning IEnumerator.",
                                                wrapper.GetType().FullName,
                                                GetTestBuilderName(test));
                    return(new FailCommand(test, ResultState.Failure, message));
                }
            }

            command = new UnityEngine.TestTools.TestActionCommand(command);
            command = new UnityEngine.TestTools.SetUpTearDownCommand(command);

            if (!testReturnsIEnumerator)
            {
                command = new ImmediateEnumerableCommand(command);
            }

            foreach (var wrapper in test.Method.GetCustomAttributes <IWrapSetUpTearDown>(true))
            {
                command = wrapper.Wrap(command);
                if (command == null)
                {
                    var message = String.Format("IWrapSetUpTearDown implementation '{0}' returned null as command.",
                                                wrapper.GetType().FullName);
                    return(new FailCommand(test, ResultState.Failure, message));
                }

                if (testReturnsIEnumerator && !(command is IEnumerableTestMethodCommand))
                {
                    command = TryReplaceWithEnumerableCommand(command);
                    if (command != null)
                    {
                        continue;
                    }

                    var message = String.Format("'{0}' is not supported on {1} as it does not handle returning IEnumerator.",
                                                wrapper.GetType().FullName,
                                                GetTestBuilderName(test));
                    return(new FailCommand(test, ResultState.Failure, message));
                }
            }

            command = new EnumerableSetUpTearDownCommand(command);
            command = new OuterUnityTestActionCommand(command);

            IApplyToContext[] changes = test.Method.GetCustomAttributes <IApplyToContext>(true);
            if (changes.Length > 0)
            {
                command = new EnumerableApplyChangesToContextCommand(command, changes);
            }

            return(command);
        }