public void MissingMemberHandlingIgnore() { var dto = ValueDto.Create(true); string json = "{\"booleanValue\":true,\"missing\":false}"; ServiceJsonUtility.FromJson <ValueDto>(json).Should().BeDto(dto); }
public void MetadataPropertyHandlingIgnore() { var dto = ValueDto.Create(true); string json = "{\"$ref\":\"xyzzy\",\"booleanValue\":true}"; ServiceJsonUtility.FromJson <ValueDto>(json).Should().BeDto(dto); }
public void MissingValueIntegerSuccessJson() { var before = ServiceResult.Success(default(int?)); const string json = "{}"; var after = ServiceJsonUtility.FromJson <ServiceResult <int?> >(json); after.Should().BeResult(before); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
/// <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; }
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); }
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); }
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); }
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); }
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); }
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); }
public void ValueAndErrorThrows() { const string json = "{\"value\":1337,\"error\":{}}"; Assert.Throws <JsonSerializationException>(() => ServiceJsonUtility.FromJson <ServiceResult <int?> >(json)); }
/// <summary> /// Load tests from JSON. /// </summary> public static ConformanceTestsInfo FromJson(string json) => ServiceJsonUtility.FromJson <ConformanceTestsInfo>(json);