I'm processing a number of items, each of which contain a DateProcessed property (a nullable DateTime) and want to Assert that the property is set to the current date. By the time it gets through the processing routine the dates are all slightly different.
I want to Test that all the DateProcessed properties have a relativity (100ms) recent DateTime.
Fluent Assertions has the .BeCloseTo method which works perfectly for a single item. But I want to use that for the entire collection. But it's not available via the Contains() when looking at a collection.
A simplified example ...
[TestFixture]
public class when_I_process_the_items
{
[SetUp]
public void context()
{
items = new List<DateTime?>(new [] { (DateTime?)DateTime.Now, DateTime.Now, DateTime.Now } );
}
public List<DateTime?> items;
[Test]
public void then_first_item_must_be_set_to_the_current_time()
{
items.First().Should().BeCloseTo(DateTime.Now, precision: 100);
}
[Test]
public void then_all_items_must_be_set_to_the_current_time()
{
items.Should().Contain .... //Not sure? :(
}
}