1

kind of new to autofixture. I am trying it out on a mvc web api controller. I have the dependencies being filled by the container (structuremap) as I step through I see the constructor of the apicontroller run and exit then I hit my ContainerSpecimenBuilder ( where structuremap provides instances ) and it's looking for the HttpContent which of course I don't have in my container. I've never even heard of HttpContent before. I'm thinking that i'll just put a filter on the ContainerSpecBuilder. That seems a bit like a hack but it's all I got right now.

EDIT

So I put a filter on my ContainerSpecBuilder if !type.IsInterface ( since I really only ever inject interfaces ) and it fell through but I get the same error except that it says autofixture can't create an HttpContent.

EDIT again

Ok so I created a FakeHttpContentSpecBuilder and that has gotten me past that problem but now i'm getting all sorts of grief from other aspects of the apicontroller. First the IDependencyResolver, now the IHttpRouteData. It seems to me that either my container is not working (although it's setup exactly the same as production) or there is a lot more to having autofixture create an instance of an ApiController than I expected.

I will keep adding my experience here and if anyone is interested in my solutions (hacks) than let me know and I will post them.

And Edit again

So I removed a bunch of classes that I had here and put them all ( a little bit more concisely ) in a GIST here.

the error I get is

StructureMap.StructureMapException: StructureMap Exception Code: 202 No Default Instance defined for PluginFamily System.Web.Http.Dependencies.IDependencyResolver, System.Web.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

which essentially means that SM can't find an IDependency in it's container. However, this code actually runs just fine outside of this test so I find that to be erroneous. Further if I add the IDependency declaration in my SM Registry it just moves on to through to another infrastructure error IhttpRouteData I think.

This seems fairly involved, I have no investment in any of this other than that I want my container to supply dependencies to objects in the constructor. if there is an easier way I'm happy to use it.

That's pretty much what I have

R

Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
Raif
  • 8,641
  • 13
  • 45
  • 56
  • 2
    Can you try the solutions provided [here](http://stackoverflow.com/questions/12605977/autofixture-and-webapi-controller) and [here](http://stackoverflow.com/questions/14985930/autofixture-fails-to-createanonymous-mvc-controller)? – Nikos Baxevanis Oct 02 '13 at 15:10
  • @NikosBaxevanis well, that solution addresses a different issue i think. I have added sa FakeHttpContent customization ( and I do use a composite. I like that pattern ) and that works for that, but for some reason AF is trying to create numerous other infrastructure types such as the RouteData and the DependencyResolver. – Raif Oct 02 '13 at 15:15
  • Can you provide a sample? – Nikos Baxevanis Oct 02 '13 at 15:17
  • How does the `MvcAutoMockData` attribute and `VendorMailController` look like? – Nikos Baxevanis Oct 02 '13 at 17:27
  • I can't reproduce what you describe.. AFAICT, the problem is in the `ContainerCustomization` class (which I don't have access to). If you replace `ContainerCustomization` with `AutoMoqCustomization` the test runs without throwing any exceptions. In order to be able to help further, I need to see how the `ContainerCustomization` class looks like. – Nikos Baxevanis Oct 03 '13 at 10:13
  • right, thank you for looking at this I will now add the containercust – Raif Oct 03 '13 at 13:50
  • I am sorry but I can't get the code to compile.. There are many types that are unknown at compile time and I have to *infer* them to get something to compile. If you can provide a gist or something that I can compile by *copy and paste* I would be happy to help. Thanks for your patience. – Nikos Baxevanis Oct 05 '13 at 17:16
  • 2
    @Raif It'd be great if you could add some followup - the two posts Nikos cites are for me pretty complete but it'd be great to get to the core of what's blocking you from achieving what you need in a natural fashion - it really shouldn't end up complicated – Ruben Bartelink Oct 06 '13 at 08:28
  • @RubenBartelink and NikoBaxevanis Thanks for your attention. I'm in the weeds right now but will be getting back to this hopefully today. I understand that this is going to be hard to reproduce because of the SM reg. I'll try and get it wrapped up in a more "exportable" way and then I'll let you know. Also I'll be happy to post the resolution when I get there. thanks again. – Raif Oct 07 '13 at 16:41
  • @NikosBaxevanis Hi, I have updated the question with a gist that contains all the classes necessary. I believe you can just drop the controller in a web.api project and everything else in a test project and it should work or, not work as it is. You'll need to reference xunit, autofixture, and structuremap of course. I think you might need Microsoft.Practices.ServiceLocation as well. Thanks a lot. – Raif Oct 08 '13 at 17:29
  • @Raif In the Gist, can you provide the code for the `FakeHttpContentCustomization` class? (It is the only type missing.) – Nikos Baxevanis Oct 10 '13 at 08:09
  • @NikosBaxevanis Whoops. I'm sorry, I thought I had them all. It's at the bottom now. – Raif Oct 10 '13 at 13:42
  • 1
    @Raif I had a look at the provided Gist. [The exception is related to StructureMap configuration](https://www.google.com/search?q=No+Default+Instance+defined+for+PluginFamily). AFAICT, this is not related to AutoFixture. – Nikos Baxevanis Oct 10 '13 at 19:59

0 Answers0