diff --git a/src/Microsoft.AspNet.JsonPatch/Adapters/ObjectAdapter.cs b/src/Microsoft.AspNet.JsonPatch/Adapters/ObjectAdapter.cs index 9f95b03541..0a30834592 100644 --- a/src/Microsoft.AspNet.JsonPatch/Adapters/ObjectAdapter.cs +++ b/src/Microsoft.AspNet.JsonPatch/Adapters/ObjectAdapter.cs @@ -157,21 +157,19 @@ namespace Microsoft.AspNet.JsonPatch.Adapters } else { - throw new JsonPatchException(operationToReport, - string.Format("Patch failed: provided path is invalid for array property type at " + - "location path: {0}: position larger than array size", - path, 422), + throw new JsonPatchException( + operationToReport, + Resources.FormatInvalidIndexForArrayProperty(operationToReport.op, path), objectToApplyTo); } } } else { - throw new JsonPatchException(operationToReport, - string.Format("Patch failed: provided path is invalid for array property type at location " + - "path: {0}: expected array", - path), - objectToApplyTo, 422); + throw new JsonPatchException( + operationToReport, + Resources.FormatInvalidPathForArrayProperty(operationToReport.op, path), + objectToApplyTo); } } else @@ -247,22 +245,20 @@ namespace Microsoft.AspNet.JsonPatch.Adapters if (array.Count <= positionAsInteger) { - throw new JsonPatchException(operation, - string.Format("Patch failed: provided from path is invalid for array property type at " + - "location from: {0}: invalid position", - operation.from), - objectToApplyTo, 422); + throw new JsonPatchException( + operation, + Resources.FormatInvalidIndexForArrayProperty(operation.op, operation.from), + objectToApplyTo); } valueAtFromLocation = array[positionAsInteger]; } else { - throw new JsonPatchException(operation, - string.Format("Patch failed: provided from path is invalid for array property type at " + - "location from: {0}: expected array", - operation.from), - objectToApplyTo, 422); + throw new JsonPatchException( + operation, + Resources.FormatInvalidPathForArrayProperty(operation.op, operation.from), + objectToApplyTo); } } else @@ -356,21 +352,19 @@ namespace Microsoft.AspNet.JsonPatch.Adapters } else { - throw new JsonPatchException(operationToReport, - string.Format("Patch failed: provided path is invalid for array property type at " + - "location path: {0}: position larger than array size", - path), - objectToApplyTo, 422); + throw new JsonPatchException( + operationToReport, + Resources.FormatInvalidIndexForArrayProperty(operationToReport.op, path), + objectToApplyTo); } } } else { - throw new JsonPatchException(operationToReport, - string.Format("Patch failed: provided path is invalid for array property type at " + - "location path: {0}: expected array", - path), - objectToApplyTo, 422); + throw new JsonPatchException( + operationToReport, + Resources.FormatInvalidPathForArrayProperty(operationToReport.op, path), + objectToApplyTo); } } else @@ -477,22 +471,20 @@ namespace Microsoft.AspNet.JsonPatch.Adapters if (array.Count <= positionInPathAsInteger) { - throw new JsonPatchException(operation, - string.Format("Patch failed: provided from path is invalid for array property type at " + - "location path: {0}: invalid position", - operation.path), - objectToApplyTo, 422); + throw new JsonPatchException( + operation, + Resources.FormatInvalidIndexForArrayProperty(operation.op, operation.path), + objectToApplyTo); } valueAtPathLocation = array[positionInPathAsInteger]; } else { - throw new JsonPatchException(operation, - string.Format("Patch failed: provided from path is invalid for array property type at " + - "location path: {0}: expected array", - operation.path), - objectToApplyTo, 422); + throw new JsonPatchException( + operation, + Resources.FormatInvalidPathForArrayProperty(operation.op, operation.path), + objectToApplyTo); } } else @@ -597,21 +589,18 @@ namespace Microsoft.AspNet.JsonPatch.Adapters if (array.Count <= positionAsInteger) { throw new JsonPatchException(operation, - string.Format("Patch failed: provided from path is invalid for array property type at " + - "location from: {0}: invalid position", - operation.from), - objectToApplyTo, 422); + Resources.FormatInvalidIndexForArrayProperty(operation.op, operation.from), + objectToApplyTo); } valueAtFromLocation = array[positionAsInteger]; } else { - throw new JsonPatchException(operation, - string.Format("Patch failed: provided from path is invalid for array property type at " + - "location from: {0}: expected array", - operation.from), - objectToApplyTo, 422); + throw new JsonPatchException( + operation, + Resources.FormatInvalidPathForArrayProperty(operation.op, operation.from), + objectToApplyTo); } } else @@ -635,15 +624,15 @@ namespace Microsoft.AspNet.JsonPatch.Adapters { throw new JsonPatchException( operation, - string.Format("Patch failed: property at location {0} does not exist", propertyPath), - objectToApplyTo, 422); + Resources.FormatPropertyDoesNotExist(propertyPath), + objectToApplyTo); } if (patchProperty.Property.Ignored) { throw new JsonPatchException( operation, - string.Format("Patch failed: cannot update property at location {0}", propertyPath), - objectToApplyTo, 422); + Resources.FormatCannotUpdateProperty(propertyPath), + objectToApplyTo); } } @@ -660,10 +649,12 @@ namespace Microsoft.AspNet.JsonPatch.Adapters Operation operation, string path) { - var errorMessage = "Patch failed: provided value is invalid for property type at location path: "; if (!result.CanBeConverted) { - throw new JsonPatchException(operation, string.Format(errorMessage + "{0}", path), objectToApplyTo, 422); + throw new JsonPatchException( + operation, + Resources.FormatInvalidValueForProperty(result.ConvertedInstance, path), + objectToApplyTo); } } } diff --git a/src/Microsoft.AspNet.JsonPatch/Converters/TypedJsonPatchDocumentConverter.cs b/src/Microsoft.AspNet.JsonPatch/Converters/TypedJsonPatchDocumentConverter.cs index 8c6f9103b0..3ddee423a6 100644 --- a/src/Microsoft.AspNet.JsonPatch/Converters/TypedJsonPatchDocumentConverter.cs +++ b/src/Microsoft.AspNet.JsonPatch/Converters/TypedJsonPatchDocumentConverter.cs @@ -16,7 +16,7 @@ namespace Microsoft.AspNet.JsonPatch.Converters { public override bool CanConvert(Type objectType) { - return true; + return true; } public override object ReadJson(JsonReader reader, Type objectType, object existingValue, @@ -60,7 +60,7 @@ namespace Microsoft.AspNet.JsonPatch.Converters } catch (Exception ex) { - throw new JsonPatchException("The JsonPatchDocument was malformed and could not be parsed.", ex, 400); + throw new JsonPatchException(Resources.FormatInvalidJsonPatchDocument(objectType.Name), ex); } } diff --git a/src/Microsoft.AspNet.JsonPatch/Exceptions/JsonPatchException.cs b/src/Microsoft.AspNet.JsonPatch/Exceptions/JsonPatchException.cs index d51a0a5d47..ae9114d4d9 100644 --- a/src/Microsoft.AspNet.JsonPatch/Exceptions/JsonPatchException.cs +++ b/src/Microsoft.AspNet.JsonPatch/Exceptions/JsonPatchException.cs @@ -33,15 +33,8 @@ namespace Microsoft.AspNet.JsonPatch.Exceptions AffectedObject = affectedObject; } - public JsonPatchException(Operation operation, string message, T affectedObject, int statusCode) + public JsonPatchException(Operation operation, string message, T affectedObject, Exception innerException) : this(operation, message, affectedObject) - { - StatusCode = statusCode; - } - - public JsonPatchException(Operation operation, string message, T affectedObject, - int statusCode, Exception innerException) - : this(operation, message, affectedObject, statusCode) { InnerException = innerException; } diff --git a/src/Microsoft.AspNet.JsonPatch/Exceptions/JsonPatchExceptionBase.cs b/src/Microsoft.AspNet.JsonPatch/Exceptions/JsonPatchExceptionBase.cs index 9141a429f0..b0c2c6cacd 100644 --- a/src/Microsoft.AspNet.JsonPatch/Exceptions/JsonPatchExceptionBase.cs +++ b/src/Microsoft.AspNet.JsonPatch/Exceptions/JsonPatchExceptionBase.cs @@ -9,8 +9,6 @@ namespace Microsoft.AspNet.JsonPatch.Exceptions { public new Exception InnerException { get; internal set; } - public int StatusCode { get; internal set; } - public object AffectedObject { get; private set; } private string _message = ""; @@ -33,13 +31,5 @@ namespace Microsoft.AspNet.JsonPatch.Exceptions _message = message; InnerException = innerException; } - - - public JsonPatchException(string message, Exception innerException, int statusCode) - : this(message, innerException) - { - StatusCode = statusCode; - } - } } \ No newline at end of file diff --git a/src/Microsoft.AspNet.JsonPatch/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.JsonPatch/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..a2ce237bc4 --- /dev/null +++ b/src/Microsoft.AspNet.JsonPatch/Properties/Resources.Designer.cs @@ -0,0 +1,126 @@ +// +namespace Microsoft.AspNet.JsonPatch +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class Resources + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNet.JsonPatch.Resources", typeof(Resources).GetTypeInfo().Assembly); + + /// + /// The property at path '{0}' could not be updated. + /// + internal static string CannotUpdateProperty + { + get { return GetString("CannotUpdateProperty"); } + } + + /// + /// The property at path '{0}' could not be updated. + /// + internal static string FormatCannotUpdateProperty(object p0) + { + return string.Format(CultureInfo.CurrentCulture, GetString("CannotUpdateProperty"), p0); + } + + /// + /// For operation '{0}' on array property at path '{1}', the index is larger than the array size. + /// + internal static string InvalidIndexForArrayProperty + { + get { return GetString("InvalidIndexForArrayProperty"); } + } + + /// + /// For operation '{0}' on array property at path '{1}', the index is larger than the array size. + /// + internal static string FormatInvalidIndexForArrayProperty(object p0, object p1) + { + return string.Format(CultureInfo.CurrentCulture, GetString("InvalidIndexForArrayProperty"), p0, p1); + } + + /// + /// The type '{0}' was malformed and could not be parsed. + /// + internal static string InvalidJsonPatchDocument + { + get { return GetString("InvalidJsonPatchDocument"); } + } + + /// + /// The type '{0}' was malformed and could not be parsed. + /// + internal static string FormatInvalidJsonPatchDocument(object p0) + { + return string.Format(CultureInfo.CurrentCulture, GetString("InvalidJsonPatchDocument"), p0); + } + + /// + /// For operation '{0}', the provided path is invalid for array property at path '{1}'. + /// + internal static string InvalidPathForArrayProperty + { + get { return GetString("InvalidPathForArrayProperty"); } + } + + /// + /// For operation '{0}', the provided path is invalid for array property at path '{1}'. + /// + internal static string FormatInvalidPathForArrayProperty(object p0, object p1) + { + return string.Format(CultureInfo.CurrentCulture, GetString("InvalidPathForArrayProperty"), p0, p1); + } + + /// + /// The value '{0}' is invalid for property at path '{1}'. + /// + internal static string InvalidValueForProperty + { + get { return GetString("InvalidValueForProperty"); } + } + + /// + /// The value '{0}' is invalid for property at path '{1}'. + /// + internal static string FormatInvalidValueForProperty(object p0, object p1) + { + return string.Format(CultureInfo.CurrentCulture, GetString("InvalidValueForProperty"), p0, p1); + } + + /// + /// Property does not exist at path '{0}'. + /// + internal static string PropertyDoesNotExist + { + get { return GetString("PropertyDoesNotExist"); } + } + + /// + /// Property does not exist at path '{0}'. + /// + internal static string FormatPropertyDoesNotExist(object p0) + { + return string.Format(CultureInfo.CurrentCulture, GetString("PropertyDoesNotExist"), p0); + } + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} diff --git a/src/Microsoft.AspNet.JsonPatch/Resources.resx b/src/Microsoft.AspNet.JsonPatch/Resources.resx new file mode 100644 index 0000000000..e41ac8c272 --- /dev/null +++ b/src/Microsoft.AspNet.JsonPatch/Resources.resx @@ -0,0 +1,138 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The property at path '{0}' could not be updated. + + + For operation '{0}' on array property at path '{1}', the index is larger than the array size. + + + The type '{0}' was malformed and could not be parsed. + + + For operation '{0}', the provided path is invalid for array property at path '{1}'. + + + The value '{0}' is invalid for property at path '{1}'. + + + Property does not exist at path '{0}'. + + \ No newline at end of file diff --git a/test/Microsoft.AspNet.JsonPatch.Test/NestedObjectTests.cs b/test/Microsoft.AspNet.JsonPatch.Test/NestedObjectTests.cs index 7938090321..65e75d7d03 100644 --- a/test/Microsoft.AspNet.JsonPatch.Test/NestedObjectTests.cs +++ b/test/Microsoft.AspNet.JsonPatch.Test/NestedObjectTests.cs @@ -281,7 +281,10 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Add(o => o.SimpleDTO.IntegerList, 4, 4); // Act & Assert - Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("For operation 'add' on array property at path '/simpledto/integerlist/4', the index is " + + "larger than the array size.", exception.Message); + } [Fact] @@ -304,7 +307,12 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + var exception = Assert.Throws>(() => + { + deserialized.ApplyTo(doc); + }); + Assert.Equal("For operation 'add' on array property at path '/simpledto/integerlist/4', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -324,7 +332,8 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Add(o => o.SimpleDTO.IntegerList, 4, -1); // Act & Assert - Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message); } [Fact] @@ -347,7 +356,11 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + var exception = Assert.Throws>(() => + { + deserialized.ApplyTo(doc); + }); + Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message); } [Fact] @@ -514,7 +527,9 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Remove(o => o.SimpleDTO.IntegerList, 3); // Act & Assert - Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("For operation 'remove' on array property at path '/simpledto/integerlist/3', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -537,7 +552,12 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + var exception = Assert.Throws>(() => + { + deserialized.ApplyTo(doc); + }); + Assert.Equal("For operation 'remove' on array property at path '/simpledto/integerlist/3', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -557,7 +577,8 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Remove(o => o.SimpleDTO.IntegerList, -1); // Act & Assert - Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message); } [Fact] @@ -580,7 +601,11 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + var exception = Assert.Throws>(() => + { + deserialized.ApplyTo(doc); + }); + Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message); } [Fact] @@ -988,7 +1013,9 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Replace(o => o.SimpleDTO.IntegerList, 5, 3); // Act & Assert - Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("For operation 'replace' on array property at path '/simpledto/integerlist/3', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -1011,7 +1038,12 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + var exception = Assert.Throws>(() => + { + deserialized.ApplyTo(doc); + }); + Assert.Equal("For operation 'replace' on array property at path '/simpledto/integerlist/3', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -1031,7 +1063,8 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Replace(o => o.SimpleDTO.IntegerList, 5, -1); // Act & Assert - Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message); } [Fact] @@ -1054,7 +1087,8 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message); } [Fact] diff --git a/test/Microsoft.AspNet.JsonPatch.Test/ObjectAdapterTests.cs b/test/Microsoft.AspNet.JsonPatch.Test/ObjectAdapterTests.cs index d4dda66479..b2a21f27a6 100644 --- a/test/Microsoft.AspNet.JsonPatch.Test/ObjectAdapterTests.cs +++ b/test/Microsoft.AspNet.JsonPatch.Test/ObjectAdapterTests.cs @@ -112,7 +112,9 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Add(o => o.IntegerList, 4, 4); // Act & Assert - Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("For operation 'add' on array property at path '/integerlist/4', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -132,7 +134,9 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + Assert.Equal("For operation 'add' on array property at path '/integerlist/4', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -235,7 +239,8 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Add(o => o.IntegerList, 4, -1); // Act & Assert - Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message); } [Fact] @@ -255,7 +260,8 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message); } [Fact] @@ -401,7 +407,9 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Remove(o => o.IntegerList, 3); // Act & Assert - Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("For operation 'remove' on array property at path '/integerlist/3', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -421,7 +429,9 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + Assert.Equal("For operation 'remove' on array property at path '/integerlist/3', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -438,7 +448,8 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Remove(o => o.IntegerList, -1); // Act & Assert - Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message); } [Fact] @@ -458,7 +469,8 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + var exception = Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message); } [Fact] @@ -622,11 +634,13 @@ namespace Microsoft.AspNet.JsonPatch.Test string serialized = "{\"Operations\": [{ \"op\": \"replace\", \"path\": \"/title\", \"value\": \"New Title\"}]}"; // Act & Assert - Assert.Throws(() => + var exception = Assert.Throws(() => { var deserialized = JsonConvert.DeserializeObject>(serialized); }); + + Assert.Equal("The type 'JsonPatchDocument`1' was malformed and could not be parsed.", exception.Message); } [Fact] @@ -953,10 +967,12 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Replace(o => o.IntegerList, 5, 3); // Act & Assert - Assert.Throws>(() => + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("For operation 'replace' on array property at path '/integerlist/3', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -975,10 +991,12 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => + var exception = Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + Assert.Equal("For operation 'replace' on array property at path '/integerlist/3', the index is " + + "larger than the array size.", exception.Message); } [Fact] @@ -995,10 +1013,11 @@ namespace Microsoft.AspNet.JsonPatch.Test patchDoc.Replace(o => o.IntegerList, 5, -1); // Act & Assert - Assert.Throws>(() => + var exception = Assert.Throws>(() => { patchDoc.ApplyTo(doc); }); + Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message); } [Fact] @@ -1018,10 +1037,11 @@ namespace Microsoft.AspNet.JsonPatch.Test var deserialized = JsonConvert.DeserializeObject>(serialized); // Act & Assert - Assert.Throws>(() => + var exception = Assert.Throws>(() => { deserialized.ApplyTo(doc); }); + Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message); } [Fact]