Skip to content

Commit

Permalink
Merge pull request #35 from sguryev/serj/main-snake-test
Browse files Browse the repository at this point in the history
Add snake case test
  • Loading branch information
Havunen authored Oct 18, 2024
2 parents 847bb2a + df190f9 commit 17bfc79
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Dynamic;
using System.Text.Json;
using SystemTextJsonPatch.Exceptions;
using SystemTextJsonPatch.Operations;
using Xunit;

namespace SystemTextJsonPatch.IntegrationTests;
Expand Down Expand Up @@ -56,6 +57,39 @@ public void ReplaceNestedObjectWithSerialization()
// Assert
Assert.Equal("B", targetObject.NestedObject.StringProperty);
}

#if NET8_0

[Fact]
public void ReplaceNestedObjectWithPlainStrings()
{
// Arrange
var targetObject = new SimpleObjectWithNestedObject()
{
IntegerValue = 1,
NestedObject = null
};
var options = new JsonSerializerOptions()
{
PropertyNamingPolicy = JsonNamingPolicy.SnakeCaseLower
};

var newNested = new NestedObject { StringProperty = "B" };
var patchDocument = new JsonPatchDocument<SimpleObjectWithNestedObject>();
patchDocument.Operations.Add(new Operation<SimpleObjectWithNestedObject>("replace", "/nested_object", JsonSerializer.Serialize(newNested, options)));
patchDocument.Options = options;

var serialized = JsonSerializer.Serialize(patchDocument, options);
var deserialized = JsonSerializer.Deserialize<JsonPatchDocument<SimpleObjectWithNestedObject>>(serialized, options);

// Act
deserialized.ApplyTo(targetObject);

// Assert
Assert.Equal("B", targetObject.NestedObject.StringProperty);
}

#endif

[Fact]
public void TestStringPropertyInNestedObject()
Expand Down

0 comments on commit 17bfc79

Please sign in to comment.