What is the best way to compare all the properties of two objects in which some of them have different formats (for example, DateTime in one and DateTime.ToString() with a custom format in the other)?
I was able to do this using 2 statements:
o1.ShouldHave().AllPropertiesBut(dto1 => dto1.Date).EqualTo(o2); o1.Date.Should().Be(DateTime.Parse(o2.Date));
I would think of the following, but this will not compile, because EqualTo<T>() not valid.
o1.ShouldHave().AllProperties().But(d => d.Date).EqualTo(o2) .And.Date.Should().Be((DateTime.Parse(o2.Date));
:
public class Dto1 { public int ID { get { return 1; } } public DateTime Date { get { return DateTime.Now.Date; } } } public class Dto2 { public int ID { get { return 1; } } public string Date { get { return DateTime.Now.Date.ToShortDateString(); } } } var o1 = new Dto1(); var o2 = new Dto2();
source share