Refactoring to get ready for JsonPatch (for dynamics) support. Relay generic typing to outer-facing contract.
This commit is contained in:
parent
46bc7dd219
commit
580914d873
|
|
@ -7,14 +7,13 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
{
|
||||
/// <summary>
|
||||
/// Defines the operations that can be performed on a JSON patch document.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type of the model.</typeparam>
|
||||
public interface IObjectAdapter<TModel> where TModel : class
|
||||
/// </summary>
|
||||
public interface IObjectAdapter
|
||||
{
|
||||
void Add(Operation<TModel> operation, TModel objectToApplyTo);
|
||||
void Copy(Operation<TModel> operation, TModel objectToApplyTo);
|
||||
void Move(Operation<TModel> operation, TModel objectToApplyTo);
|
||||
void Remove(Operation<TModel> operation, TModel objectToApplyTo);
|
||||
void Replace(Operation<TModel> operation, TModel objectToApplyTo);
|
||||
void Add(Operation operation, object objectToApplyTo);
|
||||
void Copy(Operation operation, object objectToApplyTo);
|
||||
void Move(Operation operation, object objectToApplyTo);
|
||||
void Remove(Operation operation, object objectToApplyTo);
|
||||
void Replace(Operation operation, object objectToApplyTo);
|
||||
}
|
||||
}
|
||||
|
|
@ -15,16 +15,16 @@ using Newtonsoft.Json.Serialization;
|
|||
namespace Microsoft.AspNet.JsonPatch.Adapters
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public class ObjectAdapter<TModel> : IObjectAdapter<TModel> where TModel : class
|
||||
public class ObjectAdapter : IObjectAdapter
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="ObjectAdapter{TModel}"/>.
|
||||
/// Initializes a new instance of <see cref="ObjectAdapter"/>.
|
||||
/// </summary>
|
||||
/// <param name="contractResolver">The <see cref="IContractResolver"/>.</param>
|
||||
/// <param name="logErrorAction">The <see cref="Action"/> for logging <see cref="JsonPatchError{TModel}"/>.</param>
|
||||
/// <param name="logErrorAction">The <see cref="Action"/> for logging <see cref="JsonPatchError"/>.</param>
|
||||
public ObjectAdapter(
|
||||
[NotNull] IContractResolver contractResolver,
|
||||
Action<JsonPatchError<TModel>> logErrorAction)
|
||||
Action<JsonPatchError> logErrorAction)
|
||||
{
|
||||
ContractResolver = contractResolver;
|
||||
LogErrorAction = logErrorAction;
|
||||
|
|
@ -36,9 +36,9 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
public IContractResolver ContractResolver { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Action for logging <see cref="JsonPatchError{TModel}"/>.
|
||||
/// Action for logging <see cref="JsonPatchError"/>.
|
||||
/// </summary>
|
||||
public Action<JsonPatchError<TModel>> LogErrorAction { get; }
|
||||
public Action<JsonPatchError> LogErrorAction { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The "add" operation performs one of the following functions,
|
||||
|
|
@ -100,7 +100,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
/// </summary>
|
||||
/// <param name="operation">The add operation.</param>
|
||||
/// <param name="objectToApplyTo">Object to apply the operation to.</param>
|
||||
public void Add([NotNull] Operation<TModel> operation, [NotNull] TModel objectToApplyTo)
|
||||
public void Add([NotNull] Operation operation, [NotNull] object objectToApplyTo)
|
||||
{
|
||||
Add(operation.path, operation.value, objectToApplyTo, operation);
|
||||
}
|
||||
|
|
@ -112,8 +112,8 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
private void Add(
|
||||
[NotNull] string path,
|
||||
object value,
|
||||
[NotNull] TModel objectToApplyTo,
|
||||
[NotNull] Operation<TModel> operationToReport)
|
||||
[NotNull] object objectToApplyTo,
|
||||
[NotNull] Operation operationToReport)
|
||||
{
|
||||
// add, in this implementation, does not just "add" properties - that's
|
||||
// technically impossible; It can however be used to add items to arrays,
|
||||
|
|
@ -184,7 +184,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
}
|
||||
else
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operationToReport,
|
||||
Resources.FormatInvalidIndexForArrayProperty(operationToReport.op, path)));
|
||||
|
|
@ -195,7 +195,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
}
|
||||
else
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operationToReport,
|
||||
Resources.FormatInvalidIndexForArrayProperty(operationToReport.op, path)));
|
||||
|
|
@ -244,7 +244,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
/// </summary>
|
||||
/// <param name="operation">The move operation.</param>
|
||||
/// <param name="objectToApplyTo">Object to apply the operation to.</param>
|
||||
public void Move([NotNull] Operation<TModel> operation, [NotNull] TModel objectToApplyTo)
|
||||
public void Move([NotNull] Operation operation, [NotNull] object objectToApplyTo)
|
||||
{
|
||||
// get value at from location
|
||||
object valueAtFromLocation = null;
|
||||
|
|
@ -281,7 +281,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
|
||||
if (array.Count <= positionAsInteger)
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operation,
|
||||
Resources.FormatInvalidIndexForArrayProperty(operation.op, operation.from)));
|
||||
|
|
@ -293,7 +293,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
}
|
||||
else
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operation,
|
||||
Resources.FormatInvalidPathForArrayProperty(operation.op, operation.from)));
|
||||
|
|
@ -329,7 +329,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
/// </summary>
|
||||
/// <param name="operation">The remove operation.</param>
|
||||
/// <param name="objectToApplyTo">Object to apply the operation to.</param>
|
||||
public void Remove([NotNull] Operation<TModel> operation, [NotNull] TModel objectToApplyTo)
|
||||
public void Remove([NotNull] Operation operation, [NotNull] object objectToApplyTo)
|
||||
{
|
||||
Remove(operation.path, objectToApplyTo, operation);
|
||||
}
|
||||
|
|
@ -340,8 +340,8 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
/// </summary>
|
||||
private void Remove(
|
||||
[NotNull] string path,
|
||||
[NotNull] TModel objectToApplyTo,
|
||||
[NotNull] Operation<TModel> operationToReport)
|
||||
[NotNull] object objectToApplyTo,
|
||||
[NotNull] Operation operationToReport)
|
||||
{
|
||||
var removeFromList = false;
|
||||
var positionAsInteger = -1;
|
||||
|
|
@ -397,7 +397,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
}
|
||||
else
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operationToReport,
|
||||
Resources.FormatInvalidIndexForArrayProperty(operationToReport.op, path)));
|
||||
|
|
@ -408,7 +408,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
}
|
||||
else
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operationToReport,
|
||||
Resources.FormatInvalidPathForArrayProperty(operationToReport.op, path)));
|
||||
|
|
@ -452,7 +452,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
/// </summary>
|
||||
/// <param name="operation">The replace operation.</param>
|
||||
/// <param name="objectToApplyTo">Object to apply the operation to.</param>
|
||||
public void Replace([NotNull] Operation<TModel> operation, [NotNull] TModel objectToApplyTo)
|
||||
public void Replace([NotNull] Operation operation, [NotNull] object objectToApplyTo)
|
||||
{
|
||||
Remove(operation.path, objectToApplyTo, operation);
|
||||
Add(operation.path, operation.value, objectToApplyTo, operation);
|
||||
|
|
@ -480,7 +480,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
/// </summary>
|
||||
/// <param name="operation">The copy operation.</param>
|
||||
/// <param name="objectToApplyTo">Object to apply the operation to.</param>
|
||||
public void Copy([NotNull] Operation<TModel> operation, [NotNull] TModel objectToApplyTo)
|
||||
public void Copy([NotNull] Operation operation, [NotNull] object objectToApplyTo)
|
||||
{
|
||||
// get value at from location
|
||||
object valueAtFromLocation = null;
|
||||
|
|
@ -518,7 +518,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
|
||||
if (array.Count <= positionAsInteger)
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operation,
|
||||
Resources.FormatInvalidIndexForArrayProperty(operation.op, operation.from)));
|
||||
|
|
@ -530,7 +530,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
}
|
||||
else
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operation,
|
||||
Resources.FormatInvalidPathForArrayProperty(operation.op, operation.from)));
|
||||
|
|
@ -551,13 +551,13 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
|
||||
private bool CheckIfPropertyExists(
|
||||
JsonPatchProperty patchProperty,
|
||||
TModel objectToApplyTo,
|
||||
Operation<TModel> operation,
|
||||
object objectToApplyTo,
|
||||
Operation operation,
|
||||
string propertyPath)
|
||||
{
|
||||
if (patchProperty == null)
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operation,
|
||||
Resources.FormatPropertyDoesNotExist(propertyPath)));
|
||||
|
|
@ -567,7 +567,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
|
||||
if (patchProperty.Property.Ignored)
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operation,
|
||||
Resources.FormatCannotUpdateProperty(propertyPath)));
|
||||
|
|
@ -590,13 +590,13 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
|
||||
private bool CheckIfPropertyCanBeSet(
|
||||
ConversionResult result,
|
||||
TModel objectToApplyTo,
|
||||
Operation<TModel> operation,
|
||||
object objectToApplyTo,
|
||||
Operation operation,
|
||||
string path)
|
||||
{
|
||||
if (!result.CanBeConverted)
|
||||
{
|
||||
LogError(new JsonPatchError<TModel>(
|
||||
LogError(new JsonPatchError(
|
||||
objectToApplyTo,
|
||||
operation,
|
||||
Resources.FormatInvalidValueForProperty(result.ConvertedInstance, path)));
|
||||
|
|
@ -607,7 +607,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
return true;
|
||||
}
|
||||
|
||||
private void LogError(JsonPatchError<TModel> jsonPatchError)
|
||||
private void LogError(JsonPatchError jsonPatchError)
|
||||
{
|
||||
if (LogErrorAction != null)
|
||||
{
|
||||
|
|
@ -615,7 +615,7 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new JsonPatchException<TModel>(jsonPatchError);
|
||||
throw new JsonPatchException(jsonPatchError);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ namespace Microsoft.AspNet.JsonPatch.Converters
|
|||
var targetOperations = Activator.CreateInstance(concreteList);
|
||||
|
||||
//Create a new reader for this jObject, and set all properties to match the original reader.
|
||||
JsonReader jObjectReader = jObject.CreateReader();
|
||||
var jObjectReader = jObject.CreateReader();
|
||||
jObjectReader.Culture = reader.Culture;
|
||||
jObjectReader.DateParseHandling = reader.DateParseHandling;
|
||||
jObjectReader.DateTimeZoneHandling = reader.DateTimeZoneHandling;
|
||||
|
|
|
|||
|
|
@ -3,42 +3,36 @@
|
|||
|
||||
using System;
|
||||
using Microsoft.AspNet.JsonPatch.Operations;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
||||
namespace Microsoft.AspNet.JsonPatch.Exceptions
|
||||
{
|
||||
public class JsonPatchException<TModel> : JsonPatchException where TModel : class
|
||||
public class JsonPatchException : Exception
|
||||
{
|
||||
public Operation<TModel> FailedOperation { get; private set; }
|
||||
public new TModel AffectedObject { get; private set; }
|
||||
|
||||
private string _message = string.Empty;
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
return _message;
|
||||
}
|
||||
|
||||
}
|
||||
public Operation FailedOperation { get; private set; }
|
||||
public object AffectedObject { get; private set; }
|
||||
|
||||
|
||||
public JsonPatchException()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public JsonPatchException([NotNull] JsonPatchError<TModel> jsonPatchError)
|
||||
public JsonPatchException(JsonPatchError jsonPatchError, Exception innerException)
|
||||
: base(jsonPatchError.ErrorMessage, innerException)
|
||||
{
|
||||
FailedOperation = jsonPatchError.Operation;
|
||||
_message = jsonPatchError.ErrorMessage;
|
||||
AffectedObject = jsonPatchError.AffectedObject;
|
||||
}
|
||||
|
||||
public JsonPatchException([NotNull] JsonPatchError<TModel> jsonPatchError, Exception innerException)
|
||||
: this(jsonPatchError)
|
||||
public JsonPatchException(JsonPatchError jsonPatchError)
|
||||
: this(jsonPatchError, null)
|
||||
{
|
||||
InnerException = innerException;
|
||||
}
|
||||
|
||||
public JsonPatchException(string message, Exception innerException)
|
||||
: base (message, innerException)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
// 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.AspNet.JsonPatch.Exceptions
|
||||
{
|
||||
public class JsonPatchException : Exception
|
||||
{
|
||||
public new Exception InnerException { get; internal set; }
|
||||
|
||||
public object AffectedObject { get; private set; }
|
||||
|
||||
private string _message = string.Empty;
|
||||
|
||||
public override string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
return _message;
|
||||
}
|
||||
}
|
||||
|
||||
public JsonPatchException()
|
||||
{
|
||||
}
|
||||
|
||||
public JsonPatchException(string message, Exception innerException)
|
||||
{
|
||||
_message = message;
|
||||
InnerException = innerException;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,10 +32,8 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
ContractResolver = new DefaultContractResolver();
|
||||
}
|
||||
|
||||
// Create from list of operations.
|
||||
public JsonPatchDocument(
|
||||
[NotNull] List<Operation<TModel>> operations,
|
||||
[NotNull] IContractResolver contractResolver)
|
||||
// Create from list of operations
|
||||
public JsonPatchDocument([NotNull] List<Operation<TModel>> operations, [NotNull] IContractResolver contractResolver)
|
||||
{
|
||||
Operations = operations;
|
||||
ContractResolver = contractResolver;
|
||||
|
|
@ -45,10 +43,10 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
/// Add operation. Will result in, for example,
|
||||
/// { "op": "add", "path": "/a/b/c", "value": [ "foo", "bar" ] }
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="path">The path of the property to add.</param>
|
||||
/// <param name="value">The value to add.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp">value type</typeparam>
|
||||
/// <param name="path">path</param>
|
||||
/// <param name="value">value</param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Add<TProp>([NotNull] Expression<Func<TModel, TProp>> path, TProp value)
|
||||
{
|
||||
Operations.Add(new Operation<TModel>(
|
||||
|
|
@ -61,13 +59,13 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add value to list at given position.
|
||||
/// Add value to list at given position
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="path">The path of the property to add.</param>
|
||||
/// <param name="value">The value to add.</param>
|
||||
/// <typeparam name="TProp">value type</typeparam>
|
||||
/// <param name="path">path</param>
|
||||
/// <param name="value">value</param>
|
||||
/// <param name="position">position</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Add<TProp>(
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
|
||||
TProp value,
|
||||
|
|
@ -83,12 +81,12 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// At value at end of list.
|
||||
/// At value at end of list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="path">The path of the property to add.</param>
|
||||
/// <param name="value">The value to add.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp">value type</typeparam>
|
||||
/// <param name="path">path</param>
|
||||
/// <param name="value">value</param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Add<TProp>([NotNull] Expression<Func<TModel, IList<TProp>>> path, TProp value)
|
||||
{
|
||||
Operations.Add(new Operation<TModel>(
|
||||
|
|
@ -104,26 +102,24 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
/// Remove value at target location. Will result in, for example,
|
||||
/// { "op": "remove", "path": "/a/b/c" }
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the property to remove.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <param name="remove"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Remove<TProp>([NotNull] Expression<Func<TModel, TProp>> path)
|
||||
{
|
||||
Operations.Add(
|
||||
new Operation<TModel>("remove", ExpressionHelpers.GetPath(path).ToLowerInvariant(), from: null));
|
||||
Operations.Add(new Operation<TModel>("remove", ExpressionHelpers.GetPath(path).ToLowerInvariant(), from: null));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove value from list at given position.
|
||||
/// Remove value from list at given position
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="path">The path of the property to remove.</param>
|
||||
/// <param name="position">The position in the list.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
public JsonPatchDocument<TModel> Remove<TProp>(
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
|
||||
int position)
|
||||
/// <typeparam name="TProp">value type</typeparam>
|
||||
/// <param name="path">target location</param>
|
||||
/// <param name="position">position</param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Remove<TProp>([NotNull] Expression<Func<TModel, IList<TProp>>> path, int position)
|
||||
{
|
||||
Operations.Add(new Operation<TModel>(
|
||||
"remove",
|
||||
|
|
@ -134,11 +130,11 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove value from end of list.
|
||||
/// Remove value from end of list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="path">The path of the property to remove.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp">value type</typeparam>
|
||||
/// <param name="path">target location</param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Remove<TProp>([NotNull] Expression<Func<TModel, IList<TProp>>> path)
|
||||
{
|
||||
Operations.Add(new Operation<TModel>(
|
||||
|
|
@ -153,9 +149,9 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
/// Replace value. Will result in, for example,
|
||||
/// { "op": "replace", "path": "/a/b/c", "value": 42 }
|
||||
/// </summary>
|
||||
/// <param name="path">The path of the property to replace.</param>
|
||||
/// <param name="value">The value to replace.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Replace<TProp>([NotNull] Expression<Func<TModel, TProp>> path, TProp value)
|
||||
{
|
||||
Operations.Add(new Operation<TModel>(
|
||||
|
|
@ -168,16 +164,14 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace value in a list at given position.
|
||||
/// Replace value in a list at given position
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="path">The path of the property to replace.</param>
|
||||
/// <param name="position">The position in the list.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
public JsonPatchDocument<TModel> Replace<TProp>(
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
|
||||
TProp value,
|
||||
int position)
|
||||
/// <typeparam name="TProp">value type</typeparam>
|
||||
/// <param name="path">target location</param>
|
||||
/// <param name="position">position</param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Replace<TProp>([NotNull] Expression<Func<TModel, IList<TProp>>> path,
|
||||
TProp value, int position)
|
||||
{
|
||||
Operations.Add(new Operation<TModel>(
|
||||
"replace",
|
||||
|
|
@ -189,14 +183,12 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Replace value at end of a list.
|
||||
/// Replace value at end of a list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="path">The path of the property to replace.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
public JsonPatchDocument<TModel> Replace<TProp>(
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
|
||||
TProp value)
|
||||
/// <typeparam name="TProp">value type</typeparam>
|
||||
/// <param name="path">target location</param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Replace<TProp>([NotNull] Expression<Func<TModel, IList<TProp>>> path, TProp value)
|
||||
{
|
||||
Operations.Add(new Operation<TModel>(
|
||||
"replace",
|
||||
|
|
@ -211,9 +203,9 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
/// Removes value at specified location and add it to the target location. Will result in, for example:
|
||||
/// { "op": "move", "from": "/a/b/c", "path": "/a/b/d" }
|
||||
/// </summary>
|
||||
/// <param name="from">The path of the property to remove.</param>
|
||||
/// <param name="path">The path of the property to add.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Move<TProp>(
|
||||
[NotNull] Expression<Func<TModel, TProp>> from,
|
||||
[NotNull] Expression<Func<TModel, TProp>> path)
|
||||
|
|
@ -227,13 +219,13 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move from a position in a list to a new location.
|
||||
/// Move from a position in a list to a new location
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="from">The path of the property to remove.</param>
|
||||
/// <param name="positionFrom">The position in the list to remove.</param>
|
||||
/// <param name="path">The path of the property to add.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="positionFrom"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Move<TProp>(
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
|
||||
int positionFrom,
|
||||
|
|
@ -248,13 +240,13 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move from a property to a location in a list.
|
||||
/// Move from a property to a location in a list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="from">The path of the property to remove.</param>
|
||||
/// <param name="path">The path of the property to add.</param>
|
||||
/// <param name="positionTo">The position in the list to add.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="positionFrom"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Move<TProp>(
|
||||
[NotNull] Expression<Func<TModel, TProp>> from,
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
|
||||
|
|
@ -269,14 +261,13 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move from a position in a list to another location in a list.
|
||||
/// Move from a position in a list to another location in a list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="from">The path of the property to remove.</param>
|
||||
/// <param name="positionFrom">The position in the list to remove.</param>
|
||||
/// <param name="path">The path of the property to add.</param>
|
||||
/// <param name="positionTo">The position in the list to add.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="positionFrom"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Move<TProp>(
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
|
||||
int positionFrom,
|
||||
|
|
@ -292,13 +283,13 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move from a position in a list to the end of another list.
|
||||
/// Move from a position in a list to the end of another list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="from">The path of the property to remove.</param>
|
||||
/// <param name="positionFrom">The position in the list to remove.</param>
|
||||
/// <param name="path">The path of the property to add.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="positionFrom"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Move<TProp>(
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
|
||||
int positionFrom,
|
||||
|
|
@ -313,15 +304,16 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Move to the end of a list.
|
||||
/// Move to the end of a list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="from">The path of the property to remove.</param>
|
||||
/// <param name="path">The path of the property to add.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="positionFrom"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Move<TProp>(
|
||||
[NotNull] Expression<Func<TModel, TProp>> from,
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> path)
|
||||
[NotNull] Expression<Func<TModel, TProp>> from,
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> path)
|
||||
{
|
||||
Operations.Add(new Operation<TModel>(
|
||||
"move",
|
||||
|
|
@ -332,15 +324,15 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the value at specified location to the target location. Will result in, for example:
|
||||
/// Copy the value at specified location to the target location. Willr esult in, for example:
|
||||
/// { "op": "copy", "from": "/a/b/c", "path": "/a/b/e" }
|
||||
/// </summary>
|
||||
/// <param name="from">The path of the property to copy from.</param>
|
||||
/// <param name="path">The path of the property to copy to.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Copy<TProp>(
|
||||
[NotNull] Expression<Func<TModel, TProp>> from,
|
||||
[NotNull] Expression<Func<TModel, TProp>> path)
|
||||
[NotNull] Expression<Func<TModel, TProp>> from,
|
||||
[NotNull] Expression<Func<TModel, TProp>> path)
|
||||
{
|
||||
Operations.Add(new Operation<TModel>(
|
||||
"copy",
|
||||
|
|
@ -351,17 +343,17 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy from a position in a list to a new location.
|
||||
/// Copy from a position in a list to a new location
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="from">The path of the property to copy from.</param>
|
||||
/// <param name="positionFrom">The position in the list to copy from.</param>
|
||||
/// <param name="path">The path of the property to copy to.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="positionFrom"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Copy<TProp>(
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
|
||||
int positionFrom,
|
||||
[NotNull] Expression<Func<TModel, TProp>> path)
|
||||
[NotNull] Expression<Func<TModel, TProp>> path)
|
||||
{
|
||||
Operations.Add(new Operation<TModel>(
|
||||
"copy",
|
||||
|
|
@ -372,13 +364,13 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy from a property to a location in a list.
|
||||
/// Copy from a property to a location in a list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="from">The path of the property to copy from.</param>
|
||||
/// <param name="path">The path of the property to copy to.</param>
|
||||
/// <param name="positionTo">The position in the list to copy to.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="positionFrom"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Copy<TProp>(
|
||||
[NotNull] Expression<Func<TModel, TProp>> from,
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> path,
|
||||
|
|
@ -393,14 +385,13 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy from a position in a list to a new location in a list.
|
||||
/// Copy from a position in a list to a new location in a list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="from">The path of the property to copy from.</param>
|
||||
/// <param name="positionFrom">The position in the list to copy from.</param>
|
||||
/// <param name="path">The path of the property to copy to.</param>
|
||||
/// <param name="positionTo">The position in the list to copy to.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="positionFrom"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Copy<TProp>(
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
|
||||
int positionFrom,
|
||||
|
|
@ -416,13 +407,13 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy from a position in a list to the end of another list.
|
||||
/// Copy from a position in a list to the end of another list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="from">The path of the property to copy from.</param>
|
||||
/// <param name="positionFrom">The position in the list to copy from.</param>
|
||||
/// <param name="path">The path of the property to copy to.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="positionFrom"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Copy<TProp>(
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> from,
|
||||
int positionFrom,
|
||||
|
|
@ -437,12 +428,13 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy to the end of a list.
|
||||
/// Copy to the end of a list
|
||||
/// </summary>
|
||||
/// <typeparam name="TProp">The value type.</typeparam>
|
||||
/// <param name="from">The path of the property to copy from.</param>
|
||||
/// <param name="path">The path of the property to copy to.</param>
|
||||
/// <returns>The <see cref="JsonPatchDocument{TModel}"/>.</returns>
|
||||
/// <typeparam name="TProp"></typeparam>
|
||||
/// <param name="from"></param>
|
||||
/// <param name="positionFrom"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public JsonPatchDocument<TModel> Copy<TProp>(
|
||||
[NotNull] Expression<Func<TModel, TProp>> from,
|
||||
[NotNull] Expression<Func<TModel, IList<TProp>>> path)
|
||||
|
|
@ -455,17 +447,17 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
return this;
|
||||
}
|
||||
|
||||
public void ApplyTo([NotNull] TModel objectToApplyTo)
|
||||
public void ApplyTo(TModel objectToApplyTo)
|
||||
{
|
||||
ApplyTo(objectToApplyTo, new ObjectAdapter<TModel>(ContractResolver, logErrorAction: null));
|
||||
ApplyTo(objectToApplyTo, new ObjectAdapter(ContractResolver, logErrorAction: null));
|
||||
}
|
||||
|
||||
public void ApplyTo([NotNull] TModel objectToApplyTo, Action<JsonPatchError<TModel>> logErrorAction)
|
||||
public void ApplyTo(TModel objectToApplyTo, Action<JsonPatchError> logErrorAction)
|
||||
{
|
||||
ApplyTo(objectToApplyTo, new ObjectAdapter<TModel>(ContractResolver, logErrorAction));
|
||||
ApplyTo(objectToApplyTo, new ObjectAdapter(ContractResolver, logErrorAction));
|
||||
}
|
||||
|
||||
public void ApplyTo([NotNull] TModel objectToApplyTo, [NotNull] IObjectAdapter<TModel> adapter)
|
||||
public void ApplyTo(TModel objectToApplyTo, IObjectAdapter adapter)
|
||||
{
|
||||
// apply each operation in order
|
||||
foreach (var op in Operations)
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
/// <summary>
|
||||
/// Captures error message and the related entity and the operation that caused it.
|
||||
/// </summary>
|
||||
public class JsonPatchError<TModel> where TModel : class
|
||||
public class JsonPatchError
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of <see cref="JsonPatchError{TModel}"/>.
|
||||
/// Initializes a new instance of <see cref="JsonPatchError"/>.
|
||||
/// </summary>
|
||||
/// <param name="affectedObject">The object that is affected by the error.</param>
|
||||
/// <param name="operation">The <see cref="Operation{TModel}"/> that caused the error.</param>
|
||||
/// <param name="operation">The <see cref="Operation"/> that caused the error.</param>
|
||||
/// <param name="errorMessage">The error message.</param>
|
||||
public JsonPatchError(
|
||||
[NotNull] TModel affectedObject,
|
||||
[NotNull] Operation<TModel> operation,
|
||||
object affectedObject,
|
||||
Operation operation,
|
||||
[NotNull] string errorMessage)
|
||||
{
|
||||
AffectedObject = affectedObject;
|
||||
|
|
@ -30,12 +30,12 @@ namespace Microsoft.AspNet.JsonPatch
|
|||
/// <summary>
|
||||
/// Gets the object that is affected by the error.
|
||||
/// </summary>
|
||||
public TModel AffectedObject { get; }
|
||||
public object AffectedObject { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Operation{TModel}"/> that caused the error.
|
||||
/// Gets the <see cref="Operation"/> that caused the error.
|
||||
/// </summary>
|
||||
public Operation<TModel> Operation { get; }
|
||||
public Operation Operation { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the error message.
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Microsoft.AspNet.JsonPatch.Operations
|
|||
|
||||
}
|
||||
|
||||
public void Apply([NotNull] TModel objectToApplyTo, [NotNull] IObjectAdapter<TModel> adapter)
|
||||
public void Apply([NotNull] TModel objectToApplyTo, [NotNull] IObjectAdapter adapter)
|
||||
{
|
||||
switch (OperationType)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -385,7 +385,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Add<int>(o => o.SimpleDTO.IntegerList, 4, 4);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
|
||||
Assert.Equal(
|
||||
"For operation 'add' on array property at path '/simpledto/integerlist/4', the index is " +
|
||||
"larger than the array size.",
|
||||
|
|
@ -413,7 +413,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException>(() =>
|
||||
{
|
||||
deserialized.ApplyTo(doc);
|
||||
});
|
||||
|
|
@ -441,8 +441,8 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
|
||||
var logger = new TestErrorLogger<SimpleDTOWithNestedDTO>();
|
||||
|
||||
// Act
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
|
||||
//Assert
|
||||
Assert.Equal(
|
||||
|
|
@ -469,7 +469,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Add<int>(o => o.SimpleDTO.IntegerList, 4, -1);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
|
||||
Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message);
|
||||
}
|
||||
|
||||
|
|
@ -493,7 +493,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException>(() =>
|
||||
{
|
||||
deserialized.ApplyTo(doc);
|
||||
});
|
||||
|
|
@ -518,9 +518,10 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
|
||||
var logger = new TestErrorLogger<SimpleDTOWithNestedDTO>();
|
||||
|
||||
// Act
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
|
||||
//Assert
|
||||
Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", logger.ErrorMessage);
|
||||
}
|
||||
|
|
@ -689,7 +690,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Remove<int>(o => o.SimpleDTO.IntegerList, 3);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
|
||||
Assert.Equal(
|
||||
"For operation 'remove' on array property at path '/simpledto/integerlist/3', the index is " +
|
||||
"larger than the array size.",
|
||||
|
|
@ -716,7 +717,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException>(() =>
|
||||
{
|
||||
deserialized.ApplyTo(doc);
|
||||
});
|
||||
|
|
@ -743,10 +744,9 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Remove<int>(o => o.SimpleDTO.IntegerList, 3);
|
||||
|
||||
var logger = new TestErrorLogger<SimpleDTOWithNestedDTO>();
|
||||
|
||||
// Act
|
||||
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
|
||||
// Assert
|
||||
Assert.Equal(
|
||||
"For operation 'remove' on array property at path '/simpledto/integerlist/3', the index is " +
|
||||
|
|
@ -771,7 +771,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Remove<int>(o => o.SimpleDTO.IntegerList, -1);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
|
||||
Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message);
|
||||
}
|
||||
|
||||
|
|
@ -795,7 +795,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException>(() =>
|
||||
{
|
||||
deserialized.ApplyTo(doc);
|
||||
});
|
||||
|
|
@ -820,9 +820,9 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
|
||||
var logger = new TestErrorLogger<SimpleDTOWithNestedDTO>();
|
||||
|
||||
// Act
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", logger.ErrorMessage);
|
||||
}
|
||||
|
|
@ -1232,7 +1232,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Replace<int>(o => o.SimpleDTO.IntegerList, 5, 3);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
|
||||
Assert.Equal(
|
||||
"For operation 'replace' on array property at path '/simpledto/integerlist/3', the index is " +
|
||||
"larger than the array size.",
|
||||
|
|
@ -1259,7 +1259,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException>(() =>
|
||||
{
|
||||
deserialized.ApplyTo(doc);
|
||||
});
|
||||
|
|
@ -1287,8 +1287,9 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
|
||||
var logger = new TestErrorLogger<SimpleDTOWithNestedDTO>();
|
||||
|
||||
// Act
|
||||
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
|
||||
// Assert
|
||||
Assert.Equal(
|
||||
|
|
@ -1314,7 +1315,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Replace<int>(o => o.SimpleDTO.IntegerList, 5, -1);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
|
||||
Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message);
|
||||
}
|
||||
|
||||
|
|
@ -1338,7 +1339,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { deserialized.ApplyTo(doc); });
|
||||
Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message);
|
||||
}
|
||||
|
||||
|
|
@ -1360,8 +1361,9 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
|
||||
var logger = new TestErrorLogger<SimpleDTOWithNestedDTO>();
|
||||
|
||||
// Act
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", logger.ErrorMessage);
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Add<int>(o => o.IntegerList, 4, 4);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
|
||||
Assert.Equal(
|
||||
"For operation 'add' on array property at path '/integerlist/4', the index is " +
|
||||
"larger than the array size.",
|
||||
|
|
@ -179,7 +179,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { deserialized.ApplyTo(doc); });
|
||||
Assert.Equal(
|
||||
"For operation 'add' on array property at path '/integerlist/4', the index is " +
|
||||
"larger than the array size.",
|
||||
|
|
@ -201,8 +201,8 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
|
||||
var logger = new TestErrorLogger<SimpleDTO>();
|
||||
|
||||
// Act
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
|
||||
// Assert
|
||||
Assert.Equal(
|
||||
|
|
@ -311,7 +311,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Add<int>(o => o.IntegerList, 4, -1);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
|
||||
Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message);
|
||||
}
|
||||
|
||||
|
|
@ -332,7 +332,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { deserialized.ApplyTo(doc); });
|
||||
Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message);
|
||||
}
|
||||
|
||||
|
|
@ -351,9 +351,8 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
|
||||
var logger = new TestErrorLogger<SimpleDTO>();
|
||||
|
||||
// Act
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Property does not exist at path '/integerlist/-1'.", logger.ErrorMessage);
|
||||
}
|
||||
|
|
@ -501,7 +500,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Remove<int>(o => o.IntegerList, 3);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
|
||||
Assert.Equal(
|
||||
"For operation 'remove' on array property at path '/integerlist/3', the index is " +
|
||||
"larger than the array size.",
|
||||
|
|
@ -525,7 +524,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { deserialized.ApplyTo(doc); });
|
||||
Assert.Equal(
|
||||
"For operation 'remove' on array property at path '/integerlist/3', the index is " +
|
||||
"larger than the array size.",
|
||||
|
|
@ -547,8 +546,8 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
|
||||
var logger = new TestErrorLogger<SimpleDTO>();
|
||||
|
||||
// Act
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
|
||||
// Assert
|
||||
Assert.Equal(
|
||||
|
|
@ -571,7 +570,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Remove<int>(o => o.IntegerList, -1);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
|
||||
Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message);
|
||||
}
|
||||
|
||||
|
|
@ -592,7 +591,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException>(() => { deserialized.ApplyTo(doc); });
|
||||
Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message);
|
||||
}
|
||||
|
||||
|
|
@ -611,8 +610,9 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
|
||||
var logger = new TestErrorLogger<SimpleDTO>();
|
||||
|
||||
// Act
|
||||
|
||||
patchDoc.ApplyTo(doc, logger.LogErrorMessage);
|
||||
|
||||
|
||||
// Assert
|
||||
Assert.Equal("Property does not exist at path '/integerlist/-1'.", logger.ErrorMessage);
|
||||
|
|
@ -1112,7 +1112,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Replace<int>(o => o.IntegerList, 5, 3);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException>(() =>
|
||||
{
|
||||
patchDoc.ApplyTo(doc);
|
||||
});
|
||||
|
|
@ -1138,7 +1138,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException>(() =>
|
||||
{
|
||||
deserialized.ApplyTo(doc);
|
||||
});
|
||||
|
|
@ -1162,7 +1162,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Replace<int>(o => o.IntegerList, 5, -1);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException>(() =>
|
||||
{
|
||||
patchDoc.ApplyTo(doc);
|
||||
});
|
||||
|
|
@ -1186,7 +1186,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException>(() =>
|
||||
{
|
||||
deserialized.ApplyTo(doc);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
{
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
public void LogErrorMessage(JsonPatchError<T> patchError)
|
||||
public void LogErrorMessage(JsonPatchError patchError)
|
||||
{
|
||||
ErrorMessage = patchError.ErrorMessage;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue