Add tests for Replace operation with null checks for property (#56)
See #32
This commit is contained in:
parent
e8452821b9
commit
0795ec1d9a
|
|
@ -907,6 +907,29 @@ namespace Microsoft.AspNetCore.JsonPatch
|
||||||
Assert.Equal(12, doc.SimpleDTO.DecimalValue);
|
Assert.Equal(12, doc.SimpleDTO.DecimalValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Replace_DTOWithNullCheck()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var doc = new SimpleDTOWithNestedDTOWithNullCheck()
|
||||||
|
{
|
||||||
|
SimpleDTOWithNullCheck = new SimpleDTOWithNullCheck()
|
||||||
|
{
|
||||||
|
StringProperty = "A"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// create patch
|
||||||
|
var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTOWithNullCheck>();
|
||||||
|
patchDoc.Replace(o => o.SimpleDTOWithNullCheck.StringProperty, "B");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
patchDoc.ApplyTo(doc);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal("B", doc.SimpleDTOWithNullCheck.StringProperty);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ReplaceWithSerialization()
|
public void ReplaceWithSerialization()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -648,6 +648,26 @@ namespace Microsoft.AspNetCore.JsonPatch.Adapters
|
||||||
Assert.Equal(12, doc.DecimalValue);
|
Assert.Equal(12, doc.DecimalValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Replace_DTOWithNullCheck()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var doc = new SimpleDTOWithNullCheck()
|
||||||
|
{
|
||||||
|
StringProperty = "A",
|
||||||
|
};
|
||||||
|
|
||||||
|
// create patch
|
||||||
|
var patchDoc = new JsonPatchDocument<SimpleDTOWithNullCheck>();
|
||||||
|
patchDoc.Replace(o => o.StringProperty, "B");
|
||||||
|
|
||||||
|
// Act
|
||||||
|
patchDoc.ApplyTo(doc);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
Assert.Equal("B", doc.StringProperty);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ReplaceWithSerialization()
|
public void ReplaceWithSerialization()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.JsonPatch
|
||||||
|
{
|
||||||
|
public class SimpleDTOWithNestedDTOWithNullCheck
|
||||||
|
{
|
||||||
|
public SimpleDTOWithNullCheck SimpleDTOWithNullCheck { get; set; }
|
||||||
|
|
||||||
|
public SimpleDTOWithNestedDTOWithNullCheck()
|
||||||
|
{
|
||||||
|
SimpleDTOWithNullCheck = new SimpleDTOWithNullCheck();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Microsoft.AspNetCore.JsonPatch
|
||||||
|
{
|
||||||
|
public class SimpleDTOWithNullCheck
|
||||||
|
{
|
||||||
|
private string stringProperty;
|
||||||
|
|
||||||
|
public string StringProperty
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return stringProperty;
|
||||||
|
}
|
||||||
|
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException();
|
||||||
|
}
|
||||||
|
|
||||||
|
stringProperty = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue