public void cannot_use_rules_with_strictmode() { var faker = new Faker <Examples.Order>() .Rules((f, o) => { o.Quantity = f.Random.Number(1, 4); o.Item = f.Commerce.Product(); o.OrderId = 25; }) .StrictMode(true); Action act = () => faker.AssertConfigurationIsValid(); act.Should().Throw <ValidationException>(); var faker2 = new Faker <Examples.Order>() .StrictMode(true) .Rules((f, o) => { o.Quantity = f.Random.Number(1, 4); o.Item = f.Commerce.Product(); o.OrderId = 25; }); Action act2 = () => faker2.AssertConfigurationIsValid(); act2.Should().Throw <ValidationException>(); }
public void should_throw_exception_on_incomplete_rules() { var testOrders = new Faker <Examples.Order>() .StrictMode(true) .RuleFor(o => o.Quantity, f => f.Random.Number(2, 5)); Assert.Throws <ValidationException>(() => testOrders.AssertConfigurationIsValid()); }
public void should_be_valid_no_exceptions_on_incomplete_rules_when_strict_false() { var testOrders = new Faker <Examples.Order>() .StrictMode(false) .RuleFor(o => o.Quantity, f => f.Random.Number(2, 5)); var result = testOrders.Validate(); testOrders.AssertConfigurationIsValid(); result.ShouldBeEquivalentTo(true); }
public void should_not_be_valid_and_throw_exception_on_incomplete_rules() { var testOrders = new Faker <Examples.Order>() .StrictMode(true) .RuleFor(o => o.Quantity, f => f.Random.Number(2, 5)); var result = testOrders.Validate(); Assert.Throws <ValidationException>(() => testOrders.AssertConfigurationIsValid()); result.ShouldBeEquivalentTo(false); }
public void explicit_interface_properties_in_child_interfaces_should_throw_when_strictmode_true2() { var childFaker = new Faker <IChild>() .StrictMode(true) .CustomInstantiator(f => new ChildWithExplicitInterface()) .RuleFor(e => e.Name, f => f.Address.City()); Action act = () => childFaker.AssertConfigurationIsValid(); act.Should().Throw <ValidationException>(); }
public void should_be_valid_and_not_throw_exception_on_complete_rules_with_ignore() { var testOrders = new Faker <Examples.Order>() .StrictMode(true) .Ignore(o => o.Item) .RuleFor(o => o.OrderId, f => 3343) .RuleFor(o => o.Quantity, f => f.Random.Number(2, 5)); var result = testOrders.Validate(); testOrders.AssertConfigurationIsValid(); result.ShouldBeEquivalentTo(true); }
public void should_be_valid_on_complete_rules() { var testOrders = new Faker <Examples.Order>() .StrictMode(true) .RuleFor(o => o.Quantity, f => f.Random.Number(2, 5)) .RuleFor(o => o.OrderId, f => f.Random.Number(2, 5)) .RuleFor(o => o.Item, f => f.Lorem.Sentence()) ; var result = testOrders.Validate(); testOrders.AssertConfigurationIsValid(); result.ShouldBeEquivalentTo(true); }
/// <summary>Gets a random request body.</summary> /// <returns></returns> public static Body GetRandomRequestBody() { var faker = new Faker <Body>() .CustomInstantiator(fake => new Body()) .RuleFor(x => x.Path, () => JObject.FromObject(GetRandomRantCollection()) .ToString(Formatting.Indented)) .RuleFor(x => x.Path, Body.BodyType.JSON.ToString()); faker.AssertConfigurationIsValid(); return(faker.Generate()); }
// private static List<RantCollection> RandomRantCollectionGenerator(int count, int? size = null) // { // var quoteFaker = new Faker<RandRecord>() // .RuleFor(x => x.RantId, f => f.Random.Int(1, 500000)) // .RuleFor(x => x.Person, f => f.Internet.UserNameUnicode()) // .RuleFor(x => x.Rant, f => f.Rant.Review(new Faker().Commerce.ProductName())) // .RuleFor(x => x.Date, f => f.Date.Between(DateTime.UnixEpoch, DateTime.UtcNow)); // // var faker = new Faker<RantCollection>() // .RuleFor(x => x.Id, f => f.Random.Guid().OrNull(new Faker())) // .RuleFor(x => x.Owner, f => f.Person.FullName) // .RuleFor(x => x.Gender, f => f.PickRandom<Gender>()) // .RuleFor(x => x.Rants, f => quoteFaker.Generate(new Faker().Random.Int(10, size ?? 50))); // // faker.AssertConfigurationIsValid(); // // return faker.Generate(count); // } /// <summary>Gets some test data.</summary> /// <returns></returns> private static RantCollection GetRandomRantCollection() { var quoteFaker = new Faker <RandRecord>() .RuleFor(x => x.RantId, f => f.Random.Int(1, 500000)) .RuleFor(x => x.Person, f => f.Internet.UserNameUnicode()) .RuleFor(x => x.Rant, f => f.Rant.Review(new Faker().Commerce.ProductName())) .RuleFor(x => x.Date, f => f.Date.Between(DateTime.UnixEpoch, DateTime.UtcNow)); var faker = new Faker <RantCollection>() .RuleFor(x => x.Id, f => f.Random.Guid().OrNull(new Faker())) .RuleFor(x => x.Owner, f => f.Person.FullName) .RuleFor(x => x.Gender, f => f.PickRandom <Gender>()) .RuleFor(x => x.Rants, f => quoteFaker.Generate(new Faker().Random.Int(10, 50))); faker.AssertConfigurationIsValid(); return(faker.Generate()); }