public async Task InsertAsyncWithEmptyStringIdAgainstStringIdTable()
        {
            string[] emptyIdData = IdTestData.EmptyStringIds.Concat(
                new string[] { null }).ToArray();
            IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>();

            int count = 0;
            List <ToDoWithStringId> itemsToDelete = new List <ToDoWithStringId>();

            foreach (string emptyId in emptyIdData)
            {
                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = emptyId, String = (++count).ToString()
                };
                await table.InsertAsync(item);

                Assert.IsNotNull(item.Id);
                Assert.AreEqual(count.ToString(), item.String);
                itemsToDelete.Add(item);
            }

            foreach (var item in itemsToDelete)
            {
                await table.DeleteAsync(item);
            }
        }
        public async Task OrderingReadAsyncWithValidStringIdAgainstStringIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithStringId>();

            string[] testIdData = new string[] { "a", "b", "C", "_A", "_B", "_C", "1", "2", "3" };
            IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>();

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId, String = "Hey"
                };
                await table.InsertAsync(item);
            }

            IEnumerable <ToDoWithStringId> results = await table.OrderBy(p => p.Id).ToEnumerableAsync();

            ToDoWithStringId[] items = results.ToArray();

            Assert.AreEqual(9, items.Count());
            Assert.AreEqual("_A", items[0].Id);
            Assert.AreEqual("_B", items[1].Id);
            Assert.AreEqual("_C", items[2].Id);
            Assert.AreEqual("1", items[3].Id);
            Assert.AreEqual("2", items[4].Id);
            Assert.AreEqual("3", items[5].Id);
            Assert.AreEqual("a", items[6].Id);
            Assert.AreEqual("b", items[7].Id);
            Assert.AreEqual("C", items[8].Id);

            results = await table.OrderByDescending(p => p.Id).ToEnumerableAsync();

            items = results.ToArray();

            Assert.AreEqual(9, items.Count());
            Assert.AreEqual("_A", items[8].Id);
            Assert.AreEqual("_B", items[7].Id);
            Assert.AreEqual("_C", items[6].Id);
            Assert.AreEqual("1", items[5].Id);
            Assert.AreEqual("2", items[4].Id);
            Assert.AreEqual("3", items[3].Id);
            Assert.AreEqual("a", items[2].Id);
            Assert.AreEqual("b", items[1].Id);
            Assert.AreEqual("C", items[0].Id);

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId
                };
                await table.DeleteAsync(item);
            }
        }
예제 #3
0
        public async Task UpdateAsyncWithNosuchItemAgainstStringIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithStringId>();

            string[] testIdData = IdTestData.ValidStringIds;
            IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>();

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId, Name = "Hey"
                };
                await table.InsertAsync(item);
            }

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = await table.LookupAsync(testId);

                await table.DeleteAsync(item);

                item.Id   = testId;
                item.Name = "Alright!";

                MobileServiceInvalidOperationException exception = null;
                try
                {
                    await table.UpdateAsync(item);
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.AreEqual(exception.Response.StatusCode, HttpStatusCode.NotFound);
                Assert.IsTrue(exception.Message.Contains(string.Format("Error: An item with id '{0}' does not exist.", testId)) ||
                              exception.Message == "The request could not be completed.  (Not Found)");
            }
        }
        public async Task FilterReadAsyncWithEmptyStringIdAgainstStringIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithStringId>();

            string[] testIdData = IdTestData.ValidStringIds;
            IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>();

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId, String = "Hey"
                };
                await table.InsertAsync(item);
            }

            string[] invalidIdData = IdTestData.EmptyStringIds.Concat(
                IdTestData.InvalidStringIds).Concat(
                new string[] { null }).ToArray();

            foreach (string invalidId in invalidIdData)
            {
                IEnumerable <ToDoWithStringId> results = await table.Where(p => p.Id == invalidId).ToEnumerableAsync();

                ToDoWithStringId[] items = results.ToArray();

                Assert.AreEqual(0, items.Count());
            }

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId
                };
                await table.DeleteAsync(item);
            }
        }
예제 #5
0
        public async Task InsertAsyncWithExistingItemAgainstStringIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithStringId>();

            string[] testIdData = IdTestData.ValidStringIds;
            IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>();

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId, Name = "Hey"
                };
                await table.InsertAsync(item);
            }

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = await table.LookupAsync(testId);

                item.Name = "No we're talking!";

                MobileServiceInvalidOperationException exception = null;
                try
                {
                    await table.InsertAsync(item);
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.AreEqual(exception.Response.StatusCode, HttpStatusCode.Conflict);
                Assert.IsTrue(exception.Message.Contains("Could not insert the item because an item with that id already exists.") ||
                              exception.Message == "The request could not be completed.  (Conflict)");
            }
        }
        public async Task RefreshAsyncWithNoSuchItemAgainstStringIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithStringId>();

            string[] testIdData = IdTestData.ValidStringIds;
            IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>();

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId, String = "Hey"
                };
                await table.InsertAsync(item);
            }

            foreach (string testId in testIdData)
            {
                ToDoWithStringId item = await table.LookupAsync(testId);

                await table.DeleteAsync(item);

                item.Id = testId;

                InvalidOperationException exception = null;
                try
                {
                    await table.RefreshAsync(item);
                }
                catch (InvalidOperationException e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
            }
        }
        public async Task AsyncTableOperationsWithValidStringIdAgainstStringIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithStringId>();

            string[] testIdData = IdTestData.ValidStringIds;

            foreach (string testId in testIdData)
            {
                IMobileServiceTable <ToDoWithStringId> table = GetClient().GetTable <ToDoWithStringId>();

                ToDoWithStringId item = new ToDoWithStringId()
                {
                    Id = testId, String = "Hey"
                };
                await table.InsertAsync(item);

                // Read
                IEnumerable <ToDoWithStringId> results = await table.ReadAsync();

                ToDoWithStringId[] items = results.ToArray();

                Assert.AreEqual(1, items.Count());
                Assert.AreEqual(testId, items[0].Id);
                Assert.AreEqual("Hey", items[0].String);

                // Filter
                results = await table.Where(i => i.Id == testId).ToEnumerableAsync();

                items = results.ToArray();

                Assert.AreEqual(1, items.Count());
                Assert.AreEqual(testId, items[0].Id);
                Assert.AreEqual("Hey", items[0].String);

                // Projection
                var projectedResults = await table.Select(i => new { XId = i.Id, XString = i.String }).ToEnumerableAsync();

                var projectedItems = projectedResults.ToArray();

                Assert.AreEqual(1, projectedItems.Count());
                Assert.AreEqual(testId, projectedItems[0].XId);
                Assert.AreEqual("Hey", projectedItems[0].XString);

                // Lookup
                item = await table.LookupAsync(testId);

                Assert.AreEqual(testId, item.Id);
                Assert.AreEqual("Hey", item.String);

                // Update
                item.String = "What?";
                await table.UpdateAsync(item);

                Assert.AreEqual(testId, item.Id);
                Assert.AreEqual("What?", item.String);

                // Refresh
                item = new ToDoWithStringId()
                {
                    Id = testId, String = "Hey"
                };
                await table.RefreshAsync(item);

                Assert.AreEqual(testId, item.Id);
                Assert.AreEqual("What?", item.String);

                // Read Again
                results = await table.ReadAsync();

                items = results.ToArray();

                Assert.AreEqual(1, items.Count());
                Assert.AreEqual(testId, items[0].Id);
                Assert.AreEqual("What?", items[0].String);

                await table.DeleteAsync(item);
            }
        }