Skip to content

Commit dfbd050

Browse files
committed
Merge pull request #159 from JakeGinnivan/NullableEnumIncorrectlyReportedAsNotUsed
Fixes #158
2 parents 570d70c + 97d7c1f commit dfbd050

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

TestStack.BDDfy.Tests/UnusedExampleValueScenario.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,40 @@ public class UnusedExampleValueScenario
1212
[Test]
1313
public void WhenExampleIsNotUsedItThrows()
1414
{
15-
var ex = Should.Throw<UnusedExampleException>(() => this.Given("Foo").WithExamples(new ExampleTable("Example 1") { 1 }).BDDfy());
15+
var ex = Should.Throw<UnusedExampleException>(() =>
16+
this.Given("Foo")
17+
.WithExamples(new ExampleTable("Example 1") { 1 }).BDDfy());
1618

1719
ex.Message.ShouldBe("Example Column 'Example 1' is unused, all examples should be consumed by the test (have you misspelt a field or property?)");
1820
}
21+
22+
[Test]
23+
public void NullableEnumIsUsedProperly()
24+
{
25+
SomeEnum? nullableEnum = null;
26+
string anotherExample = null;
27+
28+
this.Given(_ => GivenANullableEnumExample(nullableEnum))
29+
.Then(_ => AnotherValueIsChanged(anotherExample))
30+
.WithExamples(new ExampleTable("Nullable Enum", "Another Example")
31+
{
32+
{SomeEnum.Value, string.Empty},
33+
{null, string.Empty}
34+
})
35+
.BDDfy();
36+
}
37+
38+
private void AnotherValueIsChanged(string anotherExample)
39+
{
40+
}
41+
42+
private void GivenANullableEnumExample(SomeEnum? nullableEnum)
43+
{
44+
}
45+
46+
public enum SomeEnum
47+
{
48+
Value
49+
}
1950
}
2051
}

TestStack.BDDfy/Scanners/StepScanners/Examples/ExampleValue.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public object GetValue(Type targetType)
3939
var valueAsString = string.IsNullOrEmpty(stringValue) ? "<null>" : string.Format("\"{0}\"", _underlyingValue);
4040
throw new ArgumentException(string.Format("Cannot convert {0} to {1} (Column: '{2}', Row: {3})", valueAsString, targetType.Name, Header, Row));
4141
}
42+
43+
ValueHasBeenUsed = true;
4244
return null;
4345
}
4446

0 commit comments

Comments
 (0)