Beispiel #1
0
        public void Disposing_CompletesBatch()
        {
            var store           = new MobileServiceLocalStoreMock();
            var trackingContext = new StoreTrackingContext(StoreOperationSource.ServerPull, string.Empty);
            var eventManager    = new MobileServiceEventManagerMock <IMobileServiceEvent>();
            var settings        = new MobileServiceSyncSettingsManager(store);

            StoreOperationsBatchCompletedEvent batchEvent = null;

            eventManager.PublishAsyncFunc = e =>
            {
                batchEvent = e as StoreOperationsBatchCompletedEvent;
                return(Task.FromResult(0));
            };

            var changeTracker = new LocalStoreChangeTracker(store, trackingContext, eventManager, settings);

            changeTracker.Dispose();

            Assert.IsNotNull(batchEvent);
        }
Beispiel #2
0
        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);
        }