Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fakes should return real List implementations for .NET list types instead of a fake that is empty #23

Closed
philippdolder opened this issue Sep 10, 2012 · 4 comments

Comments

@philippdolder
Copy link
Member

No description provided.

@patrik-hagne
Copy link
Member

Not sure I understand this one, an example?

@philippdolder
Copy link
Member Author

assuming:
public interface IInterface
{
IList Items { get; }
}

The following:
var fake = A.Fake();
fake.Items.Add("item");
should lead to fake.Items containing "item".

The thing I am not sure about is if this would be a breaking change. I think it is not.

If it makes sense to you I will implement it

@patrik-hagne
Copy link
Member

It would be a breaking change and to me it would be unsuspected behaviour. Consider this:

var fake = A.Fake<IInterface>();
A.CallTo(() => fake.Items.Add(A._)).Throws(new Exception());

That wouldn't be possible if we did return a list.

I can't think of a real use case where this is beneficial. That something is exposed as IList<T> does in no way imply that the List<T> will be used. The behaviour of the Add-method may very well vary between implementors.

Maybe I'm missing a use case here?

@philippdolder
Copy link
Member Author

That's true, that's a breaking change for that case.
I didn't have your example in any case yet.

The style I do TDD I would never have such a setup that's why I didn't have your use case in mind.

While thinking about it I come to the same conclusion. The things I had in mind are no real world use cases I would have. If any pop up again, I will rethink it and come up with a solution that has no breaking changes.

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

No branches or pull requests

2 participants