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

Add support for named fakes #1488

Closed
thomaslevesque opened this issue Nov 6, 2018 · 4 comments
Closed

Add support for named fakes #1488

thomaslevesque opened this issue Nov 6, 2018 · 4 comments

Comments

@thomaslevesque
Copy link
Member

I just found myself in a situation where I have a collection of fakes, and an assertion fails on one of the fakes, but I don't know which. It would be handy to be able to name fakes, e.g. something like this:

var foo1 = A.Fake<IFoo>(options => options.Named("foo1"));
var foo2 = A.Fake<IFoo>(options => options.Named("foo2"));

Then we could have an assertion failure message like this:

Assertion failed for the following call on <foo1>:
  Blah.IFoo.Bar()
Expected to find it once or more but no calls were made to the fake object.

The name could also be used for arguments in calls list. (e.g. Blah.IFoo.Bar(<baz>)).

For A.CollectionOfFake<T>, we might need to introduce an additional overload that takes the index into account:

var foos = A.CollectionOfFake<IFoo>(10, (options, index) => options.Named("foo" + index));
@blairconrad
Copy link
Member

I'm super curious about this. For the collection, I can see it happening. I would like to know how it happened to you without using a collection.

@thomaslevesque
Copy link
Member Author

I would like to know how it happened to you without using a collection.

I had a collection; I just didn't create it with A.CollectionOfFake<T>.

@blairconrad
Copy link
Member

thomaslevesque added this to the vNext milestone an hour ago

Thanks. I'd accidentally added the PR and fixed that, but forgot to readd this!

@blairconrad
Copy link
Member

This change has been released as part of FakeItEasy 5.1.0.

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