Exemplo n.º 1
0
        public void MissingMemberHandlingIgnore()
        {
            var    dto  = ValueDto.Create(true);
            string json = "{\"booleanValue\":true,\"missing\":false}";

            ServiceJsonUtility.FromJson <ValueDto>(json).Should().BeDto(dto);
        }
Exemplo n.º 2
0
        public void MetadataPropertyHandlingIgnore()
        {
            var    dto  = ValueDto.Create(true);
            string json = "{\"$ref\":\"xyzzy\",\"booleanValue\":true}";

            ServiceJsonUtility.FromJson <ValueDto>(json).Should().BeDto(dto);
        }
Exemplo n.º 3
0
        public void MissingValueIntegerSuccessJson()
        {
            var          before = ServiceResult.Success(default(int?));
            const string json   = "{}";
            var          after  = ServiceJsonUtility.FromJson <ServiceResult <int?> >(json);

            after.Should().BeResult(before);
        }
Exemplo n.º 4
0
        public void ExtraFieldFailureJson()
        {
            var    before = ServiceResult.Failure(new ServiceErrorDto());
            string json   = "{\"values\":1337,\"error\":{},\"valuex\":1337}";
            var    after  = ServiceJsonUtility.FromJson <ServiceResult <int> >(json);

            after.Should().BeResult(before);
        }
Exemplo n.º 5
0
        public void ExtraFieldSuccessJson()
        {
            var    before = ServiceResult.Success(1337);
            string json   = "{\"values\":1337,\"value\":1337,\"valuex\":1337}";
            var    after  = ServiceJsonUtility.FromJson <ServiceResult <int> >(json);

            after.Should().BeResult(before);
        }
Exemplo n.º 6
0
        public void NullIntegerSuccessJson()
        {
            var    before = ServiceResult.Success(default(int?));
            string json   = ServiceJsonUtility.ToJson(before);

            json.Should().Be("{\"value\":null}");
            var after = ServiceJsonUtility.FromJson <ServiceResult <int?> >(json);

            after.Should().BeResult(before);
        }
Exemplo n.º 7
0
        public void IntegerFailureJson()
        {
            var    before = ServiceResult.Failure(new ServiceErrorDto("Xyzzy", "Xyzzy unexpected."));
            string json   = ServiceJsonUtility.ToJson(before);

            json.Should().Be("{\"error\":{\"code\":\"Xyzzy\",\"message\":\"Xyzzy unexpected.\"}}");
            var after = ServiceJsonUtility.FromJson <ServiceResult <int> >(json);

            after.Should().BeResult(before);
        }
Exemplo n.º 8
0
        public void IntegerEmptyFailureJson()
        {
            var    before = ServiceResult.Failure(new ServiceErrorDto());
            string json   = ServiceJsonUtility.ToJson(before);

            json.Should().Be("{\"error\":{}}");
            var after = ServiceJsonUtility.FromJson <ServiceResult <int?> >(json);

            after.Should().BeResult(before);
        }
Exemplo n.º 9
0
        public void IntegerSuccessJson()
        {
            var    before = ServiceResult.Success(1337);
            string json   = ServiceJsonUtility.ToJson(before);

            json.Should().Be("{\"value\":1337}");
            var after = ServiceJsonUtility.FromJson <ServiceResult <int> >(json);

            after.Should().BeResult(before);
        }
Exemplo n.º 10
0
        public void NoValueSuccessJson()
        {
            var    before = ServiceResult.Success();
            string json   = ServiceJsonUtility.ToJson(before);

            json.Should().Be("{}");
            var after = ServiceJsonUtility.FromJson <ServiceResult>(json);

            after.Should().BeResult(before);
        }
