public void TestCreateArray() { var RBO = new RBOInit(); RBO.AddRule("Id", SourceTypeEnum.Sequence); RBO.AddRule("Name", SourceTypeEnum.Array, "Paul", "John"); RBO.AddRule("Pets.Length", SourceTypeEnum.Value, 5); RBO.AddRule("Pets[].Name", SourceTypeEnum.Array, "Rocky", "Coco"); RBO.AddRule("Species", SourceTypeEnum.Array, "Dog", "Cat", "Fish"); RBO.AddRule("Age", SourceTypeEnum.Random, 1, 10); RBO.AddRule("IsTrained", SourceTypeEnum.Array, true, false); var owners = RBO.CreateArray <Owner>(10); Assert.Equal(10, owners.Length); for (int j = 0; j < owners.Length; j++) { var owner = owners[j]; Assert.True(new List <string> { "Paul", "John" }.Contains(owner.Name)); Assert.Equal(5, owner.Pets.Length); for (var i = 0; i < owner.Pets.Length; i++) { var pet = owner.Pets[i]; Assert.True(new List <string> { "Rocky", "Coco" }.Contains(pet.Name)); Assert.True(new List <string> { "Dog", "Cat", "Fish" }.Contains(pet.Species)); Assert.InRange <int>(pet.Age, 1, 10); } } }
static void Main(string[] args) { try { var RBO = new RBOInit(); RBO.AddRule("Id", SourceTypeEnum.Sequence); RBO.AddRule("Name", SourceTypeEnum.Array, "Paul", "John"); RBO.AddRule("Pets.Length", SourceTypeEnum.Value, 3); RBO.AddRule("Pets[].Name", SourceTypeEnum.Array, "Rocky", "Coco"); RBO.AddRule("Species", SourceTypeEnum.Array, "Dog", "Cat", "Fish"); RBO.AddRule("Age", SourceTypeEnum.Random, 1, 10); RBO.AddRule("IsTrained", SourceTypeEnum.Array, true, false); var owners = RBO.CreateArray <Owner>(2); JsonSerializerOptions options = new JsonSerializerOptions() { WriteIndented = true }; var json = JsonSerializer.Serialize(owners, options); Console.WriteLine(json); } catch (Exception e) { Console.WriteLine(e.Message); } }