Esempio n. 1
0
        public async Task PullAsync_TriggersPush_WhenPushOtherTablesIsTrue_AndThereIsOperationTable()
        {
            ResetDatabase(TestTable);
            TestUtilities.DropTestTable(TestDbName, "relatedTable");
            TestUtilities.DropTestTable(TestDbName, "StringIdType");

            var hijack = new TestHttpHandler();

            hijack.AddResponseContent("{\"id\":\"abc\",\"String\":\"Hey\"}");
            hijack.AddResponseContent("{\"id\":\"abc\",\"String\":\"Hi\"}");
            hijack.AddResponseContent("[{\"id\":\"abc\",\"String\":\"Hey\"},{\"id\":\"def\",\"String\":\"World\"}]"); // for pull
            hijack.AddResponseContent("[]");                                                                          // last page

            var store = new MobileServiceSQLiteStore(TestDbName);

            store.DefineTable("relatedTable", new JObject()
            {
                { "id", String.Empty }
            });
            store.DefineTable <StringIdType>();

            IMobileServiceClient client = await CreateClient(hijack, store);

            // insert item in pull table
            IMobileServiceSyncTable unrelatedTable = client.GetSyncTable("relatedTable");
            await unrelatedTable.InsertAsync(new JObject()
            {
                { "id", "abc" }
            });

            // then insert item in other table
            MobileServiceSyncTable <StringIdType> mainTable = client.GetSyncTable <StringIdType>() as MobileServiceSyncTable <StringIdType>;
            var item = new StringIdType()
            {
                Id = "abc", String = "what?"
            };
            await mainTable.InsertAsync(item);

            await mainTable.PullAsync(null, null, null, true, CancellationToken.None);

            Assert.Equal(4, hijack.Requests.Count); // 2 for push and 2 for pull
            QueryEquals(hijack.Requests[0].RequestUri.AbsolutePath, "/tables/relatedTable");
            QueryEquals(hijack.Requests[1].RequestUri.AbsolutePath, "/tables/StringIdType");
            QueryEquals(hijack.Requests[1].RequestUri.AbsolutePath, "/tables/StringIdType");
            QueryEquals(hijack.Requests[1].RequestUri.AbsolutePath, "/tables/StringIdType");
            Assert.Equal(0L, client.SyncContext.PendingOperations);
        }
Esempio n. 2
0
        public async Task PushAsync_PushesAllTables_WhenEmptyListIsGiven()
        {
            ResetDatabase(TestTable);
            TestUtilities.DropTestTable(TestDbName, "someTable");
            TestUtilities.DropTestTable(TestDbName, "StringIdType");

            var hijack = new TestHttpHandler();

            hijack.AddResponseContent("{\"id\":\"abc\",\"String\":\"Hey\"}");
            hijack.AddResponseContent("{\"id\":\"abc\",\"String\":\"Hey\"}");

            var store = new MobileServiceSQLiteStore(TestDbName);

            store.DefineTable("someTable", new JObject()
            {
                { "id", String.Empty }
            });
            store.DefineTable <StringIdType>();

            IMobileServiceClient client = await CreateClient(hijack, store);

            // insert item in pull table
            IMobileServiceSyncTable table1 = client.GetSyncTable("someTable");
            await table1.InsertAsync(new JObject()
            {
                { "id", "abc" }
            });

            // then insert item in other table
            MobileServiceSyncTable <StringIdType> table2 = client.GetSyncTable <StringIdType>() as MobileServiceSyncTable <StringIdType>;
            var item = new StringIdType()
            {
                Id = "abc", String = "what?"
            };
            await table2.InsertAsync(item);

            await(client.SyncContext as MobileServiceSyncContext).PushAsync(CancellationToken.None);

            Assert.Equal(2, hijack.Requests.Count);
            QueryEquals(hijack.Requests[0].RequestUri.AbsolutePath, "/tables/someTable");
            QueryEquals(hijack.Requests[1].RequestUri.AbsolutePath, "/tables/StringIdType");
            Assert.Equal(0L, client.SyncContext.PendingOperations);
        }
Esempio n. 3
0
        public async Task PushAsync_PushesOnlySelectedTables_WhenSpecified()
        {
            ResetDatabase(TestTable);
            TestUtilities.DropTestTable(TestDbName, "someTable");
            TestUtilities.DropTestTable(TestDbName, "StringIdType");

            var hijack = new TestHttpHandler();

            hijack.AddResponseContent("{\"id\":\"abc\",\"String\":\"Hey\"}");

            var store = new MobileServiceSQLiteStore(TestDbName);

            store.DefineTable("someTable", new JObject()
            {
                { "id", String.Empty }
            });
            store.DefineTable <StringIdType>();

            IMobileServiceClient client = await CreateClient(hijack, store);

            // insert item in pull table
            IMobileServiceSyncTable unrelatedTable = client.GetSyncTable("someTable");
            await unrelatedTable.InsertAsync(new JObject()
            {
                { "id", "abc" }
            });

            // then insert item in other table
            MobileServiceSyncTable <StringIdType> mainTable = client.GetSyncTable <StringIdType>() as MobileServiceSyncTable <StringIdType>;
            var item = new StringIdType()
            {
                Id = "abc", String = "what?"
            };
            await mainTable.InsertAsync(item);

            await(client.SyncContext as MobileServiceSyncContext).PushAsync(CancellationToken.None, MobileServiceTableKind.Table, "someTable");

            Assert.AreEqual(hijack.Requests.Count, 1);
            AssertEx.QueryEquals(hijack.Requests[0].RequestUri.AbsolutePath, "/tables/someTable");
            Assert.AreEqual(1L, client.SyncContext.PendingOperations);
        }