public void empty_collection_throws_better_exception_message_rather_than_index_out_of_bounds() { var x = new int[] { }; Action arrayAction = () => r.ArrayElement(x); arrayAction.Should().Throw <ArgumentException>() .Where(ex => ex.Message.StartsWith("The array is empty. There are no items to select.")); Action listAction = () => r.ListItem(x); listAction.Should().Throw <ArgumentException>() .Where(ex => ex.Message.StartsWith("The list is empty. There are no items to select.")); Action collectionAction = () => r.CollectionItem(x); collectionAction.Should().Throw <ArgumentException>() .Where(ex => ex.Message.StartsWith("The collection is empty. There are no items to select.")); }
static LocationCheckin[] GenerateRandomLocationCheckins(int numberToGenerate, IEnumerable <Member> members, IEnumerable <Location> locations, Guid batchId) { var random = new Randomizer(); return (Enumerable.Range(0, numberToGenerate) .Select(t => { var sourceId = random.ArrayElement(SourceIdentifiers); return new Faker <LocationCheckin>() .RuleFor(r => r.Member, s => s.PickRandom(members.Where(e => e.SourceId == sourceId).ToList())) .RuleFor(r => r.Location, s => s.PickRandom(locations.Where(e => e.SourceId == sourceId).ToList())) .RuleFor(r => r.CheckinCompleted, s => s.Date.Between(DateTime.Now.AddYears(-1), DateTime.Now)) .RuleFor(r => r.SourceId, sourceId) .RuleFor(r => r.SourceRowId, Guid.NewGuid()) .RuleFor(r => r.BatchId, batchId) .Generate(); }) .ToArray()); }
public static bool?NullableBool(this Randomizer randomizer) => randomizer.ArrayElement(new[] { (bool?)null, true, false });