Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System.Reflection;
using Shouldly;
using Xunit;

namespace TestStack.BDDfy.Tests.Scanner.FluentScanner
{
public class AmbiguousHeaderMatchTests
{
private int _count;

Check warning on line 9 in src/TestStack.BDDfy.Tests/Scanner/FluentScanner/AmbiguousHeaderMatchTests.cs

View workflow job for this annotation

GitHub Actions / build

Field 'AmbiguousHeaderMatchTests._count' is never assigned to, and will always have its default value 0

Check warning on line 9 in src/TestStack.BDDfy.Tests/Scanner/FluentScanner/AmbiguousHeaderMatchTests.cs

View workflow job for this annotation

GitHub Actions / build

Field 'AmbiguousHeaderMatchTests._count' is never assigned to, and will always have its default value 0

Check warning on line 9 in src/TestStack.BDDfy.Tests/Scanner/FluentScanner/AmbiguousHeaderMatchTests.cs

View workflow job for this annotation

GitHub Actions / build

Field 'AmbiguousHeaderMatchTests._count' is never assigned to, and will always have its default value 0

Check warning on line 9 in src/TestStack.BDDfy.Tests/Scanner/FluentScanner/AmbiguousHeaderMatchTests.cs

View workflow job for this annotation

GitHub Actions / build

Field 'AmbiguousHeaderMatchTests._count' is never assigned to, and will always have its default value 0

[Fact]
public void ThrowsWhenMultipleHeadersMatchParameterName()
{
// Act & Assert
var exception = Should.Throw<AmbiguousMatchException>(() =>
{
this.Given(_ => GivenInput(_count)) // Will try to bind _count to both "count" and "Count" headers
.WithExamples(new ExampleTable("count", "Count") // Deliberately ambiguous headers
{
{ 5, 10 }
})
.BDDfy();
});

exception.Message.ShouldBe("More than one headers for examples, match the parameter 'count' provided for 'GivenInput'");
}

private void GivenInput(int count)
{
// The method exists just to trigger the ambiguous header match
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,15 @@ private StepTitle CreateTitle(string stepTextTemplate, bool includeInputsInStepT
{
if (_testContext.Examples != null)
{
var matchingHeader = _testContext.Examples.Headers
.SingleOrDefault(header => ExampleTable.HeaderMatches(header, i.ParameterName) ||
ExampleTable.HeaderMatches(header, i.Value.Name));
var matchingHeaders = _testContext.Examples.Headers
.Where(header => ExampleTable.HeaderMatches(header, i.ParameterName) ||
ExampleTable.HeaderMatches(header, i.Value.Name))
.ToList();

if (matchingHeaders.Count > 1)
throw new AmbiguousMatchException ($"More than one headers for examples, match the parameter '{i.ParameterName}' provided for '{methodInfo.Name}'");

var matchingHeader = matchingHeaders.SingleOrDefault();
if (matchingHeader != null)
return string.Format("<{0}>", matchingHeader);
}
Expand Down