ruskindantra/AutoFixture.AutoEntityFramework

Auto unwrap objectProxy to object

Closed this issue · 4 comments

Would it be possible to unwrap proxy collections into their actual classes?

e.g: when table 'Car' has four 'Doors', car has a List<DoorProxy> CarDoors(generated by AutoFixture.AutoEF, nice)

But, is there any way I can get them to be just List<Door> CarDoors

I think there may be some conceptual problems there. I needed this customization to avoid infinite recursion errors due to the circular references in EF object graphs - if you try to create a Door and the door has a Car property and the Car has a Doors property and those Doors have Car properties... You get the idea!

Could you help me better understand the scenario you're facing?

Yes, ofcourse.

Intro; We use the Car object directly on an external WCF service. I have no influence in the serializer here, unfortunately.

My Car is serializable, as well as my Doors collection. However, If I get a CarProxy with DoorsProxy I cannot deserialize them and thus test fails.

Any tips or ideas for this?

The proxy network is infinite - it will keep generating objects for as long as you access their properties. There can be no generalised approach for converting a FooProxy to a Foo.

The three four options in this scenario are:

  1. Modify serialization code to accept inherited types
  2. Trick serialization code into thinking the proxy object type is the entity class (intercepting the GetType() method may work)
  3. Manually define a function which can recursively produce the entity graph
  4. Don't use this project for this test - instead specify an AutoFixture builder customization

As you say you cannot do 1 - I am happy to give guidance on the other 3 if you want

Thank you for your response. I've been reading up on option 4 and am currently testing :) 👍