Esempio n. 1
0
        public async Task SetDeltaTokenAsync_UpdatesCacheAndDatabase()
        {
            MobileServiceSyncSettingsManager settings = await GetSettingManager();

            // first save
            var saved = new DateTimeOffset(2014, 7, 24, 3, 4, 5, TimeSpan.Zero);
            await settings.SetDeltaTokenAsync(TestTable, TestQueryId, saved);

            // then read and update
            DateTimeOffset read = await settings.GetDeltaTokenAsync(TestTable, TestQueryId);

            await settings.SetDeltaTokenAsync(TestTable, TestQueryId, read.AddDays(1));

            // then read again
            read = await settings.GetDeltaTokenAsync(TestTable, TestQueryId);

            Assert.Equal(read, saved.AddDays(1));

            // then read again in fresh instance
            settings = await GetSettingManager(resetDb : false);

            read = await settings.GetDeltaTokenAsync(TestTable, TestQueryId);

            Assert.Equal(read, saved.AddDays(1));
        }
Esempio n. 2
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");
        }
Esempio n. 3
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");
        }
Esempio n. 4
0
        public async Task GetDeltaTokenAsync_ReturnsMinValue_WhenTokenDoesNotExist()
        {
            MobileServiceSyncSettingsManager settings = await GetSettingManager();

            DateTimeOffset token = await settings.GetDeltaTokenAsync(TestTable, TestQueryId);

            Assert.Equal(token, new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).ToUniversalTime());
        }
Esempio n. 5
0
        public void Constructor_Throws_WhenTrackingOptionsAreInvalid()
        {
            var store           = new MobileServiceLocalStoreMock();
            var trackingContext = new StoreTrackingContext(StoreOperationSource.Local, string.Empty, StoreTrackingOptions.None);
            var eventManager    = new MobileServiceEventManager();
            var settings        = new MobileServiceSyncSettingsManager(store);

            AssertEx.Throws <InvalidOperationException>(() => new LocalStoreChangeTracker(store, trackingContext, eventManager, settings));
        }
        private void AssertUntrackedStoreForSourceWithOptions(StoreOperationSource source, StoreTrackingOptions trackingOptions)
        {
            var store           = new MobileServiceLocalStoreMock();
            var trackingContext = new StoreTrackingContext(StoreOperationSource.Local, string.Empty, StoreTrackingOptions.None);
            var eventManager    = new MobileServiceEventManager();
            var settings        = new MobileServiceSyncSettingsManager(store);

            IMobileServiceLocalStore trackedStore = StoreChangeTrackerFactory.CreateTrackedStore(store, source, trackingOptions, eventManager, settings);

            Assert.NotNull(trackedStore);
            Assert.IsType <LocalStoreProxy>(trackedStore);
        }
Esempio n. 7
0
        private static async Task <MobileServiceSyncSettingsManager> GetSettingManager(bool resetDb = true)
        {
            if (resetDb)
            {
                TestUtilities.ResetDatabase(TestDbName);
            }

            var store = new MobileServiceSQLiteStore(TestDbName);
            await store.InitializeAsync();

            var settings = new MobileServiceSyncSettingsManager(store);

            return(settings);
        }
Esempio n. 8
0
        public async Task ResetDeltaTokenAsync_ResetsTheToken()
        {
            MobileServiceSyncSettingsManager settings = await GetSettingManager();

            DateTimeOffset saved = new DateTime(2014, 7, 24, 3, 4, 5, DateTimeKind.Local);
            await settings.SetDeltaTokenAsync(TestTable, TestQueryId, saved);

            DateTimeOffset read = await settings.GetDeltaTokenAsync(TestTable, TestQueryId);

            Assert.Equal(read, saved.ToUniversalTime());

            await settings.ResetDeltaTokenAsync(TestTable, TestQueryId);

            read = await settings.GetDeltaTokenAsync(TestTable, TestQueryId);

            Assert.Equal(read, new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero).ToUniversalTime());
        }
Esempio n. 9
0
        public async Task SetDeltaTokenAsync_SavesTheSetting()
        {
            MobileServiceSyncSettingsManager settings = await GetSettingManager();

            var saved = new DateTimeOffset(2014, 7, 24, 3, 4, 5, TimeSpan.Zero);
            await settings.SetDeltaTokenAsync(TestTable, TestQueryId, saved);

            // with cache
            DateTimeOffset read = await settings.GetDeltaTokenAsync(TestTable, TestQueryId);

            Assert.Equal(read, saved);

            // without cache
            settings = await GetSettingManager(resetDb : false);

            read = await settings.GetDeltaTokenAsync(TestTable, TestQueryId);

            Assert.Equal(read, saved);
        }
Esempio n. 10
0
        public async Task SetDeltaTokenAsync_SavesTheSetting_AsUTCDate()
        {
            MobileServiceSyncSettingsManager settings = await GetSettingManager();

            DateTimeOffset saved = new DateTime(2014, 7, 24, 3, 4, 5, DateTimeKind.Local);
            await settings.SetDeltaTokenAsync(TestTable, TestQueryId, saved);

            // with cache
            DateTimeOffset read = await settings.GetDeltaTokenAsync(TestTable, TestQueryId);

            Assert.Equal(read, saved.ToUniversalTime());

            // without cache
            settings = await GetSettingManager(resetDb : false);

            read = await settings.GetDeltaTokenAsync(TestTable, TestQueryId);

            Assert.Equal(read, saved.ToUniversalTime());
        }
Esempio n. 11
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);
        }
Esempio n. 12
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);
        }
Esempio n. 13
0
        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));
            }
        }