Skip to content

Commit

Permalink
Add missing test for null subject inside an assertion scope
Browse files Browse the repository at this point in the history
  • Loading branch information
IT-VBFK committed Nov 24, 2022
1 parent 347b42e commit 8035ef1
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Tests/FluentAssertions.Specs/Primitives/TimeOnlyAssertionSpecs.cs
@@ -1,5 +1,6 @@
using System;
using FluentAssertions.Extensions;
using FluentAssertions.Execution;
using Xunit;
using Xunit.Sdk;

Expand Down Expand Up @@ -352,6 +353,25 @@ public void When_subject_nulltime_is_close_to_another_it_should_throw()
act.Should().Throw<XunitException>()
.WithMessage("Expected*, but found <null>.");
}

[Fact]
public void A_null_time_inside_an_assertion_scope_fails()
{
// Arrange
TimeOnly? time = null;
TimeOnly nearbyTime = new TimeOnly(12, 15, 31);

// Act
Action act = () =>
{
using var _ = new AssertionScope();
time.Should().BeCloseTo(nearbyTime, 35.Milliseconds());
};

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Expected*, but found <null>.");
}
}

public class NotBeCloseTo
Expand All @@ -371,6 +391,25 @@ public void A_null_time_is_never_unclose_to_an_other_time()
.WithMessage("Did not expect*, but found <null>.");
}

[Fact]
public void A_null_time_inside_an_assertion_scope_is_never_unclose_to_an_other_time()
{
// Arrange
TimeOnly? time = null;
TimeOnly nearbyTime = new TimeOnly(12, 15, 31);

// Act
Action act = () =>
{
using var _ = new AssertionScope();
time.Should().NotBeCloseTo(nearbyTime, 35.Milliseconds());
};

// Assert
act.Should().Throw<XunitException>()
.WithMessage("Did not expect*, but found <null>.");
}

[Fact]
public void When_time_is_not_close_to_a_negative_precision_it_should_throw()
{
Expand Down

0 comments on commit 8035ef1

Please sign in to comment.