示例#1
0
 public BackgroundBuilder(IGherkinBlock item)
 {
     this.result = new FixtureBackground(FixtureStep.Create(GherkinKeyword.Background, item.Name));
     this.result.AddComments(item.Gherkin);
     this.result.AddChild(Steps(GherkinStep.Given, item));
     this.result.AddChild(Steps(GherkinStep.When, item));
 }
示例#2
0
    private string CreateStackTrace(FixtureStep step)
    {
        var getResourceStringMethod = typeof(Environment).GetTypeInfo().DeclaredMethods.FirstOrDefault(m => m.Name == "GetResourceString");
        var at = getResourceStringMethod?.Invoke(null, new object[] { "Word_At" }) as string ?? string.Empty;
        var inFileLineNumber = getResourceStringMethod?.Invoke(null, new object[] { "StackTrace_InFileLineNumber" }) as string ?? string.Empty;

        return($"   {at} {step.CallerType}.{step.CallerMemberName} {string.Format(inFileLineNumber, step.CallerFilePath, step.CallerLineNumber)}");
    }
示例#3
0
 private FixtureStepRunningResultAssertion(FixtureStep step, bool startTimeHasValue, bool endTimeHasValue, bool durationHasValue, Exception?exception, FixtureStepStatus status)
 {
     Step = step;
     StartTimeHasValue = startTimeHasValue;
     EndTimeHasValue   = endTimeHasValue;
     DurationHasValue  = durationHasValue;
     Exception         = exception;
     Status            = status;
 }
示例#4
0
    /// <summary>
    /// Creates a new instance that runs the specified fixture step.
    /// </summary>
    /// <param name="step">The fixture step to run.</param>
    /// <returns>The new instance that runs the specified fixture step.</returns>
    /// <exception cref="FixtureStepRunnerNotFoundException">
    /// The fixture step runner instance that implements the <see cref="IFixtureStepRunner"/> is not found.
    /// </exception>
    protected virtual IFixtureStepRunner Create(FixtureStep step)
    {
        if (!stepRunnerTypes.TryGetValue(step.GetType(), out var stepRunnerType))
        {
            throw new FixtureStepRunnerNotFoundException(step.GetType());
        }

        return(Activator.CreateInstance(stepRunnerType, step) as IFixtureStepRunner ?? throw new FixtureStepRunnerNotFoundException(step.GetType()));
    }
示例#5
0
        public FixtureBuilder(IGherkinFeature gherkin, ISpockOptions options)
        {
            this.gherkin           = gherkin;
            this.options           = options;
            this.fixtureInvariants = new FixtureInvariants(gherkin, options);

            var summary = new List <string>
            {
                "Feature Id: " + this.fixtureInvariants.FeatureId,
                gherkin.Name,
                gherkin.Description
            };

            if (gherkin.Background != null)
            {
                summary.AddRange(gherkin.Background.Gherkin);
            }

            var disabled = gherkin.Comments.DisabledScenarios("<item>", "</item>").ToArray();

            if (disabled.Any())
            {
                const string header =
                    "The following Scenario Ids (Test Step Id's) have been disabled from this fixture. Please review " +
                    "the original test cases XML file to see if the test scenario was valid, and if " +
                    "so, update the Gherkin .feature file to reflect the test case. Then regenerate " +
                    "this test fixture to include the new scenario.";

                var builder = new StringBuilder();
                builder.Append(header);
                builder.Append("<list type=\"bullet\">");
                foreach (var d in disabled)
                {
                    builder.Append(d);
                }

                builder.Append("</list>");
                summary.Add(builder.ToString());
            }

            this.comments.AddRange(CodeGeneration.ToXmlSummary(summary.ToArray(), false));
            this.comments.AddRange(CodeGeneration.ToXmlRemarks(gherkin.Gherkin, new[] { "example", "code language=\"none\" title=\"Gherkin\"" }));
            this.feature = FixtureStep.Create(GherkinKeyword.Feature, gherkin.Description);
            if (gherkin.Background == null)
            {
                return;
            }

            this.background = new BackgroundBuilder(gherkin.Background).Build();
            this.feature.AddBackground(this.background);
        }
