public void SetValueFromPath_ReplaceIndexOutOfBounds_ThrowsException() { //Arrange var entity = new ArrayEntity { Foo = new string[] { "Element One", "Element Two" } }; //act PathHelper.SetValueFromPath(typeof(ArrayEntity), "/foo/2", entity, "Element Two Updated", JsonPatchOperationType.replace); }
public void GetValueFromPath_InvalidCollectionIndex_ThrowsException() { //Arrange var entity = new ArrayEntity { Foo = new string[] { "Element One", "Element Two" } }; //act PathHelper.GetValueFromPath(typeof(ArrayEntity), "/foo/5", entity); }
public void ApplyUpdate_TestOperation_Array_Failed() { //Arrange var patchDocument = new JsonPatchDocument <ArrayEntity>(); var entity = new ArrayEntity { Foo = new string[] { "bar1", "bar2" } }; //Act patchDocument.Test("Foo/1", "blah"); patchDocument.ApplyUpdatesTo(entity); }
public void SetValueFromPath_RemoveArrayValue_ThrowsException() { //Arrange var entity = new ArrayEntity { Foo = new string[] { "Element One", "Element Two", "Element Three" } }; //act PathHelper.SetValueFromPath(typeof(ArrayEntity), "/foo/1", entity, null, JsonPatchOperationType.remove); // Arrays should not support resizing. Expect JsonPatchException with an inner exception of type // NotSupportedException: Collection was of a fixed size }
public void GetValueFromPath_CollectionIndexOnRoot_ReturnsValue() { //Arrange var entity = new ArrayEntity { Foo = new string[] { "Element One", "Element Two" } }; //act var value = PathHelper.GetValueFromPath(typeof(ArrayEntity), "/foo/1", entity); //Assert Assert.AreEqual("Element Two", value); }
public void SetValueFromPath_ReplaceArrayValue_UpdatesValue() { //Arrange var entity = new ArrayEntity { Foo = new string[] { "Element One", "Element Two" } }; //act PathHelper.SetValueFromPath(typeof(ArrayEntity), "/foo/1", entity, "Element Two Updated", JsonPatchOperationType.replace); //Assert Assert.AreEqual("Element Two Updated", entity.Foo[1]); Assert.AreEqual(2, entity.Foo.Length); }
/// <summary> /// This method maps an int array to ArrayEntity objects. /// </summary> /// <param name="array">int array to be mapped.</param> /// <returns>Collection of ArrayEntity</returns> private List <ArrayEntity> MapToArrayEntity(int[,] array) { List <ArrayEntity> arrayEntities = new List <ArrayEntity>(); for (int i = 0; i < 9; i++) { for (int j = 0; j < 9; j++) { ArrayEntity arrayEntity = new ArrayEntity(); arrayEntity.RowIndex = i; arrayEntity.ColumnIndex = j; arrayEntity.Value = array[i, j]; arrayEntities.Add(arrayEntity); } } return(arrayEntities); }
public void SetValueFromPath_ComplexValueWithCollections_Sets() { //arrange var entity = new ComplexEntity { }; var value = new ArrayEntity { Foo = new[] { "Element One", "Element Two", "Element Three" } }; // act PathHelper.SetValueFromPath(typeof(ComplexEntity), "/foo", entity, value, JsonPatchOperationType.add); //assert Assert.AreEqual(3, entity.Foo.Foo.Length); Assert.AreEqual("Element One", entity.Foo.Foo[0]); Assert.AreEqual("Element Two", entity.Foo.Foo[1]); Assert.AreEqual("Element Three", entity.Foo.Foo[2]); }