I have a unit test using FluentAssertion resembling this:
var instance = new ServiceInstance(name, "1.0.0", new Uri("http://www.google.com"));
var id = registry.RegisterInstance(instance);
registry.ExistsInstance(id).Should().BeTrue();
var queryiedInstance = registry.QueryForInstance(id);
queryiedInstance.ShouldBeEquivalentTo(instance);
That latest assertion fails with the following message:
Result Message:
Expected member RegistrationData.RegistrationTime to be <2015-10-13 08:36:20.619>, but found <2015-10-13 08:36:20.619>.
Expected member RegistrationData.LastActivationTime to be <2015-10-13 08:36:20.619>, but found <2015-10-13 08:36:20.619>.
Expected member RegistrationData.LastPinged to be <2015-10-13 08:36:20.619>, but found <2015-10-13 08:36:20.619>.
As you can see, FluentAssertion reports identical datetimes but nevertheless fails.
In that specific case, my registry backend is MongoDB that I access through the latest C# driver. However, it can use other backends (Zookeeper or Consul, for example) for which that specific assertion doesn't fail.
So my guess is that the problem comes from the Mongo C# driver and not from FluentAssertion. I've played a bit with DateTime serialization options in Mongo,(I use UTC everywhere and it seems that's the default for Mongo as well), but without being successful. Any idea of what could be wrong?
Thanks for your help.
I suspect the ticks of those two DateTime
instances differ. If that's true, you can work around this by using the specific DateTime
assertions BeCloseTo
.