Skip to content
This repository was archived by the owner on Nov 15, 2018. It is now read-only.

Add tests for "op" Replace with null checks #56

Merged
merged 2 commits into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions test/Microsoft.AspNetCore.JsonPatch.Test/NestedObjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,29 @@ public void Replace()
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()
{
Expand Down
20 changes: 20 additions & 0 deletions test/Microsoft.AspNetCore.JsonPatch.Test/ObjectAdapterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,26 @@ public void Replace()
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()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
}
29 changes: 29 additions & 0 deletions test/Microsoft.AspNetCore.JsonPatch.Test/SimpleDTOWithNullCheck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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
{
string stringProperty;

public string StringProperty
{
get
{
return stringProperty;
}

set
{
if (value == null)
{
throw new ArgumentNullException();
}
stringProperty = value;
}
}
}
}