Skip to content

Commit

Permalink
Add matching of VSTest _Variant results.
Browse files Browse the repository at this point in the history
Implements the VsTestScenarioOutlineExampleMatcher to detect _Variant style examples.
These occur when there are examples which contain characters that are illegal for method names,
or when examples contain duplicate values in the first column.

Fixes #507
  • Loading branch information
jvandertil committed May 23, 2018
1 parent 4519e56 commit 854ef80
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
// --------------------------------------------------------------------------------------------------------------------


using System.Collections.Generic;
using NFluent;


Expand Down Expand Up @@ -136,7 +137,30 @@ public void ThenCanReadExamplesWithRegexValuesFromScenarioOutline_ShouldBeTestRe

var feature = new Feature { Name = "Scenarios With Special Characters" };

var scenarioOutline = new ScenarioOutline { Name = "This scenario contains examples with Regex-special characters", Feature = feature };
var scenarioOutline = new ScenarioOutline
{
Name = "This scenario contains examples with Regex-special characters",
Feature = feature,
Examples = new List<Example>
{
new Example
{
TableArgument = new ExampleTable
{
DataRows = new List<TableRow>
{
new TableRow("**"),
new TableRow("++"),
new TableRow(".*"),
new TableRow("[]"),
new TableRow("{}"),
new TableRow("()"),
new TableRow(@"^.*(?<foo>BAR)\s[^0-9]{3,4}A+$"),
}
}
}
}
};

TestResult exampleResultOutline = results.GetScenarioOutlineResult(scenarioOutline);
Check.That(exampleResultOutline).IsEqualTo(TestResult.Passed);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ public WhenParsingVsTestResultsFileWithIndividualResults()
base.ThenCanReadIndividualResultsFromScenarioOutline_MultipleExampleSections_ShouldBeTestResultFailed();
}

[Test]
public new void ThenCanReadExamplesWithRegexValuesFromScenarioOutline_ShouldBeTestResultPassed()
{
base.ThenCanReadExamplesWithRegexValuesFromScenarioOutline_ShouldBeTestResultPassed();
}

[Test]
public new void ThenCanReadExamplesWithLongExampleValues()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.Linq;
using System.Text.RegularExpressions;
using System.Xml.Linq;

using PicklesDoc.Pickles.ObjectModel;
Expand All @@ -26,6 +28,9 @@ namespace PicklesDoc.Pickles.TestFrameworks.VsTest
{
public class VsTestScenarioOutlineExampleMatcher : IScenarioOutlineExampleMatcher
{
private static readonly Regex VariantRegex = new Regex(@"(.*)_Variant([\d*])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private const int VariantNumberGroup = 2;

public bool IsMatch(ScenarioOutline scenarioOutline, string[] exampleValues, object scenarioElement)
{
var element = (XElement)scenarioElement;
Expand All @@ -51,7 +56,23 @@ public bool IsMatch(ScenarioOutline scenarioOutline, string[] exampleValues, obj
.Replace('Ø', 'O')
.Replace('Å', 'A');

var isMatch = element.Name().ToUpperInvariant()
var variantMatch = VariantRegex.Match(element.Name().ToUpperInvariant());
if (variantMatch.Success)
{
int variantNumber;
if (int.TryParse(variantMatch.Groups[VariantNumberGroup].Value, out variantNumber))
{
if (scenarioOutline.Examples?.Count > 0)
{
var allExamples = scenarioOutline.Examples.SelectMany(x => x.TableArgument.DataRows);
var example = allExamples.ElementAt(variantNumber);

return example.Cells.SequenceEqual(exampleValues);
}
}
}

var isMatch = element.Name().ToUpperInvariant()
.EndsWith(matchValue);

return isMatch;
Expand Down

0 comments on commit 854ef80

Please sign in to comment.