Пример #1
0
        public virtual void QueryByJsonPath_Should_ReturnValueAccordingToGenericValueTypeAndJsonPathPassedIn()
        {
            // Arrange
            var utf8JsonBytes = JsonSerializer.SerializeToUtf8Bytes(new ADto
            {
                RedPanda = "Hello World!",
                Happy    = true,
                Year     = 2020,
                Enum     = TestEnum.RedPanda,
                BDto     = new BDto
                {
                    Service = "RedPanda"
                },
                CDtos = new CDto[]
                {
                    new CDto
                    {
                        Governance = "Hot"
                    },
                    new CDto
                    {
                        Governance = "Cool"
                    },
                }
            });

            // Assert
            var stringResult           = jsonProvider.QueryByJsonPath <string>(utf8JsonBytes, "$.RedPanda");
            var booleanResult          = jsonProvider.QueryByJsonPath <bool>(utf8JsonBytes, "$.Happy");
            var intResult              = jsonProvider.QueryByJsonPath <int>(utf8JsonBytes, "$.Year");
            var enumResult             = jsonProvider.QueryByJsonPath <TestEnum>(utf8JsonBytes, "$.Enum");
            var innerStringResult      = jsonProvider.QueryByJsonPath <string>(utf8JsonBytes, "$.BDto.Service");
            var innerArrayStringResult = jsonProvider.QueryByJsonPath <string>(utf8JsonBytes, "$.CDtos.[1].Governance");

            // Act
            stringResult.Should().BeEquivalentTo("Hello World!");
            booleanResult.Should().Be(true);
            intResult.Should().Be(2020);
            enumResult.Should().Be(TestEnum.RedPanda);
            innerStringResult.Should().Be("RedPanda");
            innerArrayStringResult.Should().Be("Cool");
        }