Saturday, November 21, 2015

Populate real time data for testing using GenFu API C#

We need test data very often for sake of testing in Test or UAT server. There are Few API’s available which can generate random data. Fixture and AutoFixture is such kind of library but the limitation is, It will generates random string.

The beauty of GenFu is, it will provide you real time value. Here is one example.

public class Contact
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public string EmailAdress { get; set; }
        public string PhoneNumber { get; set; }

        public override string ToString()
        {
            return $"{Id}: {FirstName}
              {LastName}
              {EmailAdress} - {PhoneNumber}";
        }
    }

The class definition is very simple and self-explanatory. Now, we will call API function to Generate random objects for the class.

        public static void Main(String[] args)
        {
            //Generate 25 random 
            //Information by default
            var people = A.ListOf<Contact>();
            foreach (var person in people)
            {
              Console.
              WriteLine(person.ToString());
            }

            Console.ReadLine();
        }

GenFu to load real time data

Please read more about GenFu in below link.

 

2 comments:

  1. You're copying content that originally belongs to someone else... sad

    ReplyDelete
  2. That's why the reference is given in bottom.. :)

    ReplyDelete