Skip to content

I am trying to generate 3000 fake records in C# with condition that each 1000 items will have same time stamp(update_time) in UTC milliseconds, then next 1000 will have same time stamp in UTC milliseconds. how to achieve that? #376

Answered by bchavez
mehulparmariitr asked this question in Q&A
Discussion options

You must be logged in to vote

The following code seems to work:

void Main()
{
   var now = DateTimeOffset.UtcNow;
   var documentFaker = new Faker<Document>()
            .StrictMode(true)
            .RuleFor(o => o.id, f => Guid.NewGuid().ToString())
            .RuleFor(o => o.update_time, f =>
               {
                  if (f.IndexFaker % 3 == 0) now = now.AddMilliseconds(10);
                  return now.ToUnixTimeMilliseconds().ToString();
               });
   var fakeDocuments = documentFaker.Generate(30);
   fakeDocuments.Dump();
}

public class Document
{
   public string update_time { get; set; }
   public string id { get; set; }
}

Every 3 generated documents, the update_time is updated +10 millise…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by bchavez
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants