Note that there are some explanatory texts on larger screens.

plurals
  1. POCustomizing AutoFixture builder with seeded property
    primarykey
    data
    text
    <p>I've got a customized autofixture builder for an integration test. Code is below.</p> <p>Question 1 - At present the first transaction has a TransactionViewKey.TransactionId of 1, etc. How do I set the TransactionViewKey TransactionId so it is seeded from the method param <em>beginningTransactionId</em>? eg returning an array of TransactionViews where the first TransactionId is 200, then each incrementing by 1?</p> <p>Question 2 - the lambda for determining transactiondate seems to be run once only - and so each date is the same value. How do I setup the builder so it runs the random date generator for each generated instance rather than once only?</p> <p>thanks</p> <pre><code> static TransactionView[] CreateTransactions(int transactionsToReturnCount, long beginningTransactionId) { Random random = new Random(); IFixture fixture = new Fixture(); fixture.Customize&lt;TransactionViewKey&gt;(ob =&gt; ob .With(t =&gt; t.TransactionId) .With(t =&gt; t.TransactionIdSpecified, true) .OmitAutoProperties() ); fixture.Customize&lt;TransactionView&gt;(ob =&gt; ob .With(t =&gt; t.TransactionDate, DateTime.Now - new TimeSpan(random.Next(30),0,0,0)) .With(t =&gt; t.PostDate, DateTime.Now - new TimeSpan(random.Next(30), 0, 0, 0)) .With(t =&gt; t.ViewKey) .With(t =&gt; t.Amount) .OmitAutoProperties() ); IEnumerable&lt;TransactionView&gt; transactionViews = fixture.CreateMany&lt;TransactionView&gt;(transactionsToReturnCount); return transactionViews.OrderBy(t =&gt; t.TransactionDate).ToArray(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload