public async Task AsyncTableOperationsWithIntegerAsStringIdAgainstIntIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithStringIdAgainstIntIdTable>();

            IMobileServiceTable <ToDoWithStringIdAgainstIntIdTable> stringIdTable = GetClient().GetTable <ToDoWithStringIdAgainstIntIdTable>();
            ToDoWithStringIdAgainstIntIdTable item = new ToDoWithStringIdAgainstIntIdTable()
            {
                String = "Hey"
            };

            // Insert
            await stringIdTable.InsertAsync(item);

            string testId = item.Id.ToString();

            // Read
            IEnumerable <ToDoWithStringIdAgainstIntIdTable> results = await stringIdTable.ReadAsync();

            ToDoWithStringIdAgainstIntIdTable[] items = results.ToArray();

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

            // Filter
            results = await stringIdTable.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 stringIdTable.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
            ToDoWithStringIdAgainstIntIdTable stringIdItem = await stringIdTable.LookupAsync(testId);

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

            // Update
            stringIdItem.String = "What?";
            await stringIdTable.UpdateAsync(stringIdItem);

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

            // Refresh
            stringIdItem = new ToDoWithStringIdAgainstIntIdTable()
            {
                Id = testId, String = "Hey"
            };
            await stringIdTable.RefreshAsync(stringIdItem);

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

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

            items = results.ToArray();

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

            // Delete
            await stringIdTable.DeleteAsync(item);
        }
        public async Task AsyncTableOperationsWithStringIdAgainstIntegerIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithIntId>();

            IMobileServiceTable <ToDoWithIntId> table = GetClient().GetTable <ToDoWithIntId>();
            List <ToDoWithIntId> integerIdItems       = new List <ToDoWithIntId>();

            for (var i = 0; i < 10; i++)
            {
                ToDoWithIntId item = new ToDoWithIntId()
                {
                    String = i.ToString()
                };
                await table.InsertAsync(item);

                integerIdItems.Add(item);
            }

            string[] testIdData = IdTestData.ValidStringIds.ToArray();

            IMobileServiceTable <ToDoWithStringIdAgainstIntIdTable> stringIdTable = GetClient().GetTable <ToDoWithStringIdAgainstIntIdTable>();

            foreach (string testId in testIdData)
            {
                // Filter
                Exception exception = null;
                try
                {
                    IEnumerable <ToDoWithStringIdAgainstIntIdTable> results = await stringIdTable.Where(p => p.Id == testId).ToEnumerableAsync();

                    ToDoWithStringIdAgainstIntIdTable[] items = results.ToArray();
                }
                catch (Exception e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.IsTrue(exception.Message.Contains("Bad request"));

                // Refresh
                exception = null;
                try
                {
                    ToDoWithStringIdAgainstIntIdTable item = new ToDoWithStringIdAgainstIntIdTable()
                    {
                        Id = testId, String = "Hey!"
                    };
                    await stringIdTable.RefreshAsync(item);
                }
                catch (Exception e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.IsTrue(exception.Message.Contains("Bad request"));

                // Insert
                exception = null;
                try
                {
                    ToDoWithStringIdAgainstIntIdTable item = new ToDoWithStringIdAgainstIntIdTable()
                    {
                        Id = testId, String = "Hey!"
                    };
                    await stringIdTable.InsertAsync(item);
                }
                catch (Exception e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.IsTrue(exception.Message.Contains("Error: A value cannot be specified for property 'id'"));

                // Lookup
                exception = null;
                try
                {
                    await stringIdTable.LookupAsync(testId);
                }
                catch (Exception e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.IsTrue(exception.Message.Contains("Error: The value specified for 'id' must be a number."));

                // Update
                exception = null;
                try
                {
                    ToDoWithStringIdAgainstIntIdTable item = new ToDoWithStringIdAgainstIntIdTable()
                    {
                        Id = testId, String = "Hey!"
                    };
                    await stringIdTable.UpdateAsync(item);
                }
                catch (Exception e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.IsTrue(exception.Message.Contains("Error: The value specified for 'id' must be a number."));

                // Delete
                exception = null;
                try
                {
                    ToDoWithStringIdAgainstIntIdTable item = new ToDoWithStringIdAgainstIntIdTable()
                    {
                        Id = testId, String = "Hey!"
                    };
                    await stringIdTable.DeleteAsync(item);
                }
                catch (Exception e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.IsTrue(exception.Message.Contains("Error: The value specified for 'id' must be a number."));
            }

            foreach (ToDoWithIntId integerIdItem in integerIdItems)
            {
                await table.DeleteAsync(integerIdItem);
            }
        }
예제 #3
0
        public async Task AsyncTableOperationsWithStringIdAgainstIntegerIdTable()
        {
            Log("This test fails with the .NET backend since in .NET the DTO always has string-id. In Node, querying an int-id column for a string causes an error.");

            await EnsureEmptyTableAsync <ToDoWithIntId>();

            IMobileServiceTable <ToDoWithIntId> table = GetClient().GetTable <ToDoWithIntId>();
            List <ToDoWithIntId> integerIdItems       = new List <ToDoWithIntId>();

            for (var i = 0; i < 10; i++)
            {
                ToDoWithIntId item = new ToDoWithIntId()
                {
                    Name = i.ToString()
                };
                await table.InsertAsync(item);

                integerIdItems.Add(item);
            }

            string[] testIdData = IdTestData.ValidStringIds.ToArray();

            IMobileServiceTable <ToDoWithStringIdAgainstIntIdTable> stringIdTable = GetClient().GetTable <ToDoWithStringIdAgainstIntIdTable>();

            foreach (string testId in testIdData)
            {
                // Filter
                MobileServiceInvalidOperationException exception = null;
                try
                {
                    IEnumerable <ToDoWithStringIdAgainstIntIdTable> results = await stringIdTable.Where(p => p.Id == testId).ToEnumerableAsync();

                    ToDoWithStringIdAgainstIntIdTable[] items = results.ToArray();
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.Equals(exception.Response.StatusCode, HttpStatusCode.BadRequest);

                // Refresh
                exception = null;
                try
                {
                    ToDoWithStringIdAgainstIntIdTable item = new ToDoWithStringIdAgainstIntIdTable()
                    {
                        Id = testId, Name = "Hey!"
                    };
                    await stringIdTable.RefreshAsync(item);
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.Equals(exception.Response.StatusCode, HttpStatusCode.BadRequest);

                // Lookup
                exception = null;
                try
                {
                    await stringIdTable.LookupAsync(testId);
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.Equals(exception.Response.StatusCode, HttpStatusCode.BadRequest);

                // Update
                exception = null;
                try
                {
                    ToDoWithStringIdAgainstIntIdTable item = new ToDoWithStringIdAgainstIntIdTable()
                    {
                        Id = testId, Name = "Hey!"
                    };
                    await stringIdTable.UpdateAsync(item);
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.Equals(exception.Response.StatusCode, HttpStatusCode.BadRequest);

                // Delete
                exception = null;
                try
                {
                    ToDoWithStringIdAgainstIntIdTable item = new ToDoWithStringIdAgainstIntIdTable()
                    {
                        Id = testId, Name = "Hey!"
                    };
                    await stringIdTable.DeleteAsync(item);
                }
                catch (MobileServiceInvalidOperationException e)
                {
                    exception = e;
                }

                Assert.IsNotNull(exception);
                Assert.Equals(exception.Response.StatusCode, HttpStatusCode.BadRequest);
            }

            foreach (ToDoWithIntId integerIdItem in integerIdItems)
            {
                await table.DeleteAsync(integerIdItem);
            }
        }