public async Task FilterReadAsyncWithIntegerAsStringIdAgainstIntegerIdTable()
        {
            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);
            }

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

            IEnumerable <ToDoWithStringIdAgainstIntIdTable> results = await stringIdTable.Where(p => p.Id == integerIdItems[0].Id.ToString()).ToEnumerableAsync();

            ToDoWithStringIdAgainstIntIdTable[] items = results.ToArray();
            Assert.AreEqual(1, items.Count());
            Assert.AreEqual(integerIdItems[0].Id.ToString(), items[0].Id);
            Assert.AreEqual("0", items[0].String);

            foreach (ToDoWithIntId integerIdItem in integerIdItems)
            {
                await table.DeleteAsync(integerIdItem);
            }
        }
        public async Task OrderingReadAsyncWithStringIdAgainstIntegerIdTable()
        {
            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);
            }

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

            IEnumerable <ToDoWithStringIdAgainstIntIdTable> results = await stringIdTable.OrderBy(p => p.Id).ToEnumerableAsync();

            ToDoWithStringIdAgainstIntIdTable[] items = results.ToArray();

            Assert.AreEqual(10, items.Count());
            for (var i = 0; i < 8; i++)
            {
                Assert.AreEqual((int.Parse(items[i].Id) + 1).ToString(), items[i + 1].Id);
            }

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

            items = results.ToArray();

            Assert.AreEqual(10, items.Count());
            for (var i = 8; i >= 0; i--)
            {
                Assert.AreEqual((int.Parse(items[i].Id) - 1).ToString(), items[i + 1].Id);
            }

            foreach (ToDoWithIntId integerIdItem in integerIdItems)
            {
                await table.DeleteAsync(integerIdItem);
            }
        }
        public async Task ReadAsyncWithValidIntIdAgainstIntIdTable()
        {
            await EnsureEmptyTableAsync <ToDoWithIntId>();

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

            ToDoWithIntId item = new ToDoWithIntId()
            {
                String = "Hey"
            };
            await table.InsertAsync(item);

            IEnumerable <ToDoWithIntId> results = await table.ReadAsync();

            ToDoWithIntId[] items = results.ToArray();

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

            await table.DeleteAsync(item);
        }
        public async Task FilterReadAsyncWithEmptyStringIdAgainstIntegerIdTable()
        {
            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 = new string[] { "", " ", null };

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

            foreach (string testId in testIdData)
            {
                IEnumerable <ToDoWithStringIdAgainstIntIdTable> results = await stringIdTable.Where(p => p.Id == testId).ToEnumerableAsync();

                ToDoWithStringIdAgainstIntIdTable[] items = results.ToArray();

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

            foreach (ToDoWithIntId integerIdItem in integerIdItems)
            {
                await table.DeleteAsync(integerIdItem);
            }
        }
        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);
            }
        }
Exemple #6
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);
            }
        }