user92382
user92382

Reputation: 389

AutoFixture EF entity constraints

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.

Upvotes: 0

Views: 1108

Answers (2)

Mark Seemann
Mark Seemann

Reputation: 233150

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:

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

Upvotes: 3

Nikos Baxevanis
Nikos Baxevanis

Reputation: 11201

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

Upvotes: 2

Related Questions