Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BeforeTestActionCommand"/> class.
        /// </summary>
        /// <param name="innerCommand">The inner command.</param>
        /// <param name="action">The TestActionItem to run before the inner command.</param>
        public BeforeTestActionCommand(TestCommand innerCommand, TestActionItem action)
            : base(innerCommand)
        {
            Guard.ArgumentValid(innerCommand.Test is TestSuite, "TestActionBeforeCommand may only apply to a TestSuite", "innerCommand");
            Guard.ArgumentNotNull(action, nameof(action));

            BeforeTest = (context) =>
            {
                action.BeforeTest(Test);
            };
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AfterTestActionCommand"/> class.
        /// </summary>
        /// <param name="innerCommand">The inner command.</param>
        /// <param name="action">The TestActionItem to run before the inner command.</param>
        public AfterTestActionCommand(TestCommand innerCommand, TestActionItem action)
            : base(innerCommand)
        {
            Guard.ArgumentValid(innerCommand.Test is TestSuite, "BeforeTestActionCommand may only apply to a TestSuite", nameof(innerCommand));
            Guard.ArgumentNotNull(action, nameof(action));

            AfterTest = (context) =>
            {
                if (action.BeforeTestWasRun)
                {
                    action.AfterTest(Test);
                }
            };
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="AfterTestActionCommand"/> class.
        /// </summary>
        /// <param name="innerCommand">The inner command.</param>
        /// <param name="action">The TestActionItem to run before the inner command.</param>
        public AfterTestActionCommand(TestCommand innerCommand, TestActionItem action)
            : base(innerCommand)
        {
            Guard.ArgumentValid(innerCommand.Test is TestSuite, "BeforeTestActionCommand may only apply to a TestSuite", nameof(innerCommand));
            Guard.ArgumentNotNull(action, nameof(action));

            AfterTest = (context) =>
            {
                if (action.BeforeTestWasRun)
                {
                    var oldCount = context.CurrentResult.AssertionResults.Count;

                    action.AfterTest(Test);

                    // If there are new assertion results here, they are warnings issued
                    // in teardown. Redo test completion so they are listed properly.
                    if (context.CurrentResult.AssertionResults.Count > oldCount)
                    {
                        context.CurrentResult.RecordTestCompletion();
                    }
                }
                ;
            };
        }