From 422db30b4af91d09f2b0888d2c5502e6d75a6e24 Mon Sep 17 00:00:00 2001 From: Amanda Tarafa Mas Date: Wed, 13 Sep 2023 10:49:11 -0700 Subject: [PATCH] tests: Add tests for serializing and deserializing case sensitive JSON. --- .../Json/NewtonsoftJsonSerializerTest.cs | 41 ++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/Src/Support/Google.Apis.Tests/Json/NewtonsoftJsonSerializerTest.cs b/Src/Support/Google.Apis.Tests/Json/NewtonsoftJsonSerializerTest.cs index 0906488c008..b2b0a721da3 100644 --- a/Src/Support/Google.Apis.Tests/Json/NewtonsoftJsonSerializerTest.cs +++ b/Src/Support/Google.Apis.Tests/Json/NewtonsoftJsonSerializerTest.cs @@ -52,7 +52,7 @@ public void DefaultInstanceParsesDates() } [Fact] - public void CustomInstanceAvoidingDateParsin() + public void CustomInstanceAvoidingDateParsing() { string text = "\"2017-05-03T16:38:00Z\""; var settings = NewtonsoftJsonSerializer.CreateDefaultSettings(); @@ -63,5 +63,44 @@ public void CustomInstanceAvoidingDateParsin() // No magic parsing to DateTime... Assert.IsType(value); } + + [Fact] + public void DefaultInstanceSerializesTwoETags() + { + var data = new DataWithTwoEtags + { + AField = "a value", + ETag = "lowercase", + ETag__ = "no-lowercase" + }; + var expectedText = "{\"a_field\":\"a value\",\"etag\":\"lowercase\",\"ETag\":\"no-lowercase\"}"; + var text = NewtonsoftJsonSerializer.Instance.Serialize(data); + + Assert.Equal(expectedText, text); + } + + [Fact] + public void DefaultInstanceDeserializesTwoETags() + { + var text = "{\"a_field\":\"a value\",\"etag\":\"lowercase\",\"ETag\":\"no-lowercase\"}"; + + var data = NewtonsoftJsonSerializer.Instance.Deserialize(text); + + Assert.Equal("a value", data.AField); + Assert.Equal("lowercase", data.ETag); + Assert.Equal("no-lowercase", data.ETag__); + } + + public class DataWithTwoEtags + { + [JsonProperty("a_field")] + public string AField { get; set; } + + [JsonProperty("etag")] + public string ETag { get; set; } + + [JsonProperty("ETag")] + public string ETag__ { get; set; } + } } }