public void AbleToDeleteStringListItemThenRevertViaPatch() { var testObj = TestClass.CreateSimpleInstance(); testObj.PopulateStringListOnTestClass(); var updatedTestObj = TestClass.CreateSimpleInstance(); updatedTestObj.PopulateStringListOnTestClass(); updatedTestObj.ListOfStringProperty.Remove("list"); Assert.NotEqual(testObj.ListOfStringProperty, updatedTestObj.ListOfStringProperty); var diff = ObjectDiffPatch.GenerateDiff(testObj, updatedTestObj); var revertPatch = diff.OldValues.ToString(); var revertedObj = ObjectDiffPatch.PatchObject(updatedTestObj, revertPatch); Assert.Equal(testObj.ListOfStringProperty, revertedObj.ListOfStringProperty); }
public void AbleToDeleteStringListItemThenRevertViaPatch() { var testObj = GetSimpleTestObject(); PopulateStringListOnTestClass(testObj); var updatedTestObj = GetSimpleTestObject(); PopulateStringListOnTestClass(updatedTestObj); updatedTestObj.ListOfStringProperty.Remove("list"); CollectionAssert.AreNotEqual(testObj.ListOfStringProperty, updatedTestObj.ListOfStringProperty); var diff = ObjectDiffPatch.GenerateDiff(testObj, updatedTestObj); var revertPatch = JsonConvert.SerializeObject(diff.OldValues); var revertedObj = ObjectDiffPatch.PatchObject(updatedTestObj, revertPatch); CollectionAssert.AreEqual(testObj.ListOfStringProperty, revertedObj.ListOfStringProperty); }
public void AbleToEditObjectInListThenRevertViaPatch() { var testObj = TestClass.CreateSimpleInstance(); testObj.PopulateObjectListOnTestClass(); var updatedTestObj = TestClass.CreateSimpleInstance(); updatedTestObj.PopulateObjectListOnTestClass(); updatedTestObj.ListOfObjectProperty[2].IntProperty = 30; updatedTestObj.ListOfObjectProperty[2].StringProperty = "this is an update to the last object in the list"; updatedTestObj.ListOfObjectProperty[2].DoubleProperty = 33.333; var diff = ObjectDiffPatch.GenerateDiff(testObj, updatedTestObj); var revertPatch = diff.OldValues.ToString(); var revertedObj = ObjectDiffPatch.PatchObject(updatedTestObj, revertPatch); Assert.Equal(testObj.ListOfObjectProperty[2].IntProperty, revertedObj.ListOfObjectProperty[2].IntProperty); Assert.Equal(testObj.ListOfObjectProperty[2].StringProperty, revertedObj.ListOfObjectProperty[2].StringProperty); Assert.Equal(testObj.ListOfObjectProperty[2].DoubleProperty, revertedObj.ListOfObjectProperty[2].DoubleProperty); }
public TEntity Modify(object id, dynamic bm) { if (bm.id == null || bm.id.ToString() != id.ToString()) { throw new KeyNotFoundException("Keys do not match."); } var dest = Find(id); if (dest == null) { throw new KeyNotFoundException("Item with the key given was not found."); } Ds.Context.Entry <TEntity>(dest).State = EntityState.Detached; var patched = ObjectDiffPatch.PatchObject <TEntity>(dest, bm); if (!CanWrite(patched)) { throw new UnauthorizedAccessException("Not Authorized."); } Ds.Context.Entry <TEntity>(patched).State = EntityState.Modified; return(patched); }
public void AbleToEditObjectInListThenRevertViaPatch() { var testObj = GetSimpleTestObject(); PopulateObjectListOnTestClass(testObj); var updatedTestObj = GetSimpleTestObject(); PopulateObjectListOnTestClass(updatedTestObj); updatedTestObj.ListOfObjectProperty[2].IntProperty = 30; updatedTestObj.ListOfObjectProperty[2].StringProperty = "this is an update to the last object in the list"; updatedTestObj.ListOfObjectProperty[2].DoubleProperty = 33.333; var diff = ObjectDiffPatch.GenerateDiff(testObj, updatedTestObj); var revertPatch = JsonConvert.SerializeObject(diff.OldValues); var revertedObj = ObjectDiffPatch.PatchObject(updatedTestObj, revertPatch); Assert.AreEqual(testObj.ListOfObjectProperty[2].IntProperty, revertedObj.ListOfObjectProperty[2].IntProperty); Assert.AreEqual(testObj.ListOfObjectProperty[2].StringProperty, revertedObj.ListOfObjectProperty[2].StringProperty); Assert.AreEqual(testObj.ListOfObjectProperty[2].DoubleProperty, revertedObj.ListOfObjectProperty[2].DoubleProperty); }
public T UpdateObject <T>(T original, T updated) where T : class { var diffs = ObjectDiffPatch.GenerateDiff(original, updated); return(ObjectDiffPatch.PatchObject(original, diffs.NewValues)); }