Exemplo n.º 11
0
        private void SerializePreference(PreferenceDto dto, string expectedJson = null)
        {
            string json = ServiceJsonUtility.ToJson(dto);

            if (expectedJson != null)
            {
                json.Should().Be(expectedJson);
            }
            ServiceJsonUtility.FromJson <PreferenceDto>(json).Should().BeDto(dto);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a test provider from the specified directory path.
        /// </summary>
        public ConformanceTestProvider(string testsFilePath)
        {
            var conformanceTests = new Dictionary <string, ConformanceTestInfo>();
            var testsInfo        = ServiceJsonUtility.FromJson <ConformanceTestsInfo>(File.ReadAllText(testsFilePath));

            foreach (var testInfo in testsInfo.Tests)
            {
                conformanceTests.Add(testInfo.Test, testInfo);
            }
            m_conformanceTests = conformanceTests;
        }
Exemplo n.º 13
0
        public void NullValueHandlingIgnore()
        {
            var    dto  = ValueDto.Create(default(bool?));
            string json = "{}";

            ServiceJsonUtility.ToJson(dto).Should().Be(json);
            ServiceJsonUtility.FromJson <ValueDto>(json).Should().BeDto(dto);

            var token = ServiceJsonUtility.FromJson <JToken>(json);

            token["stringValue"].Should().BeNull();
            ServiceJsonUtility.ToJson(token).Should().Be(json);
        }
Exemplo n.º 14
0
        public void DateParseHandlingNone()
        {
            var    dto  = ValueDto.Create("2016-10-21T15:31:00Z");
            string json = $"{{\"stringValue\":\"{dto.StringValue}\"}}";

            ServiceJsonUtility.ToJson(dto).Should().Be(json);
            ServiceJsonUtility.FromJson <ValueDto>(json).Should().BeDto(dto);

            var token = ServiceJsonUtility.FromJson <JToken>(json);

            token["stringValue"].Type.Should().Be(JTokenType.String);
            ServiceJsonUtility.ToJson(token).Should().Be(json);
        }
Exemplo n.º 15
0
        public void CamelCase()
        {
            var    dto  = ValueDto.Create(true);
            string json = "{\"booleanValue\":true}";

            ServiceJsonUtility.ToJson(dto).Should().Be(json);
            ServiceJsonUtility.FromJson <ValueDto>(json).Should().BeDto(dto);

            var token = ServiceJsonUtility.FromJson <JToken>(json);

            token["booleanValue"].Type.Should().Be(JTokenType.Boolean);
            ServiceJsonUtility.ToJson(token).Should().Be(json);
        }
Exemplo n.º 16
0
        public void CamelCaseExceptDictionaryKeys()
        {
            var dto = ValueDto.Create(new Dictionary <string, bool> {
                ["Key"] = true
            });
            string json = "{\"booleanMapValue\":{\"Key\":true}}";

            ServiceJsonUtility.ToJson(dto).Should().Be(json);
            ServiceJsonUtility.FromJson <ValueDto>(json).Should().BeDto(dto);

            var token = ServiceJsonUtility.FromJson <JToken>(json);

            token["booleanMapValue"].Type.Should().Be(JTokenType.Object);
            ServiceJsonUtility.ToJson(token).Should().Be(json);
        }
Exemplo n.º 17
0
        public void ArraySerialization()
        {
            var invalidRequest = new ServiceErrorDto {
                Code = ServiceErrors.InvalidRequest
            };
            var invalidResponse = new ServiceErrorDto {
                Code = ServiceErrors.InvalidResponse
            };
            var dto = ValueDto.Create(new List <ServiceErrorDto>
            {
                invalidRequest,
                invalidResponse,
            });
            string json = "{\"errorArrayValue\":[{\"code\":\"InvalidRequest\"},{\"code\":\"InvalidResponse\"}]}";

            ServiceJsonUtility.ToJson(dto).Should().Be(json);
            ServiceJsonUtility.FromJson <ValueDto>(json).Should().BeDto(dto);

            var token = ServiceJsonUtility.FromJson <JToken>(json);

            token["errorArrayValue"].Type.Should().Be(JTokenType.Array);
            ServiceJsonUtility.ToJson(token).Should().Be(json);
        }
Exemplo n.º 18
0
        public void DictionarySerialization()
        {
            var invalidRequest = new ServiceErrorDto {
                Code = ServiceErrors.InvalidRequest
            };
            var invalidResponse = new ServiceErrorDto {
                Code = ServiceErrors.InvalidResponse
            };
            var dto = ValueDto.Create(new Dictionary <string, ServiceErrorDto>
            {
                ["request"]  = invalidRequest,
                ["response"] = invalidResponse,
            });

            string json = "{\"errorMapValue\":{\"request\":{\"code\":\"InvalidRequest\"},\"response\":{\"code\":\"InvalidResponse\"}}}";

            ServiceJsonUtility.ToJson(dto).Should().Be(json);
            ServiceJsonUtility.FromJson <ValueDto>(json).Should().BeDto(dto);

            var token = ServiceJsonUtility.FromJson <JToken>(json);

            token["errorMapValue"].Type.Should().Be(JTokenType.Object);
            ServiceJsonUtility.ToJson(token).Should().Be(json);
        }
Exemplo n.º 19
0
        public void ValueAndErrorThrows()
        {
            const string json = "{\"value\":1337,\"error\":{}}";

            Assert.Throws <JsonSerializationException>(() => ServiceJsonUtility.FromJson <ServiceResult <int?> >(json));
        }
Exemplo n.º 20
0
 /// <summary>
 /// Load tests from JSON.
 /// </summary>
 public static ConformanceTestsInfo FromJson(string json) => ServiceJsonUtility.FromJson <ConformanceTestsInfo>(json);