public void Deserialize_Works_WithoutItem() { var expected = new UpdateOperation("test", "1234"); var operation = TableOperation.Deserialize(serializedObject); Assert.IsAssignableFrom <UpdateOperation>(operation); Assert.Equal(expected, operation); }
public void Deserialize_Works_WithoutItem() { var expected = new DeleteOperation("test", "1234"); serializedObject["item"] = null; // We aren't expecting this. var operation = TableOperation.Deserialize(serializedObject); Assert.IsAssignableFrom <DeleteOperation>(operation); Assert.Equal(expected, operation); }
public void Deserialize_Works_WithItem() { var expected = new DeleteOperation("test", "1234") { Item = testObject }; var operation = TableOperation.Deserialize(serializedObject); Assert.IsAssignableFrom <DeleteOperation>(operation); Assert.Equal(expected, operation); }
public async Task PushItemsAsync_SingleTable_HandlesUpdateOperation_Conflict() { await table.ServiceClient.InitializeOfflineStoreAsync(); var itemToUpdate = new ClientMovie { Id = Guid.NewGuid().ToString(), Version = "1", Title = "The Big Test" }; var instance = table.ServiceClient.Serializer.Serialize(itemToUpdate) as JObject; store.Upsert("movies", new[] { instance }); var updatedItem = itemToUpdate.Clone(); updatedItem.Title = "Modified"; var mInstance = table.ServiceClient.Serializer.Serialize(updatedItem) as JObject; var returnedItem = itemToUpdate.Clone(); returnedItem.Version = "2"; var expectedInstance = table.ServiceClient.Serializer.Serialize(returnedItem) as JObject; MockHandler.AddResponse(HttpStatusCode.Conflict, returnedItem); await table.ReplaceItemAsync(mInstance); var ex = await Assert.ThrowsAsync <PushFailedException>(() => table.PushItemsAsync()); Assert.Single(MockHandler.Requests); var request = MockHandler.Requests[0]; Assert.Equal(HttpMethod.Put, request.Method); Assert.Equal($"/tables/movies/{itemToUpdate.Id}", request.RequestUri.PathAndQuery); Assert.Equal("\"1\"", request.Headers.IfMatch.First().Tag); var requestObj = JObject.Parse(await request.Content.ReadAsStringAsync()); AssertEx.JsonEqual(mInstance, requestObj); Assert.Equal(PushStatus.Complete, ex.PushResult.Status); Assert.Single(ex.PushResult.Errors); Assert.Equal("movies", ex.PushResult.Errors.First().TableName); Assert.Equal(itemToUpdate.Id, ex.PushResult.Errors.First().Item.Value <string>("id")); Assert.Single(store.TableMap[SystemTables.OperationsQueue]); var op = TableOperation.Deserialize(store.TableMap[SystemTables.OperationsQueue].Values.First()); Assert.Equal(TableOperationState.Failed, op.State); Assert.Single(store.TableMap[SystemTables.SyncErrors]); }
public async Task DeleteItemAsync_DeletesItem_AndAddsToQueue_WhenItemExists() { await table.ServiceClient.InitializeOfflineStoreAsync(); var item = GetSampleMovie <ClientMovie>(); item.Id = Guid.NewGuid().ToString(); var instance = StoreInTable("movies", item); await table.DeleteItemAsync(instance); Assert.Empty(store.TableMap["movies"]); Assert.Single(store.TableMap[SystemTables.OperationsQueue]); var op = TableOperation.Deserialize(store.TableMap[SystemTables.OperationsQueue].Values.First()); Assert.Equal(TableOperationKind.Delete, op.Kind); Assert.Equal(item.Id, op.ItemId); AssertEx.JsonEqual(instance, op.Item); }
public async Task PushItemsAsync_SingleTable_HandlesDeleteOperation_Conflict() { await table.ServiceClient.InitializeOfflineStoreAsync(); var item = new ClientMovie { Id = Guid.NewGuid().ToString(), Version = "1" }; var conflictItem = new ClientMovie { Id = item.Id, Version = "2" }; var instance = (JObject)table.ServiceClient.Serializer.Serialize(item); store.Upsert("movies", new[] { instance }); MockHandler.AddResponse(HttpStatusCode.Conflict, conflictItem); await table.DeleteItemAsync(instance); var ex = await Assert.ThrowsAsync <PushFailedException>(() => table.PushItemsAsync()); Assert.Single(MockHandler.Requests); var request = MockHandler.Requests[0]; Assert.Equal(HttpMethod.Delete, request.Method); Assert.Equal($"/tables/movies/{item.Id}", request.RequestUri.PathAndQuery); Assert.Equal(PushStatus.Complete, ex.PushResult.Status); Assert.Single(ex.PushResult.Errors); Assert.Equal("movies", ex.PushResult.Errors.First().TableName); Assert.Equal(item.Id, ex.PushResult.Errors.First().Item.Value <string>("id")); Assert.Single(store.TableMap[SystemTables.OperationsQueue]); var op = TableOperation.Deserialize(store.TableMap[SystemTables.OperationsQueue].Values.First()); Assert.Equal(TableOperationState.Failed, op.State); Assert.Single(store.TableMap[SystemTables.SyncErrors]); }
public void Deserialize_Null_ReturnsNull() { var operation = TableOperation.Deserialize(null); Assert.Null(operation); }