c# - Fluent Assertions - Overriding comparison in ShouldBeEquivalentTo() -
i have following dto:
public class dto { public datetime date { get; set; } }
and i'm trying override comparison of property using syntax per fa wiki:
public void override_test() { // arrange var actual = new dto { date = datetime.now }; var expected = new dto { date = datetime.now }; // act // assert actual.shouldbeequivalentto(expected, options => options.using<datetime>(x => x.subject.should().becloseto(datetime.now))); }
but test not compile. error:
cannot implicitly convert type 'fluentassertions.equivalency.equivalencyassertionoptions<fluentassertions.shouldbeequivalentto.override.dto>.restriction<system.datetime>' 'fluentassertions.equivalency.equivalencyassertionoptions<fluentassertions.shouldbeequivalentto.override.dto>'
can advise correct syntax?
you have tell fa when use using
construction using whentypeis<datetime>()
. in other words:
actual.shouldbeequivalentto(expected, options => options.using<datetime>(x => x.subject.should().becloseto(datetime.now)).whentypeis<datetime>());
however, suggest not rely on datetime.now
much. instead, consider using ayende rahien has proposed in this article.
Comments
Post a Comment