示例#6
0
    private static void ExecuteAssertion(this FixtureStep @this, LambdaExpression expression, Func <bool> assertion, Exception?exception = null)
    {
        bool result;

        try
        {
            result = assertion();
        }
        catch (Exception exc)
        {
            throw new AssertionException(@this, exc);
        }

        if (!result)
        {
            throw new AssertionException(@this, AssertionDescription.Of(expression, exception));
        }
    }
示例#7
0
        public static IFixtureStep Steps(GherkinStep step, IGherkinBlock item)
        {
            var parent = item.Steps[step];

            if (parent == null)
            {
                return(null);
            }

            var result = FixtureStep.Create(parent);

            foreach (var child in item.Steps.Parent(parent.Step.Syntax.Block()))
            {
                result.AddChild(FixtureStep.Create(child));
            }

            return(result);
        }
示例#8
0
 /// <summary>
 /// Creates a new instance of the <see cref="Builder"/> class
 /// with the specified a fixture step.
 /// </summary>
 /// <param name="step">The fixture step.</param>
 /// <returns>
 /// The new instance of the <see cref="Builder"/> class.
 /// </returns>
 public static Builder Of(FixtureStep step) => new(step);
示例#9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssertionException"/> class
 /// with the specified fixture step and exception that was thrown when the assertion was failed.
 /// </summary>
 /// <param name="step">The fixture step when the assertion was failed.</param>
 /// <param name="cause">The exception that was thrown when the assertion was failed.</param>
 public AssertionException(FixtureStep step, Exception?cause) : base(cause?.Message)
 {
     StackTrace = $"{cause?.StackTrace}{Environment.NewLine}{CreateStackTrace(step)}";
     Cause      = cause;
 }
示例#10
0
 public static FixtureStepRunningResultAssertion Of(FixtureStep step, bool startTimeHasValue, bool endTimeHasValue, bool durationHasValue, Exception?exception, FixtureStepStatus status) => new(step, startTimeHasValue, endTimeHasValue, durationHasValue, exception, status);
示例#11
0
 public SimpleFixtureStepRunner(FixtureStep step)
 {
     Step = step;
 }
示例#12
0
 /// <summary>
 /// Executes the specified assertion with the specified exception that is a parameter of the assertion.
 /// </summary>
 /// <param name="this">The fixture step that runs the assertion.</param>
 /// <param name="assertion">The assertion to run.</param>
 /// <param name="exception">The exception that is a parameter of the assertion.</param>
 public static void ExecuteAssertion(this FixtureStep @this, Expression <Func <Exception, bool> > assertion, Exception exception)
 {
     @this.ExecuteAssertion(assertion, () => assertion.Compile()(exception), exception);
 }
示例#13
0
 public IFixtureStepRunner Create(FixtureStep step)
 {
     return(new SimpleFixtureStepRunner(step));
 }
 public static FixtureStepResultAssertion ForNullException(FixtureStepStatus status, FixtureStep step) => new(status, new EqualAssertionProperty <Exception?>(null), step);
 private FixtureStepResultAssertion(FixtureStepStatus status, AssertionProperty <Exception?> exception, FixtureStep step)
 {
     Status    = status;
     Exception = exception;
     Step      = step;
 }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssertionException"/> class
 /// with the specified fixture step and assertion description.
 /// </summary>
 /// <param name="step">The fixture step when the assertion was failed.</param>
 /// <param name="description">The assertion description when the assertion was failed.</param>
 public AssertionException(FixtureStep step, AssertionDescription description) : base($"{step.Description}{Environment.NewLine}{description}")
 {
     StackTrace = CreateStackTrace(step);
 }
示例#17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Builder"/> class
 /// with the specified fixture step.
 /// </summary>
 /// <param name="step">The fixture step.</param>
 public Builder(FixtureStep step)
 {
     Step = step;
 }