public void VersionTypeDeserialization()
        {
            List<Tuple<VersionType, string>> testCases = new List<Tuple<VersionType, string>>() {
                new Tuple<VersionType, string>(new VersionType { Version = "0x0004F" }, "{\"__version\":\"0x0004F\"}"),
                new Tuple<VersionType, string>(new VersionType { Version = null }, "{\"__version\":null}"),
            };

            // Need to ensure that the type is registered as a table to force the id property check
            DefaultSerializer.SerializerSettings.ContractResolver.ResolveTableName(typeof(VersionType));

            foreach (var testCase in testCases)
            {
                var input = testCase.Item2;
                var expected = testCase.Item1;

                VersionType actual = new VersionType();
                DefaultSerializer.Deserialize(input, actual);

                Assert.AreEqual(actual.Version, expected.Version);
            }
        }
コード例 #2
0
        public async Task VersionSystemPropertySetsIfMatchHeader()
        {
            List<Tuple<string, string>> testCases = new List<Tuple<string,string>>() {
                new Tuple<string, string>("AAAAAAAAH2o=", "\"AAAAAAAAH2o=\""),
                new Tuple<string, string>("a version", "\"a version\""),
                new Tuple<string, string>("a version with a \" quote", "\"a version with a \\\" quote\""),
                new Tuple<string, string>("a version with an already escaped \\\" quote", "\"a version with an already escaped \\\" quote\""),
                new Tuple<string, string>("\"a version with a quote at the start", "\"\\\"a version with a quote at the start\""),
                new Tuple<string, string>("a version with a quote at the end\"", "\"a version with a quote at the end\\\"\""),
                new Tuple<string, string>("datetime'2013-10-08T04%3A12%3A36.96Z'", "\"datetime'2013-10-08T04%3A12%3A36.96Z'\""),
            };

            foreach (Tuple<string, string> testcase in testCases)
            {
                TestHttpHandler hijack = new TestHttpHandler();

                hijack.SetResponseContent("{\"id\":\"an id\",\"__version\":\"AAAAAAAAH2o=\"}");

                IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

                IMobileServiceTable<VersionType> table = service.GetTable<VersionType>();

                hijack.OnSendingRequest = async (request) =>
                {
                    string content = await request.Content.ReadAsStringAsync();
                    JObject jobject = JObject.Parse(content);
                    Assert.AreEqual(request.Headers.IfMatch.First().Tag, testcase.Item2);
                    return request;
                };

                VersionType item = new VersionType() { Id = "an id", Version = testcase.Item1 };
                await table.UpdateAsync(item);

            }
        }
コード例 #3
0
        public async Task VersionSystemPropertySetFromEtagHeader()
        {
            List<Tuple<string, string>> testCases = new List<Tuple<string, string>>() {
                new Tuple<string, string>("AAAAAAAAH2o=", "\"AAAAAAAAH2o=\""),
                new Tuple<string, string>("a version", "\"a version\""),
                new Tuple<string, string>("a version with a \" quote", "\"a version with a \\\" quote\""),
                new Tuple<string, string>("a version with an already escaped \" quote", "\"a version with an already escaped \\\" quote\""),
                new Tuple<string, string>("\"a version with a quote at the start", "\"\\\"a version with a quote at the start\""),
                new Tuple<string, string>("a version with a quote at the end\"", "\"a version with a quote at the end\\\"\""),
                new Tuple<string, string>("datetime'2013-10-08T04%3A12%3A36.96Z'", "\"datetime'2013-10-08T04%3A12%3A36.96Z'\""),
            };

            foreach (Tuple<string, string> testcase in testCases)
            {
                TestHttpHandler hijack = new TestHttpHandler();

                hijack.SetResponseContent("{\"id\":\"an id\"}");
                hijack.Response.Headers.ETag = new EntityTagHeaderValue(testcase.Item2);

                IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

                IMobileServiceTable<VersionType> table = service.GetTable<VersionType>();

                VersionType item = new VersionType() { Id = "an id" };
                await table.UpdateAsync(item);

                Assert.AreEqual(item.Version, testcase.Item1);
            }
        }
        private static async Task TestIfMatchHeaderIsSet(Func<IMobileServiceTable<VersionType>, VersionType, Task> action)
        {
             List<Tuple<string, string>> testCases = new List<Tuple<string,string>>() {
                new Tuple<string, string>("AAAAAAAAH2o=", "\"AAAAAAAAH2o=\""),
                new Tuple<string, string>("a version", "\"a version\""),
                new Tuple<string, string>("a version with a \" quote", "\"a version with a \\\" quote\""),
                new Tuple<string, string>("a version with an already escaped \\\" quote", "\"a version with an already escaped \\\" quote\""),
                new Tuple<string, string>("\"a version with a quote at the start", "\"\\\"a version with a quote at the start\""),
                new Tuple<string, string>("a version with a quote at the end\"", "\"a version with a quote at the end\\\"\""),
                new Tuple<string, string>("datetime'2013-10-08T04%3A12%3A36.96Z'", "\"datetime'2013-10-08T04%3A12%3A36.96Z'\""),
            };

             foreach (Tuple<string, string> testcase in testCases)
             {
                 TestHttpHandler hijack = new TestHttpHandler();

                 hijack.SetResponseContent("{\"id\":\"an id\",\"__version\":\"AAAAAAAAH2o=\"}");

                 IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

                 IMobileServiceTable<VersionType> table = service.GetTable<VersionType>();

                 hijack.OnSendingRequest = (request) =>
                 {
                     Assert.AreEqual(request.Headers.IfMatch.First().Tag, testcase.Item2);
                     return Task.FromResult(request);
                 };
                 var item = new VersionType() { Id = "an id", Version = testcase.Item1 };
                 await action(table, item);
             }
        }