本文整理汇总了C#中JsonPatchDocument.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# JsonPatchDocument.Remove方法的具体用法?C# JsonPatchDocument.Remove怎么用?C# JsonPatchDocument.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonPatchDocument
的用法示例。
在下文中一共展示了JsonPatchDocument.Remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Remove_InvalidPath_ThrowsJsonPatchParseException
public void Remove_InvalidPath_ThrowsJsonPatchParseException()
{
//Arrange
var patchDocument = new JsonPatchDocument<SimpleEntity>();
//Act
patchDocument.Remove("FooMissing");
}
示例2: Remove_ValidPath_OperationAdded
public void Remove_ValidPath_OperationAdded()
{
//Arrange
var patchDocument = new JsonPatchDocument<SimpleEntity>();
//Act
patchDocument.Remove("Foo");
//Assert
Assert.AreEqual(1, patchDocument.Operations.Count);
Assert.AreEqual(JsonPatchOperationType.remove, patchDocument.Operations.Single().Operation);
}
示例3: RemoveFromList
public void RemoveFromList()
{
var doc = new SimpleDTO()
{
IntegerList = new List<int>() { 1, 2, 3 }
};
// create patch
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Remove("IntegerList/2");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
deserialized.ApplyTo(doc);
Assert.Equal(new List<int>() { 1, 2 }, doc.IntegerList);
}
示例4: NestedRemove
public void NestedRemove()
{
dynamic doc = new ExpandoObject();
doc.SimpleDTO = new SimpleDTO()
{
StringProperty = "A"
};
// create patch
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Remove("SimpleDTO/StringProperty");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
deserialized.ApplyTo(doc);
Assert.Equal(null, doc.SimpleDTO.StringProperty);
}
示例5: NestedRemoveFromEndOfList
public void NestedRemoveFromEndOfList()
{
dynamic doc = new ExpandoObject();
doc.SimpleDTO = new SimpleDTO()
{
IntegerList = new List<int>() { 1, 2, 3 }
};
// create patch
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Remove("SimpleDTO/IntegerList/-");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
deserialized.ApplyTo(doc);
Assert.Equal(new List<int>() { 1, 2 }, doc.SimpleDTO.IntegerList);
}
示例6: RemovePropertyFromExpandoObject
public void RemovePropertyFromExpandoObject()
{
dynamic obj = new ExpandoObject();
obj.Test = 1;
// create patch
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Remove("Test");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
deserialized.ApplyTo(obj);
var cont = obj as IDictionary<string, object>;
object valueFromDictionary;
cont.TryGetValue("Test", out valueFromDictionary);
Assert.Null(valueFromDictionary);
}
示例7: RemovePropertyShouldFailIfItDoesntExist
public void RemovePropertyShouldFailIfItDoesntExist()
{
dynamic doc = new ExpandoObject();
doc.Test = 1;
// create patch
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Remove("NonExisting");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
var exception = Assert.Throws<JsonPatchException>(() =>
{
deserialized.ApplyTo(doc);
});
Assert.Equal(
"The property at path '/NonExisting' could not be removed.",
exception.Message);
}
示例8: RemovePropertyShouldFailIfRootIsAnonymous
public void RemovePropertyShouldFailIfRootIsAnonymous()
{
dynamic doc = new
{
Test = 1
};
// create patch
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Remove("Test");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
var exception = Assert.Throws<JsonPatchException>(() =>
{
deserialized.ApplyTo(doc);
});
Assert.Equal(
"The property at path '/Test' could not be updated.",
exception.Message);
}
示例9: RemoveFromListInvalidPositionTooLarge
public void RemoveFromListInvalidPositionTooLarge()
{
var doc = new SimpleDTO()
{
IntegerList = new List<int>() { 1, 2, 3 }
};
// create patch
JsonPatchDocument patchDoc = new JsonPatchDocument();
patchDoc.Remove("IntegerList/3");
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument>(serialized);
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.",
exception.Message);
}
示例10: RemoveFromListInvalidPositionTooSmallWithSerialization
public void RemoveFromListInvalidPositionTooSmallWithSerialization()
{
var doc = new SimpleDTOWithNestedDTO()
{
SimpleDTO = new SimpleDTO()
{
IntegerList = new List<int>() { 1, 2, 3 }
}
}
;
// create patch
JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
patchDoc.Remove<int>(o => o.SimpleDTO.IntegerList, -1);
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
Assert.Throws<JsonPatchException>(() => { deserialized.ApplyTo(doc); });
}
示例11: RemoveFromListInvalidPositionTooSmall
public void RemoveFromListInvalidPositionTooSmall()
{
var doc = new SimpleDTOWithNestedDTO()
{
SimpleDTO = new SimpleDTO()
{
IntegerList = new List<int>() { 1, 2, 3 }
}
}
;
// create patch
JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
patchDoc.Remove<int>(o => o.SimpleDTO.IntegerList, -1);
Assert.Throws<JsonPatchException>(() => { patchDoc.ApplyTo(doc); });
}
示例12: RemoveWithSerialization
public void RemoveWithSerialization()
{
var doc = new SimpleDTOWithNestedDTO()
{
SimpleDTO = new SimpleDTO()
{
StringProperty = "A"
}
};
// create patch
JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
patchDoc.Remove<string>(o => o.SimpleDTO.StringProperty);
var serialized = JsonConvert.SerializeObject(patchDoc);
var deserialized = JsonConvert.DeserializeObject<JsonPatchDocument<SimpleDTOWithNestedDTO>>(serialized);
deserialized.ApplyTo(doc);
Assert.Equal(null, doc.SimpleDTO.StringProperty);
}
示例13: Remove
public void Remove()
{
var doc = new SimpleDTOWithNestedDTO()
{
SimpleDTO = new SimpleDTO()
{
StringProperty = "A"
}
};
// create patch
JsonPatchDocument<SimpleDTOWithNestedDTO> patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
patchDoc.Remove<string>(o => o.SimpleDTO.StringProperty);
patchDoc.ApplyTo(doc);
Assert.Equal(null, doc.SimpleDTO.StringProperty);
}
示例14: RemoveFromListInvalidPositionTooLarge
public void RemoveFromListInvalidPositionTooLarge()
{
// Arrange
var doc = new SimpleDTOWithNestedDTO()
{
SimpleDTO = new SimpleDTO()
{
IntegerList = new List<int>() { 1, 2, 3 }
}
};
// create patch
var patchDoc = new JsonPatchDocument<SimpleDTOWithNestedDTO>();
patchDoc.Remove<int>(o => o.SimpleDTO.IntegerList, 3);
// Act & Assert
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);
}
示例15: Remove
public void Remove()
{
// Arrange
var doc = new SimpleDTO()
{
StringProperty = "A"
};
// create patch
var patchDoc = new JsonPatchDocument<SimpleDTO>();
patchDoc.Remove<string>(o => o.StringProperty);
// Act
patchDoc.ApplyTo(doc);
// Assert
Assert.Equal(null, doc.StringProperty);
}