Add tests for Replace operation with null checks for property (#56)

See #32
This commit is contained in:
Jass Bagga 2017-01-26 11:28:35 -08:00 committed by GitHub
parent e8452821b9
commit 0795ec1d9a
4 changed files with 88 additions and 0 deletions

View File

@ -907,6 +907,29 @@ namespace Microsoft.AspNetCore.JsonPatch
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]
public void ReplaceWithSerialization()
{

View File

@ -648,6 +648,26 @@ namespace Microsoft.AspNetCore.JsonPatch.Adapters
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]
public void ReplaceWithSerialization()
{

View File

@ -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();
}
}
}

View File

@ -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;
}
}
}
}