public void Validate_Throws_WithDeleteOperation_WhenInsertIsAttempted() { var newOperation = new DeleteOperation("test", MobileServiceTableKind.Table, "abc"); this.operation.State = MobileServiceTableOperationState.Attempted; var ex = AssertEx.Throws<InvalidOperationException>(() => this.operation.Validate(newOperation)); Assert.AreEqual("The item is in inconsistent state in the local store. Please complete the pending sync by calling PushAsync() before deleting the item.", ex.Message); }
public async Task DeleteAsync(string tableName, MobileServiceTableKind tableKind, string id, JObject item) { var operation = new DeleteOperation(tableName, tableKind, id) { Table = await this.GetTable(tableName), Item = item // item will be deleted from store, so we need to put it in the operation queue }; await this.ExecuteOperationAsync(operation, item); }
internal static MobileServiceTableOperation Deserialize(JObject obj) { if (obj == null) { return(null); } var kind = (MobileServiceTableOperationKind)obj.Value <int>("kind"); string tableName = obj.Value <string>("tableName"); var tableKind = (MobileServiceTableKind)obj.Value <int?>("tableKind").GetValueOrDefault(); string itemId = obj.Value <string>("itemId"); MobileServiceTableOperation operation = null; switch (kind) { case MobileServiceTableOperationKind.Insert: operation = new InsertOperation(tableName, tableKind, itemId); break; case MobileServiceTableOperationKind.Update: operation = new UpdateOperation(tableName, tableKind, itemId); break; case MobileServiceTableOperationKind.Delete: operation = new DeleteOperation(tableName, tableKind, itemId); break; } if (operation != null) { operation.Id = obj.Value <string>(MobileServiceSystemColumns.Id); operation.Sequence = obj.Value <long?>("sequence").GetValueOrDefault(); operation.Version = obj.Value <long?>("version").GetValueOrDefault(); string itemJson = obj.Value <string>("item"); operation.Item = !String.IsNullOrEmpty(itemJson) ? JObject.Parse(itemJson) : null; operation.State = (MobileServiceTableOperationState)obj.Value <int?>("state").GetValueOrDefault(); } return(operation); }
public void Validate_Succeeds_WithDeleteOperation() { var newOperation = new DeleteOperation("test", MobileServiceTableKind.Table, "abc"); this.operation.Validate(newOperation); }
public void Collapse_CancelsExistingOperation_WithDeleteOperation() { var newOperation = new DeleteOperation("test", MobileServiceTableKind.Table, "abc"); this.operation.Collapse(newOperation); // new operation should not be cancelled but rather updated Assert.IsFalse(newOperation.IsCancelled); Assert.IsTrue(newOperation.IsUpdated); Assert.AreEqual(newOperation.Version, 2L); // existing operation should be cancelled Assert.IsTrue(this.operation.IsCancelled); }
public void Initialize() { this.operation = new DeleteOperation("test", MobileServiceTableKind.Table, "abc"); }
public void Validate_Throws_WithDeleteOperation() { var tableOperation = new DeleteOperation("test", MobileServiceTableKind.Table, "abc"); TestDeleteValidateThrows(tableOperation); }
public void Collapse_CancelsBothOperations_WithDeleteOperation() { var newOperation = new DeleteOperation("test", MobileServiceTableKind.Table, "abc"); this.operation.Collapse(newOperation); // new operation should be cancelled Assert.IsTrue(newOperation.IsCancelled); // existing operation should also be cancelled Assert.IsTrue(this.operation.IsCancelled); }
internal static MobileServiceTableOperation Deserialize(JObject obj) { if (obj == null) { return null; } var kind = (MobileServiceTableOperationKind)obj.Value<int>("kind"); string tableName = obj.Value<string>("tableName"); var tableKind = (MobileServiceTableKind)obj.Value<int?>("tableKind").GetValueOrDefault(); string itemId = obj.Value<string>("itemId"); MobileServiceTableOperation operation = null; switch (kind) { case MobileServiceTableOperationKind.Insert: operation = new InsertOperation(tableName, tableKind, itemId); break; case MobileServiceTableOperationKind.Update: operation = new UpdateOperation(tableName, tableKind, itemId); break; case MobileServiceTableOperationKind.Delete: operation = new DeleteOperation(tableName, tableKind, itemId); break; } if (operation != null) { operation.Id = obj.Value<string>(MobileServiceSystemColumns.Id); operation.Sequence = obj.Value<long?>("sequence").GetValueOrDefault(); operation.Version = obj.Value<long?>("version").GetValueOrDefault(); string itemJson = obj.Value<string>("item"); operation.Item = !String.IsNullOrEmpty(itemJson) ? JObject.Parse(itemJson) : null; operation.State = (MobileServiceTableOperationState)obj.Value<int?>("state").GetValueOrDefault(); } return operation; }
public async Task ExecuteAsync_DoesNotSaveTheResult_IfOperationDoesNotWriteToStore() { var op = new DeleteOperation("table", MobileServiceTableKind.Table, "id") { Item = new JObject() }; Assert.IsFalse(op.CanWriteResultToStore); await TestResultSave(op, status: null, resultId: "id", saved: false); }