Ryan Betker - healthNCode Ryan Betker - healthNCode - 1 year ago 132
C# Question

NUnit Assert.AreEqual double vars with delta parameter - compiler thinks I want int compares

A compare against the ticks of 2 different dates with a delta param and error message isn't compiling, and looks like it's thinking I'm after a different overloaded method. I've also tried without an error msg, and similar: expected int, int, string problem.

Assert.AreEqual((double)data.LastModified.Ticks, (double)DateTime.UtcNow.Ticks, 300000000M, "Last modified wasn't set");

I would use overload #9 or #16 (with error message), yet the compiler thinks I want the
int, int, string, object

Any ideas?

Answer Source

I am not clear what is "data" in your example here but here is how I will compare ticks.

DateTime data= new DateTime(2014,12,23);
DateTime data2 = new DateTime(2014, 12, 24);
Assert.AreEqual((double)data.Ticks,(double)data.Ticks,(double)3000M, "msg 1");
Assert.AreEqual((double)DateTime.Today.Ticks,(double)DateTime.UtcNow.Ticks, (double)300000M, "msg 2")