I would like to use the data generated using the Bogus library in unit tests. How can I pass the generated data to the appropriate place in the code - noted in the comment.
public class Person
{
public string Name { get; set; }
public string Surname{ get; set; }
public string Phone { get; set; }
}
using Bogus;
public class Generator
{
public void Seed(Person context)
{
var personGenerator = new Faker<Person>()
.RuleFor(c => c.Name, f => f.Name.FirstName())
.RuleFor(c => c.Surname, f => f.Name.LastName())
.RuleFor(c => c.Phone, f => f.Phone.PhoneNumber())
var person = personGenerator.Generate(50);
}
}
public class PersonTests
{
private readonly Person PERSON = new()
{
Name = "Tom", //how to pass the generated data here
Surname = "Cat",
Phone = "+47 123 123 123",
};
[Theory]
[InlineData(nameof(PERSON))]
public void Validate_ValidModel_ReturnsSuccessState(string item)
{
var person = this.GetValueByName<Person>(item) ?? throw new ArgumentNullException(nameof(item));
//Act
var res = new Person.Validator().Validate(person);
//Assert
Assert.True(res.IsValid);
}
}
I will be grateful for your help!