Example #1
0
    /// <summary>
    /// Runs a When step with the specified results of a fixture step.
    /// </summary>
    /// <param name="results">The results of the fixture step that was completed running.</param>
    /// <returns>The result of the When step running.</returns>
    protected override FixtureStepResult.Builder Run(FixtureStepResultCollection results)
    {
        if (IsPending)
        {
            return(FixtureStepResult.Of(Step).Pending());
        }

        if (results.HasExceptionAt <GivenStep>() || results.HasLatestExceptionAt <WhenStep>())
        {
            return(FixtureStepResult.Of(Step).Ready());
        }

        if (results.HasStatusAt <GivenStep>(FixtureStepStatus.Ready) || results.HasStatusAtLatest <WhenStep>(FixtureStepStatus.Ready))
        {
            return(FixtureStepResult.Of(Step).Ready());
        }

        if (results.HasStatusAt <GivenStep>(FixtureStepStatus.Pending) || results.HasStatusAtLatest <WhenStep>(FixtureStepStatus.Pending))
        {
            return(FixtureStepResult.Of(Step).Pending());
        }

        try
        {
            RunWhenStep();

            return(FixtureStepResult.Of(Step).Passed());
        }
        catch (Exception exc)
        {
            return(FixtureStepResult.Of(Step).Failed(exc));
        }
    }
Example #2
0
    /// <summary>
    /// Runs a Then step with the specified results of a fixture step.
    /// </summary>
    /// <param name="results">The results of the fixture step that was completed running.</param>
    /// <returns>The result of the Then step running.</returns>
    /// <exception cref="InvalidFixtureStepException">
    /// The <paramref name="results"/> does not have the <see cref="WhenStep"/>.
    /// </exception>
    protected override FixtureStepResult.Builder Run(FixtureStepResultCollection results)
    {
        if (!results.Has(typeof(WhenStep)))
        {
            throw new InvalidFixtureStepException("Then must be after When.");
        }

        if (IsPending)
        {
            return(FixtureStepResult.Of(Step).Pending());
        }

        if (HasAssertionWithoutException && results.HasLatestExceptionAt <WhenStep>())
        {
            return(FixtureStepResult.Of(Step).Ready());
        }

        if (results.HasStatusAtLatest <WhenStep>(FixtureStepStatus.Ready))
        {
            return(FixtureStepResult.Of(Step).Ready());
        }

        if (results.HasStatusAtLatest <WhenStep>(FixtureStepStatus.Pending))
        {
            return(FixtureStepResult.Of(Step).Pending());
        }

        try
        {
            if (Step.Assertion is not null)
            {
                Step.ExecuteAssertion(Step.Assertion);
            }
            Step.Action?.Invoke();
            Step.AsyncAction?.Invoke().GetAwaiter().GetResult();

            if (HasAssertionWithException)
            {
                RunExceptionAssertion(results);
            }

            return(FixtureStepResult.Of(Step).Passed());
        }
        catch (Exception exc)
        {
            return(FixtureStepResult.Of(Step).Failed(exc));
        }
    }
Example #3
0
    /// <summary>
    /// Runs an Expect step with the specified results of a fixture step.
    /// </summary>
    /// <param name="results">The results of the fixture step that was completed running.</param>
    /// <returns>The result of the Expect step running.</returns>
    protected override FixtureStepResult.Builder Run(FixtureStepResultCollection results)
    {
        if (IsPending)
        {
            return(FixtureStepResult.Of(Step).Pending());
        }

        if (results.HasExceptionAt <GivenStep>() || results.HasLatestExceptionAt <WhenStep>())
        {
            return(FixtureStepResult.Of(Step).Ready());
        }

        if (results.HasStatusAt <GivenStep>(FixtureStepStatus.Ready) || results.HasStatusAtLatest <WhenStep>(FixtureStepStatus.Ready))
        {
            return(FixtureStepResult.Of(Step).Ready());
        }

        if (results.HasStatusAt <GivenStep>(FixtureStepStatus.Pending) || results.HasStatusAtLatest <WhenStep>(FixtureStepStatus.Pending))
        {
            return(FixtureStepResult.Of(Step).Pending());
        }

        try
        {
            if (Step.Assertion is not null)
            {
                Step.ExecuteAssertion(Step.Assertion);
            }
            Step.Action?.Invoke();
            Step.AsyncAction?.Invoke().GetAwaiter().GetResult();

            return(FixtureStepResult.Of(Step).Passed());
        }
        catch (Exception exc)
        {
            return(FixtureStepResult.Of(Step).Failed(exc));
        }
    }