AutoFixture EF entity constraints

99封情书 提交于 2019-12-11 18:49:45

问题


Is it possbile to configure AutoFixture so that it adheres the entity constraints [from the EDMX file]?

E.g. Consider a snippet from the CSDL section of my EDMX file:

<EntityType Name="RndtAd">
...
<Property Name="AD" Type="Decimal" Precision="12" Scale="0" Nullable="false" />
<Property Name="USERNAME" Type="String" MaxLength="255" FixedLength="false" Unicode="true" />
<Property Name="VERSION" Type="Decimal" Precision="12" Scale="4" Nullable="false" />
<Property Name="EFFECTIVE_FROM" Type="DateTime" Precision="3" />
<Property Name="EFFECTIVE_FROM_TZ" Type="DateTime" Precision="7" />
<Property Name="EFFECTIVE_TILL" Type="DateTime" Precision="3" />
<Property Name="EFFECTIVE_TILL_TZ" Type="DateTime" Precision="7" />
<Property Name="IS_TEMPLATE" Type="String" MaxLength="1" FixedLength="true" Unicode="false" />
<Property Name="IS_USER" Type="String" MaxLength="1" FixedLength="true" Unicode="false" />
<Property Name="STRUCT_CREATED" Type="String" MaxLength="1" FixedLength="true" Unicode="false" />
<Property Name="AD_TP" Type="String" MaxLength="20" FixedLength="false" Unicode="true" />
<Property Name="PERSON" Type="String" MaxLength="40" FixedLength="false" Unicode="true" />
<Property Name="TITLE" Type="String" MaxLength="20" FixedLength="false" Unicode="true" />
<Property Name="FUNCTION_NAME" Type="String" MaxLength="20" FixedLength="false" Unicode="true" />
<Property Name="COMPANY" Type="String" MaxLength="40" FixedLength="false" Unicode="true" />
<Property Name="STREET" Type="String" MaxLength="40" FixedLength="false" Unicode="true" />
...

What I would like if fixture.Create<RndtAd>() generated randomly an entity where all the previous constraints are satisfied.

What options do I have? All suggestions are welcome.

EDIT. I'm not bound to AutoFixture. If there is another tool which does the job, I'm ok with that too.


回答1:


AutoFixture has no built-in support for Entity Framework, but during the last couple of years, several people have fought their own battles to integrate the two.

Here's what a Google search turned up for me:

  • Autofixture and Moq to test Entity Framework project
  • AutoFixture.AutoEntityFramework
  • Creating a domain model without circular references in Entity Framework
  • Using autofixture in my data integration tests to create proxies
  • How to mockup Entity Framework 6 With Moq & Autofixture

Perhaps you can find some inspiration by looking some of those resources over.




回答2:


As-is, AutoFixture can't be customized through .EDMX files.



来源:https://stackoverflow.com/questions/24931551/autofixture-ef-entity-constraints

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!