public async Task BatchNotification_ReportsOperationCount() { var store = new MobileServiceLocalStoreMock(); var trackingContext = new StoreTrackingContext(StoreOperationSource.ServerPull, string.Empty); var eventManager = new MobileServiceEventManagerMock <IMobileServiceEvent>(); var settings = new MobileServiceSyncSettingsManager(store); var changeTracker = new LocalStoreChangeTracker(store, trackingContext, eventManager, settings); EnqueueSimpleObjectResponse(store, "123", "XXX", "789"); await changeTracker.UpsertAsync("test", new JObject() { { "id", "123" }, { "version", "2" } }, true); // Update await changeTracker.UpsertAsync("test", new JObject() { { "id", "456" }, { "version", "2" } }, true); // Insert await changeTracker.DeleteAsync("test", "789"); // Delete StoreOperationsBatchCompletedEvent batchEvent = null; eventManager.PublishAsyncFunc = e => { batchEvent = e as StoreOperationsBatchCompletedEvent; return(Task.FromResult(0)); }; changeTracker.Dispose(); Assert.IsNotNull(batchEvent); Assert.AreEqual(batchEvent.Batch.OperationCount, 3); Assert.AreEqual(batchEvent.Batch.GetOperationCountByKind(LocalStoreOperationKind.Update), 1); Assert.AreEqual(batchEvent.Batch.GetOperationCountByKind(LocalStoreOperationKind.Insert), 1); Assert.AreEqual(batchEvent.Batch.GetOperationCountByKind(LocalStoreOperationKind.Delete), 1); }
private async Task AssertNotificationResultWithMatchingLocalRecordVersion(StoreOperationSource[] operationSources, bool shouldNotify) { foreach (var operationSource in operationSources) { var store = new MobileServiceLocalStoreMock(); var trackingContext = new StoreTrackingContext(operationSource, string.Empty); var eventManager = new MobileServiceEventManagerMock <IMobileServiceEvent>(); var settings = new MobileServiceSyncSettingsManager(store); var changeTracker = new LocalStoreChangeTracker(store, trackingContext, eventManager, settings); JObject item = EnqueueSimpleObjectResponse(store); bool notificationSent = false; eventManager.PublishAsyncFunc = t => { notificationSent = true; return(Task.FromResult(0)); }; await changeTracker.UpsertAsync("test", item, true); Assert.AreEqual(notificationSent, shouldNotify, string.Format("Incorrect notification result with source {0}", operationSource)); } }