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
 public ThenStepRunnerSpec_StepRunningWithoutException()
 {
     StepResults = new FixtureStepResultCollection
     {
         FixtureStepResult.Of(FixtureSteps.CreateWhenStep()).Passed().Build()
     };
 }
Example #3
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));
        }
    }
 public ThenStepRunnerSpec_StepRunningWithTypedException()
 {
     StepResults = new FixtureStepResultCollection
     {
         FixtureStepResult.Of(FixtureSteps.CreateWhenStep()).Failed(new ArgumentNullException()).Build()
     };
 }
Example #5
0
 public ThenStepRunnerSpec_StepRunningWithExceptionAsync()
 {
     StepResults = new FixtureStepResultCollection
     {
         FixtureStepResult.Of(FixtureSteps.CreateWhenStep()).Failed(AssertedException).Build()
     };
 }
Example #6
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 #7
0
    private void RunExceptionAssertion(FixtureStepResultCollection results)
    {
        Exception?exception;
        var       lastStep = results.Last().Step;

        if (lastStep is ThenStep lastThenStep)
        {
            exception = lastThenStep.AssertedException;
        }
        else
        {
            exception = results.GetLatestExceptionAt <WhenStep>();
            if (exception is not null)
            {
                results.ClearException(exception);
            }
        }

        Step.AssertedException = exception;
        if (Step.ExceptionType is not null)
        {
            if (exception is null)
            {
                Step.ExecuteAssertion(() => null == Step.ExceptionType);
            }
            else
            {
                Step.ExecuteAssertion(() => exception.GetType() == Step.ExceptionType);
            }
        }
        if (exception is null)
        {
            return;
        }

        if (Step.ExceptionAssertion is not null)
        {
            Step.ExecuteAssertion(Step.ExceptionAssertion, exception);
        }
        Step.ExceptionAction?.Invoke(exception);
        Step.AsyncExceptionAction?.Invoke(exception).GetAwaiter().GetResult();
    }
Example #8
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));
        }
    }
 public GivenStepRunnerSpec_StepRunning()
 {
     StepResults = new FixtureStepResultCollection();
 }
Example #10
0
 public FixtureStepResultCollectionSpec()
 {
     Results = new FixtureStepResultCollection();
 }
Example #11
0
 public ExpectStepRunnerSpec_Constrains()
 {
     StepResults = new FixtureStepResultCollection();
 }
Example #12
0
 public NoteStepRunnerSpec()
 {
     StepResults = new FixtureStepResultCollection();
 }
Example #13
0
 FixtureStepResult.Builder IFixtureStepRunner.Run(FixtureStepResultCollection results) => Run(results);
Example #14
0
 /// <summary>
 /// Runs a fixture 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 fixture step running.</returns>
 protected abstract FixtureStepResult.Builder Run(FixtureStepResultCollection results);
Example #15
0
 public FixtureStepResult.Builder Run(FixtureStepResultCollection results)
 {
     return(FixtureStepResult.Of(Step).Passed());
 }
Example #16
0
 public WhenStepRunnerSpec_StepRunningAsync()
 {
     StepResults = new FixtureStepResultCollection();
 }
 public WhenStepRunnerSpec_StepRunningWithTimeout()
 {
     StepResults = new FixtureStepResultCollection();
 }
Example #18
0
 /// <summary>
 /// Runs a Note 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 Note step running.</returns>
 protected override FixtureStepResult.Builder Run(FixtureStepResultCollection results)
 => FixtureStepResult.Of(Step).None();