DEV Community

Discussion on: How to save time writing unit and integration tests with AutoFixture

Collapse
bchavez profile image
Brian Chavez

You can also use AutoBogus and Bogus together to make a 1-liner. No manual rules necessary:

void Main()
{
   var c = AutoBogus.AutoFaker.Generate<Customer>();
   c.Dump();
}

public class Customer
{
   public string FirstName { get; set; }
   public string LastName { get; set; }
   public string EmailAddress {get;set;}
   public DateTime DateOfBirth {get;set;}
   public Address Address {get;set;}
};

public class Address
{
   public string AddressLine1 { get; set; }
   public string AddressLine2 { get; set; }
   public string ZipOrPostcode { get; set; }
   public string Country {get;set;}
}
{
  "FirstName": "Mauritania",
  "LastName": "Path",
  "EmailAddress": "Open-source",
  "DateOfBirth": "2019-09-11T10:34:41.9215413-07:00",
  "Address": {
    "AddressLine1": "Auto Loan Account",
    "AddressLine2": "Illinois",
    "ZipOrPostcode": "Azerbaijanian Manat",
    "Country": "Liaison"
  }
}