I'm not sure what happened, but in FluentAssertions 2.0.1, this code sample worked fine and it stopped working in 2.1.0. I simplified as much as I could to reproduce the issue and it seems confined to use NodaTime's (version 1.1) LocalTime objects.
I have a ZIP file with the solution but GitHub won't let me attach it, so I'll just paste in the code here:
public NestedClass(IsoDayOfWeek dayOfWeek,
LocalTime start,
LocalTime end)
{
Start = start;
End = end;
DayOfWeek = dayOfWeek;
}
}
public class Class1
{
public string Name { get; set; }
public IEnumerable<NestedClass> Nested { get; set; }
public Class1(string name,
IEnumerable<NestedClass> nested)
{
Name = name;
Nested = nested;
}
}
[TestFixture]
public class SomeTest1
{
private static readonly LocalTime Midnight = new LocalTime(hour: 0,
minute: 0);
private static readonly LocalTime JustBeforeMidnight = new LocalTime(hour: 23,
minute: 59,
second: 59);
#region Utility Methods
private static IEnumerable<NestedClass> GetNestedObjects()
{
for (var index = 0; index <= 7; index++)
{
var day = (IsoDayOfWeek) index;
// skip monday or none
if (day == IsoDayOfWeek.Monday || day == IsoDayOfWeek.None)
{
continue;
}
var obj = new NestedClass(day,
new LocalTime(hour: 0,
minute: 0),
new LocalTime(hour: 23,
minute: 59,
second: 59));
yield return obj;
}
}
#endregion
#region Tests
[Test]
public void Fails_properly()
{
var actual = new NestedClass(IsoDayOfWeek.Thursday,
new LocalTime(hour: 0,
minute: 0),
new LocalTime(hour: 23,
minute: 59,
second: 59));
var expected = new NestedClass(IsoDayOfWeek.Thursday,
Midnight,
new LocalTime(20,
59,
59));
actual
.Should()
.Be(expected);
}
[Test]
public void Replicate_problem_without_collection_hangs()
{
// arrange
var actual = new NestedClass(IsoDayOfWeek.Thursday,
new LocalTime(hour: 0,
minute: 0),
new LocalTime(hour: 23,
minute: 59,
second: 59));
var expected = new NestedClass(IsoDayOfWeek.Thursday,
Midnight,
new LocalTime(20,
59,
59));
// this should fail but instead it hangs
actual.ShouldBeEquivalentTo(expected);
}
[Test]
public void ReplicateProblem_WithoutCollection_Passes()
{
// arrange
var actual = new NestedClass(IsoDayOfWeek.Thursday,
new LocalTime(hour: 0,
minute: 0),
new LocalTime(hour: 23,
minute: 59,
second: 59));
var expected = new NestedClass(IsoDayOfWeek.Thursday,
Midnight,
JustBeforeMidnight);
actual.ShouldBeEquivalentTo(expected);
}
[Test]
public void Replicate_problem_with_collection_hangs()
{
// arrange
var nested = GetNestedObjects();
var obj = new Class1("the class",
nested);
// act
var result = obj.Nested;
// assert
var expectedResult = new[]
{
new NestedClass(IsoDayOfWeek.Sunday,
Midnight,
JustBeforeMidnight),
new NestedClass(IsoDayOfWeek.Tuesday,
Midnight,
JustBeforeMidnight),
new NestedClass(IsoDayOfWeek.Wednesday,
Midnight,
JustBeforeMidnight),
new NestedClass(IsoDayOfWeek.Thursday,
Midnight,
new LocalTime(20,59,59)),
new NestedClass(IsoDayOfWeek.Friday,
Midnight,
JustBeforeMidnight),
new NestedClass(IsoDayOfWeek.Saturday,
Midnight,
JustBeforeMidnight),
};
// hangs
result
.ShouldBeEquivalentTo(expectedResult);
}
#endregion
}