Пример #1
0
        public async void GetValue_WithObjectInsideStructureAndRightJson_ShouldReturnItemsValues()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    new Field
                    {
                        Id        = "test_address",
                        Name      = "address",
                        DataType  = DataTypeEnum.Object,
                        Nullable  = false,
                        Structure = new StructureDefinition
                        {
                            Id     = "address",
                            Name   = "address",
                            Fields = new List <Field>
                            {
                                Field.NotNullString("test_city", "city"),
                                Field.NotNullString("test_country", "country")
                            }
                        }
                    }
                }
            };

            var city = await structure.GetValue("address.city", JsonSerializer.Serialize(new { address = new { city = "Tabriz", country = "Iran" } }));

            Assert.Equal("Tabriz", city);
        }
Пример #2
0
        public async void GetValue_WithNullableString_ShouldReturnNull()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    Field.NullableString("name", "name")
                }
            };

            Assert.Null(await structure.GetValue("name", JsonSerializer.Serialize(new { age = 34 })));
        }
Пример #3
0
        public async void GetValue_WithNotNullableString_ShouldThrowException()
        {
            var structure = new StructureDefinition
            {
                Id     = "test",
                Fields = new List <Field>
                {
                    Field.NotNullString("name", "name")
                }
            };

            await Assert.ThrowsAsync <InvalidJsonStringInputException>(async() => await structure.GetValue("name", JsonSerializer.Serialize(new { age = 34 })));
        }