I have this object from an external library that implements IEnumerable<T>
. I just want to check the properties of this object and not the equivalence of the collection. I'm not interested in the stuff inside the IEnumerable
. How can I exclude this from the assertion?
public class Example : IEnumerable<string>
{
public string Id { get; set; }
public string Name { get; set; }
public IEnumerator<string> GetEnumerator() => new List<string> { Id }.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
This is the test, which will fail on the IEnumerable
.
(new Example {Id = "123", Name= "Test" } as object)
.Should().BeEquivalentTo(new Example{Name = "Test"},
o => o.Excluding(p => p.Id));
Doing this before the test this will work, but then I lose the ability to check any IEnumerable
property on the class:
AssertionOptions.EquivalencyPlan.Remove<GenericEnumerableEquivalencyStep>();
AssertionOptions.EquivalencyPlan.Remove<EnumerableEquivalencyStep>();