Moved exception messages to resource file and updated tests to validate exception messages
This commit is contained in:
parent
a001cd4f2a
commit
9f97d25e02
|
|
@ -157,21 +157,19 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new JsonPatchException<T>(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<T>(
|
||||
operationToReport,
|
||||
Resources.FormatInvalidIndexForArrayProperty(operationToReport.op, path),
|
||||
objectToApplyTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonPatchException<T>(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<T>(
|
||||
operationToReport,
|
||||
Resources.FormatInvalidPathForArrayProperty(operationToReport.op, path),
|
||||
objectToApplyTo);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -247,22 +245,20 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
|
||||
if (array.Count <= positionAsInteger)
|
||||
{
|
||||
throw new JsonPatchException<T>(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<T>(
|
||||
operation,
|
||||
Resources.FormatInvalidIndexForArrayProperty(operation.op, operation.from),
|
||||
objectToApplyTo);
|
||||
}
|
||||
|
||||
valueAtFromLocation = array[positionAsInteger];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonPatchException<T>(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<T>(
|
||||
operation,
|
||||
Resources.FormatInvalidPathForArrayProperty(operation.op, operation.from),
|
||||
objectToApplyTo);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -356,21 +352,19 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
}
|
||||
else
|
||||
{
|
||||
throw new JsonPatchException<T>(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<T>(
|
||||
operationToReport,
|
||||
Resources.FormatInvalidIndexForArrayProperty(operationToReport.op, path),
|
||||
objectToApplyTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonPatchException<T>(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<T>(
|
||||
operationToReport,
|
||||
Resources.FormatInvalidPathForArrayProperty(operationToReport.op, path),
|
||||
objectToApplyTo);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -477,22 +471,20 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
|
||||
if (array.Count <= positionInPathAsInteger)
|
||||
{
|
||||
throw new JsonPatchException<T>(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<T>(
|
||||
operation,
|
||||
Resources.FormatInvalidIndexForArrayProperty(operation.op, operation.path),
|
||||
objectToApplyTo);
|
||||
}
|
||||
|
||||
valueAtPathLocation = array[positionInPathAsInteger];
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new JsonPatchException<T>(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<T>(
|
||||
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<T>(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<T>(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<T>(
|
||||
operation,
|
||||
Resources.FormatInvalidPathForArrayProperty(operation.op, operation.from),
|
||||
objectToApplyTo);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
@ -635,15 +624,15 @@ namespace Microsoft.AspNet.JsonPatch.Adapters
|
|||
{
|
||||
throw new JsonPatchException<T>(
|
||||
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<T>(
|
||||
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<T> operation,
|
||||
string path)
|
||||
{
|
||||
var errorMessage = "Patch failed: provided value is invalid for property type at location path: ";
|
||||
if (!result.CanBeConverted)
|
||||
{
|
||||
throw new JsonPatchException<T>(operation, string.Format(errorMessage + "{0}", path), objectToApplyTo, 422);
|
||||
throw new JsonPatchException<T>(
|
||||
operation,
|
||||
Resources.FormatInvalidValueForProperty(result.ConvertedInstance, path),
|
||||
objectToApplyTo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,15 +33,8 @@ namespace Microsoft.AspNet.JsonPatch.Exceptions
|
|||
AffectedObject = affectedObject;
|
||||
}
|
||||
|
||||
public JsonPatchException(Operation<T> operation, string message, T affectedObject, int statusCode)
|
||||
public JsonPatchException(Operation<T> operation, string message, T affectedObject, Exception innerException)
|
||||
: this(operation, message, affectedObject)
|
||||
{
|
||||
StatusCode = statusCode;
|
||||
}
|
||||
|
||||
public JsonPatchException(Operation<T> operation, string message, T affectedObject,
|
||||
int statusCode, Exception innerException)
|
||||
: this(operation, message, affectedObject, statusCode)
|
||||
{
|
||||
InnerException = innerException;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,126 @@
|
|||
// <auto-generated />
|
||||
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);
|
||||
|
||||
/// <summary>
|
||||
/// The property at path '{0}' could not be updated.
|
||||
/// </summary>
|
||||
internal static string CannotUpdateProperty
|
||||
{
|
||||
get { return GetString("CannotUpdateProperty"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The property at path '{0}' could not be updated.
|
||||
/// </summary>
|
||||
internal static string FormatCannotUpdateProperty(object p0)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, GetString("CannotUpdateProperty"), p0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For operation '{0}' on array property at path '{1}', the index is larger than the array size.
|
||||
/// </summary>
|
||||
internal static string InvalidIndexForArrayProperty
|
||||
{
|
||||
get { return GetString("InvalidIndexForArrayProperty"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For operation '{0}' on array property at path '{1}', the index is larger than the array size.
|
||||
/// </summary>
|
||||
internal static string FormatInvalidIndexForArrayProperty(object p0, object p1)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, GetString("InvalidIndexForArrayProperty"), p0, p1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The type '{0}' was malformed and could not be parsed.
|
||||
/// </summary>
|
||||
internal static string InvalidJsonPatchDocument
|
||||
{
|
||||
get { return GetString("InvalidJsonPatchDocument"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The type '{0}' was malformed and could not be parsed.
|
||||
/// </summary>
|
||||
internal static string FormatInvalidJsonPatchDocument(object p0)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, GetString("InvalidJsonPatchDocument"), p0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For operation '{0}', the provided path is invalid for array property at path '{1}'.
|
||||
/// </summary>
|
||||
internal static string InvalidPathForArrayProperty
|
||||
{
|
||||
get { return GetString("InvalidPathForArrayProperty"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For operation '{0}', the provided path is invalid for array property at path '{1}'.
|
||||
/// </summary>
|
||||
internal static string FormatInvalidPathForArrayProperty(object p0, object p1)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, GetString("InvalidPathForArrayProperty"), p0, p1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The value '{0}' is invalid for property at path '{1}'.
|
||||
/// </summary>
|
||||
internal static string InvalidValueForProperty
|
||||
{
|
||||
get { return GetString("InvalidValueForProperty"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The value '{0}' is invalid for property at path '{1}'.
|
||||
/// </summary>
|
||||
internal static string FormatInvalidValueForProperty(object p0, object p1)
|
||||
{
|
||||
return string.Format(CultureInfo.CurrentCulture, GetString("InvalidValueForProperty"), p0, p1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Property does not exist at path '{0}'.
|
||||
/// </summary>
|
||||
internal static string PropertyDoesNotExist
|
||||
{
|
||||
get { return GetString("PropertyDoesNotExist"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Property does not exist at path '{0}'.
|
||||
/// </summary>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="CannotUpdateProperty" xml:space="preserve">
|
||||
<value>The property at path '{0}' could not be updated.</value>
|
||||
</data>
|
||||
<data name="InvalidIndexForArrayProperty" xml:space="preserve">
|
||||
<value>For operation '{0}' on array property at path '{1}', the index is larger than the array size.</value>
|
||||
</data>
|
||||
<data name="InvalidJsonPatchDocument" xml:space="preserve">
|
||||
<value>The type '{0}' was malformed and could not be parsed.</value>
|
||||
</data>
|
||||
<data name="InvalidPathForArrayProperty" xml:space="preserve">
|
||||
<value>For operation '{0}', the provided path is invalid for array property at path '{1}'.</value>
|
||||
</data>
|
||||
<data name="InvalidValueForProperty" xml:space="preserve">
|
||||
<value>The value '{0}' is invalid for property at path '{1}'.</value>
|
||||
</data>
|
||||
<data name="PropertyDoesNotExist" xml:space="preserve">
|
||||
<value>Property does not exist at path '{0}'.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
|
@ -281,7 +281,10 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Add<int>(o => o.SimpleDTO.IntegerList, 4, 4);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { 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<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() =>
|
||||
{
|
||||
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<int>(o => o.SimpleDTO.IntegerList, 4, -1);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { 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<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() =>
|
||||
{
|
||||
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<int>(o => o.SimpleDTO.IntegerList, 3);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { 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<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() =>
|
||||
{
|
||||
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<int>(o => o.SimpleDTO.IntegerList, -1);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { 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<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() =>
|
||||
{
|
||||
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<int>(o => o.SimpleDTO.IntegerList, 5, 3);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { 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<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() =>
|
||||
{
|
||||
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<int>(o => o.SimpleDTO.IntegerList, 5, -1);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { 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<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTOWithNestedDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
Assert.Equal("Property does not exist at path '/simpledto/integerlist/-1'.", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -112,7 +112,9 @@ namespace Microsoft.AspNet.JsonPatch.Test
|
|||
patchDoc.Add<int>(o => o.IntegerList, 4, 4);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { 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<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { 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<int>(o => o.IntegerList, 4, -1);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { 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<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { 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<int>(o => o.IntegerList, 3);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { 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<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { 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<int>(o => o.IntegerList, -1);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() => { patchDoc.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { 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<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() => { deserialized.ApplyTo(doc); });
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() => { 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<JsonPatchException>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException>(() =>
|
||||
{
|
||||
var deserialized
|
||||
= JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTO>>(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<int>(o => o.IntegerList, 5, 3);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
{
|
||||
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<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
{
|
||||
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<int>(o => o.IntegerList, 5, -1);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
{
|
||||
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<JsonPatchDocument<SimpleDTO>>(serialized);
|
||||
|
||||
// Act & Assert
|
||||
Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
var exception = Assert.Throws<JsonPatchException<SimpleDTO>>(() =>
|
||||
{
|
||||
deserialized.ApplyTo(doc);
|
||||
});
|
||||
Assert.Equal("Property does not exist at path '/integerlist/-1'.", exception.Message);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
Loading…
Reference in New Issue