public void MetadataPropertyHandlingIgnore() { var dto = ValueDto.Create(true); var json = "{\"$ref\":\"xyzzy\",\"booleanValue\":true}"; JsonSerializer.FromJson <ValueDto>(json).Should().BeDto(dto); }
public void MissingMemberHandlingIgnore() { var dto = ValueDto.Create(true); var json = "{\"booleanValue\":true,\"missing\":false}"; JsonSerializer.FromJson <ValueDto>(json).Should().BeDto(dto); }
public void NullValueHandlingIgnore() { var dto = ValueDto.Create(default(bool?)); var json = "{}"; JsonSerializer.ToJson(dto).Should().Be(json); JsonSerializer.FromJson <ValueDto>(json).Should().BeDto(dto); }
public void CamelCase() { var dto = ValueDto.Create(true); var json = "{\"booleanValue\":true}"; JsonSerializer.ToJson(dto).Should().Be(json); JsonSerializer.FromJson <ValueDto>(json).Should().BeDto(dto); }
public void DateParseHandlingNone() { var dto = ValueDto.Create("2016-10-21T15:31:00Z"); var json = $"{{\"stringValue\":\"{dto.StringValue}\"}}"; JsonSerializer.ToJson(dto).Should().Be(json); JsonSerializer.FromJson <ValueDto>(json).Should().BeDto(dto); }
public void ServiceResultClone() { var result = ServiceResult.Success(ValueDto.Create(true)); var clone = Serializer.Clone(result); clone.Should().NotBeSameAs(result); ServiceDataUtility.AreEquivalentResults(clone, result).Should().Be(true); }
public void CamelCaseExceptDictionaryKeys() { var dto = ValueDto.Create(new Dictionary <string, bool> { ["Key"] = true }); var json = "{\"booleanMapValue\":{\"Key\":true}}"; JsonSerializer.ToJson(dto).Should().Be(json); JsonSerializer.FromJson <ValueDto>(json).Should().BeDto(dto); }
public void NullValueHandlingIgnore() { var dto = ValueDto.Create(default(bool?)); var 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"); var 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); var 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 }); var 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, }); var json = "{\"errorArrayValue\":[{\"code\":\"InvalidRequest\"},{\"code\":\"InvalidResponse\"}]}"; JsonSerializer.ToJson(dto).Should().Be(json); JsonSerializer.FromJson <ValueDto>(json).Should().BeDto(dto); }
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, }); var json = "{\"errorMapValue\":{\"request\":{\"code\":\"InvalidRequest\"},\"response\":{\"code\":\"InvalidResponse\"}}}"; JsonSerializer.ToJson(dto).Should().Be(json); JsonSerializer.FromJson <ValueDto>(json).Should().BeDto(dto); }
public void DictionaryClone() { 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, }); var clone = Serializer.Clone(dto); clone.Should().NotBeSameAs(dto); clone.ErrorMapValue.Should().NotBeSameAs(dto.ErrorMapValue); clone.IsEquivalentTo(dto).Should().Be(true); }
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, }); var 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, }); var 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); }