Before I dive into answering the specific questions, I'd like to point out something that might be a lot easier: you might consider just assigning values to those writable properties after you called CreateMany, but before you return the result.
Something like this:
var transactionViews = fixture.CreateMany<TransactionView>(transactionsToReturnCount);
foreach (var tv in transactionViews)
{
tv.ViewKey.TransactionId = beginningTransactionId++;
tv.TransactionDate = DateTime.Now - new TimeSpan(random.Next(30),0,0,0);
}
return transactionViews.OrderBy(t => t.TransactionDate).ToArray();
This might look like a hack, but really isn't. AutoFixture is designed to create Anonymous Values so whenever you are trying to assign specific values (which you currently are), you are stepping outside of its original purpose.
Don't get me wrong: it's cool that you use AutoFixture like this. I also sometimes have to assign some specific values to some members of the specimens I have AutoFixture create, but I tend to use the above technique, because the normal .NET API of getters and setter is already specialized at doing exactly that. AutoFixture, on the other hand, is specialized at defining rules for being vague, so its purpose is the opposite.
That said, however, I will now answer the specific questions put forth above:
Question 1
I haven't tried to compile this, so you may have to tweak it a bit, but the best thing you can do would be something like this:
fixture.Customize<TransactionViewKey>(ob => ob
.Without(t => t.TransactionId)
.Do(t => t.TransactionId = beginningTransactionId++)
.With(t => t.TransactionIdSpecified, true)
.OmitAutoProperties());
Question 2
The second parameter to the With method is not a delegate - it's a value so it's only being evaluated once.
To evaluate it each time, you can use the same trick as above:
fixture.Customize<TransactionView>(ob => ob
.Without(t => t.TransactionDate)
.Do(t => t.TransactionDate = DateTime.Now - new TimeSpan(random.Next(30),0,0,0))
.With(t => t.PostDate, DateTime.Now - new TimeSpan(random.Next(30), 0, 0, 0))
.With(t => t.ViewKey)
.With(t => t.Amount)
.OmitAutoProperties());
Please let me know if you have any additional questions.
HTH