예제 #1
0
        //Demo that shows that
        static void Main(string[] args)
        {
            try
            {
                var RBO = new RBOInitClient(new Uri("https://localhost:44351/"));
                RBO.Login("user", "pass");

                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);

                JsonSerializerOptions options = new JsonSerializerOptions()
                {
                    WriteIndented = true
                };
                var json = JsonSerializer.Serialize(owners, options);
                Console.WriteLine(json);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #2
0
        public void TestCreateObject()
        {
            var           client = _factory.CreateClient();
            RBOInitClient RBO    = new RBOInitClient(client);

            RBO.Login("user", "pass");
            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 owner = RBO.Create <Owner>();

            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);
            }
        }