Skip to content
This repository has been archived by the owner on Oct 21, 2018. It is now read-only.

"Expects" will falsely match on a class which overrides a collection #20

Open
andrewducker opened this issue Jun 10, 2016 · 0 comments
Open

Comments

@andrewducker
Copy link
Contributor

Given a class:

public class ListWithProperty : List<int>
{
    public string MyProperty { get; set; }
}

I can create two different instances, with different properties, set an expectation for the first one, and then pass in the second one and get the response I'd set up.

        var class1 = MockRepository.GenerateMock<IClass1>();
        var expectedList = new ListWithProperty{MyProperty = "A value"};
        class1.Expect(x => x.GetPropertyFromList(expectedList)).Return("Fake Response");

        var actualList = new ListWithProperty { MyProperty = "A completely different value" };
        var response = class1.GetPropertyFromList(actualList);
        Assert.AreEqual("Fake Response",response);

This is due to the line in Validate.cs RecursiveCollectionEqual
if (expected is ICollection)
Which assumes that if an object is a collection and the items in the collection match then the items are the same. Which is not true in this case.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant