예제 #1
0
        public async Task DeleteAsync_WithQuery_SendsNotification()
        {
            var store           = new MobileServiceLocalStoreMock();
            var trackingContext = new StoreTrackingContext(StoreOperationSource.Local, string.Empty);
            var eventManager    = new MobileServiceEventManagerMock <IMobileServiceEvent>();
            var settings        = new MobileServiceSyncSettingsManager(store);
            var changeTracker   = new LocalStoreChangeTracker(store, trackingContext, eventManager, settings);

            JObject item = EnqueueSimpleObjectResponse(store);

            StoreOperationCompletedEvent operationEvent = null;

            eventManager.PublishAsyncFunc = t =>
            {
                operationEvent = t as StoreOperationCompletedEvent;
                return(Task.FromResult(0));
            };

            MobileServiceTableQueryDescription query = new MobileServiceTableQueryDescription("test");

            query.Filter = new BinaryOperatorNode(BinaryOperatorKind.Equal, new MemberAccessNode(null, MobileServiceSystemColumns.Id), new ConstantNode("123"));

            await changeTracker.DeleteAsync(query);

            Assert.IsNotNull(operationEvent);
            Assert.AreEqual(operationEvent.Operation.Kind, LocalStoreOperationKind.Delete);
            Assert.AreEqual(operationEvent.Operation.RecordId, "123");
            Assert.AreEqual(operationEvent.Operation.TableName, "test");
        }
예제 #2
0
        public async Task DeleteAsync_WithTableNameAndRecordIds_SendsNotification()
        {
            var store           = new MobileServiceLocalStoreMock();
            var trackingContext = new StoreTrackingContext(StoreOperationSource.Local, string.Empty);
            var eventManager    = new MobileServiceEventManagerMock <IMobileServiceEvent>();
            var settings        = new MobileServiceSyncSettingsManager(store);
            var changeTracker   = new LocalStoreChangeTracker(store, trackingContext, eventManager, settings);

            JObject item = EnqueueSimpleObjectResponse(store);

            StoreOperationCompletedEvent operationEvent = null;

            eventManager.PublishAsyncFunc = t =>
            {
                operationEvent = t as StoreOperationCompletedEvent;
                return(Task.FromResult(0));
            };

            await changeTracker.DeleteAsync("test", "123");

            Assert.IsNotNull(operationEvent);
            Assert.AreEqual(operationEvent.Operation.Kind, LocalStoreOperationKind.Delete);
            Assert.AreEqual(operationEvent.Operation.RecordId, "123");
            Assert.AreEqual(operationEvent.Operation.TableName, "test");
        }
예제 #3
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);
        }