Skip to content

Commit

Permalink
tests: Add tests for serializing and deserializing case sensitive JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
amanda-tarafa committed Sep 14, 2023
1 parent 51e6a72 commit d012918
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -63,5 +63,44 @@ public void CustomInstanceAvoidingDateParsin()
// No magic parsing to DateTime...
Assert.IsType<string>(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<DataWithTwoEtags>(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; }
}
}
}

0 comments on commit d012918

Please sign in to comment.