-
Notifications
You must be signed in to change notification settings - Fork 340
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
Allow registration of customizer that is invoked after an anonymous instance as been created #96
Comments
Perhaps an approach similar to the one described in this post could work.. |
Can you solve it by applying the |
@ploeh I don't see how. In fact, that attribute already is applied to the parameter of my unit test. |
To answer my question about telling AutoFixture to never set a certain property when creating an instance of a certain class: That's already possible:
|
OK. Then I don't understand what the question is about... From your OP it looks like you want to configure the Test Double. |
@ploeh I don't want to configure a specific test double. That would mean, I would have to do it again in every unit test. |
You may implement a custom |
@moodmosaic Thanks for the suggestion but that's not really a solution, is it? That would mean that |
Wouldn't it be possible to use NSubstitute and setup the stub? (e.g. Moq has a method |
@moodmosaic : As far as I know, there is no such possibility. But I don't think that's the correct way anyway. This wouldn't work as soon as the configuration I want to register is for a concrete type instead of an interface. |
Isn't there some hook that simply receives the created object? |
@dhilgarth The impl of DisposableTracker might be interesting wrt that (related: http://stackoverflow.com/a/11657881/11635 ) |
AutoFixture is nothing but hooks. IIRC you built the NSubstitute Auto-Mocking extensions yourself. That's where your 'hook' is :) Put a Postprocessor or similar around the ISpecimenBuilder you have there. |
@ploeh I have the feeling I am a bit misunderstood here. I don't want to put a Postprocessor around a specific, hardcoded builder as you do in your @bartelink Looking into it, thanks. |
@bartelink I think I found what I need: A |
OK, this is what I came up with: Usage:
Implemented via the following:
Looks very nice to me. Any comments? |
👍 |
@dhilgarth Nice! In my use case, I was using 'typeof.IsAssignableFrom' as my type matching specification so nice to let that bubble up - I could use PostprocessorBehavior as-is though I'd use a different extension method. As it happens, I only used it once and that case (AutoMoqing ASP.NET MVC IController) is better handled by the @moodmosaic trickery here: http://stackoverflow.com/a/14989866/11635 so I personally would let the dust settle before making this an actual Issue for packaged into Core I've added a backlink to the cited CodePlex discussion pointing here. |
It just occurred to me: fixture.Customize<IFoo>(c => c.Do(x => x.Bar().Returns(42))); |
I looks very similar - I think it'd do the same :) |
Just wondering why nobody brought this up in this thread :-) Anyway, I performed some tests. The semantics are a bit different. fixture.Customize<Foo>(c => c.Do(x => x.Property = 9)); Please disregard that I could use I wrote this mainly for documentation purposes, in case someone else sees the last two comments about However, I wonder if it is intended that |
Thanks for the write-up; that all sounds correct to me. Off the top of my head, I don't think there's any particular reason that the |
In the context of the auto mocking feature, I currently am trying to achieve the following:
After AutoFixture created the anonymous instance using NSubstitute I want to automatically configure the substitute.
Example:
Is this already possible? If not, is this something you would find valuable, too?
The text was updated successfully, but these errors were encountered: