How do I test if two dates are within a certain tolerance in NUnit?
You may want to look at the "Within" method that lives off of the Constraint object.
For example:
Assert.That(DateTime.Now, Is.EqualTo(DateTime.Now.AddMilliseconds(1000)).Within(101));
It's usually used to give a tolerance to doubles and floats, but since in the end a DateTime is a double, it might suit your needs.
TimeSpan tolerance = new TimeSpan(0,1,0); // e.g. 1 minute
Assert.IsTrue((firstDateTime-SecondDateTime).Duration() > tolerance);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With