예제 #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));
        }
    }
예제 #2
0
    /// <summary>
    /// Runs a Given 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 Given step running.</returns>
    /// <exception cref="InvalidFixtureStepException">
    /// The <paramref name="results"/> does not have the <see cref="WhenStep"/> or the <see cref="ThenStep"/>.
    /// </exception>
    protected override FixtureStepResult.Builder Run(FixtureStepResultCollection results)
    {
        if (results.Has(typeof(WhenStep), typeof(ThenStep)))
        {
            throw new InvalidFixtureStepException("Given must be before When or Then");
        }

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

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

        try
        {
            Step.Arrangement?.Invoke();
            Step.AsyncArrangement?.Invoke().GetAwaiter().GetResult();

            return(FixtureStepResult.Of(Step).Passed());
        }
        catch (Exception exc)
        {
            return(FixtureStepResult.Of(Step).Failed(exc));
        }
    }
예제 #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));
        }
    }