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
3 changes: 2 additions & 1 deletion Source/aweXpect/That/Enums/ThatNullableEnum.HasValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ private sealed class HasValueConstraint<TEnum>(string it, ExpectationGrammars gr
public ConstraintResult IsMetBy(TEnum? actual)
{
Actual = actual;
Outcome = Convert.ToInt64(actual, CultureInfo.InvariantCulture) == expectedValue
Outcome = actual is not null &&
Convert.ToInt64(actual.Value, CultureInfo.InvariantCulture) == expectedValue
? Outcome.Success
: Outcome.Failure;
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ Expected that subject
""");
}

[Fact]
public async Task WhenSubjectIsNull_ShouldSucceed()
[Theory]
[InlineData(null)]
[InlineData(0L)]
[InlineData(2L)]
public async Task WhenSubjectIsNull_ShouldSucceed(long? unexpected)
{
MyColors? subject = null;

async Task Act()
=> await That(subject).DoesNotHaveValue(2);
=> await That(subject).DoesNotHaveValue(unexpected);

await That(Act).DoesNotThrow();
}
Expand Down
19 changes: 11 additions & 8 deletions Tests/aweXpect.Tests/Enums/ThatEnum.Nullable.HasValue.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,23 @@ async Task Act()
await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
[Theory]
[InlineData(null)]
[InlineData(0L)]
[InlineData(1L)]
public async Task WhenSubjectIsNull_ShouldFail(long? expected)
{
MyNumbers? subject = null;

async Task Act()
=> await That(subject).HasValue(1L);
=> await That(subject).HasValue(expected);

await That(Act).Throws<XunitException>()
.WithMessage("""
Expected that subject
has value 1,
but it was <null>
""");
.WithMessage($"""
Expected that subject
has value {Formatter.Format(expected)},
but it was <null>
""");
}
}
}
Expand Down
Loading