當前位置: 首頁>>代碼示例>>C#>>正文


C# Test.TestHttpHandler類代碼示例

本文整理匯總了C#中Microsoft.WindowsAzure.MobileServices.Test.TestHttpHandler的典型用法代碼示例。如果您正苦於以下問題:C# TestHttpHandler類的具體用法?C# TestHttpHandler怎麽用?C# TestHttpHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TestHttpHandler類屬於Microsoft.WindowsAzure.MobileServices.Test命名空間,在下文中一共展示了TestHttpHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ReadAsyncWithStringIdTypeAndStringIdResponseContent

        public async Task ReadAsyncWithStringIdTypeAndStringIdResponseContent()
        {
            string[] testIdData = IdTestData.ValidStringIds.Concat(
                                  IdTestData.EmptyStringIds).Concat(
                                  IdTestData.InvalidStringIds).ToArray();

            foreach (string testId in testIdData)
            {
                TestHttpHandler hijack = new TestHttpHandler();

                // Make the testId JSON safe
                string jsonTestId = testId.Replace("\\", "\\\\").Replace("\"", "\\\"");

                hijack.SetResponseContent("[{\"id\":\"" + jsonTestId + "\",\"String\":\"Hey\"}]");
                IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

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

                IEnumerable<StringIdType> results = await table.ReadAsync();
                StringIdType[] items = results.ToArray();

                Assert.AreEqual(1, items.Count());
                Assert.AreEqual(testId, items[0].Id);
                Assert.AreEqual("Hey", items[0].String);
            }
        }
開發者ID:rfaisal,項目名稱:azure-mobile-services,代碼行數:26,代碼來源:MobileServiceTable.Generic.Test.cs

示例2: ReadAsync_WithRelativeUri_Generic

        public async Task ReadAsync_WithRelativeUri_Generic()
        {
            var data = new[]
            {
                new 
                {
                    ServiceUri = "http://www.test.com", 
                    QueryUri = "/about?$filter=a eq b&$orderby=c", 
                    RequestUri = "http://www.test.com/about?$filter=a eq b&$orderby=c"
                },
                new 
                {
                    ServiceUri = "http://www.test.com/", 
                    QueryUri = "/about?$filter=a eq b&$orderby=c", 
                    RequestUri = "http://www.test.com/about?$filter=a eq b&$orderby=c"
                }
            };

            foreach (var item in data)
            {
                var hijack = new TestHttpHandler();
                hijack.SetResponseContent("[{\"col1\":\"Hey\"}]");
                IMobileServiceClient service = new MobileServiceClient(item.ServiceUri, "secret...", hijack);

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

                await table.ReadAsync<ToDo>(item.QueryUri);

                Assert.AreEqual("TT", hijack.Request.Headers.GetValues("X-ZUMO-FEATURES").First());
                Assert.AreEqual(item.RequestUri, hijack.Request.RequestUri.ToString());
            }
        }
開發者ID:RecursosOnline,項目名稱:azure-mobile-services,代碼行數:32,代碼來源:MobileServiceTable.Generic.Test.cs

示例3: PullAsync_Cancels_WhenCancellationTokenIsCancelled

        public async Task PullAsync_Cancels_WhenCancellationTokenIsCancelled()
        {
            var store = new MobileServiceLocalStoreMock();

            var handler = new MobileServiceSyncHandlerMock();
            handler.TableOperationAction = op => Task.Delay(TimeSpan.MaxValue).ContinueWith<JObject>(t => null); // long slow operation
            var hijack = new TestHttpHandler();
            hijack.OnSendingRequest = async req =>
            {
                await Task.Delay(1000);
                return req;
            };
            IMobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack);
            await service.SyncContext.InitializeAsync(store, handler);

            IMobileServiceSyncTable table = service.GetSyncTable("someTable");

            using (var cts = new CancellationTokenSource())
            {
                Task pullTask = table.PullAsync(null, null, null, cancellationToken: cts.Token);
                cts.Cancel();

                var ex = await ThrowsAsync<Exception>(() => pullTask);

                Assert.IsTrue((ex is OperationCanceledException || ex is TaskCanceledException));
                Assert.AreEqual(pullTask.Status, TaskStatus.Canceled);
            }
        }
開發者ID:Azure,項目名稱:azure-mobile-apps-net-client,代碼行數:28,代碼來源:MobileServiceSyncTable.Generic.Test.cs

示例4: DoesNotRewireSingleWiredDelegatingHandler

        public void DoesNotRewireSingleWiredDelegatingHandler()
        {
            string appUrl = MobileAppUriValidator.DummyMobileApp;

            TestHttpHandler innerHandler = new TestHttpHandler();
            DelegatingHandler wiredHandler = new TestHttpHandler();
            wiredHandler.InnerHandler = innerHandler;

            IMobileServiceClient service = new MobileServiceClient(appUrl, handlers: wiredHandler);

            Assert.AreEqual(wiredHandler.InnerHandler, innerHandler, "The prewired handler passed in should not have been rewired");
        }
開發者ID:Azure,項目名稱:azure-mobile-apps-net-client,代碼行數:12,代碼來源:MobileServiceClient.Test.cs

示例5: DateOffsetUri

        public async Task DateOffsetUri()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            IMobileServiceClient client = new MobileServiceClient("http://www.test.com", null, hijack);
            IMobileServiceTable<DateOffsetExample> table = client.GetTable<DateOffsetExample>();

            hijack.Response.StatusCode = HttpStatusCode.OK;
            hijack.SetResponseContent("[]");

            DateTimeOffset date = new DateTimeOffset(2009, 11, 21, 14, 22, 59, 860, TimeSpan.FromHours(-8));
            await table.Where(b => b.Date == date).ToEnumerableAsync();
            Assert.EndsWith(hijack.Request.RequestUri.ToString(), "$filter=(DateOffsetExampleDate eq datetimeoffset'2009-11-21T14:22:59.8600000-08:00')");
        }
開發者ID:bharathrajvm,項目名稱:azure-mobile-services,代碼行數:13,代碼來源:DateTests.cs

示例6: ReadAsync_WithAbsoluteUri_Generic

        public async Task ReadAsync_WithAbsoluteUri_Generic()
        {
            var hijack = new TestHttpHandler();
            hijack.SetResponseContent("[{\"col1\":\"Hey\"}]");
            IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

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

            await table.ReadAsync<ToDo>("http://www.test.com/about?$filter=a eq b&$orderby=c");

            Assert.AreEqual("TT,LH", hijack.Request.Headers.GetValues("X-ZUMO-FEATURES").First());
            Assert.AreEqual("http://www.test.com/about?$filter=a eq b&$orderby=c", hijack.Request.RequestUri.ToString());
        }
開發者ID:RecursosOnline,項目名稱:azure-mobile-services,代碼行數:13,代碼來源:MobileServiceTable.Generic.Test.cs

示例7: DateOffsetUri

        public async Task DateOffsetUri()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            IMobileServiceClient client = new MobileServiceClient("http://www.test.com", null, hijack);
            IMobileServiceTable<DateOffsetExample> table = client.GetTable<DateOffsetExample>();

            hijack.Response = new HttpResponseMessage(HttpStatusCode.OK);
            hijack.SetResponseContent("[]");

            var date = DateTimeOffset.Parse("2009-11-21T06:22:59.8600000-08:00");
            await table.Where(b => b.Date == date).ToEnumerableAsync();
            Assert.EndsWith(hijack.Request.RequestUri.ToString(), "$filter=(DateOffsetExampleDate eq datetimeoffset'2009-11-21T06:22:59.8600000-08:00')");
        }
開發者ID:RecursosOnline,項目名稱:azure-mobile-services,代碼行數:13,代碼來源:DateTests.cs

示例8: LookupAsyncGeneric

        public async Task LookupAsyncGeneric()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
            IMobileServiceTable<StringType> table = service.GetTable<StringType>();

            hijack.SetResponseContent("{\"id\":12,\"String\":\"Hello\"}");

            StringType expected = await table.LookupAsync(12);

            Assert.Contains(hijack.Request.RequestUri.ToString(), "12");
            Assert.AreEqual(12, expected.Id);
            Assert.AreEqual("Hello", expected.String);
        }
開發者ID:v-jiasi,項目名稱:azure-mobile-services,代碼行數:14,代碼來源:MobileServiceTable.Generic.Test.cs

示例9: ReadAsyncWithStringIdTypeAndNullIdResponseContent

        public async Task ReadAsyncWithStringIdTypeAndNullIdResponseContent()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("[{\"id\":null,\"String\":\"Hey\"}]");
            IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

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

            IEnumerable<StringIdType> results = await table.ReadAsync();
            StringIdType[] items = results.ToArray();

            Assert.AreEqual(1, items.Count());
            Assert.AreEqual(null, items[0].Id);
            Assert.AreEqual("Hey", items[0].String);
        }
開發者ID:jlaanstra,項目名稱:azure-mobile-services,代碼行數:15,代碼來源:MobileServiceTable.Generic.Test.cs

示例10: PushAsync_FeatureHeaderPresent

        public async Task PushAsync_FeatureHeaderPresent()
        {
            var hijack = new TestHttpHandler();
            hijack.AddResponseContent("{\"id\":\"abc\",\"String\":\"Hey\"}");

            IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
            var store = new MobileServiceLocalStoreMock();
            await service.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());

            IMobileServiceSyncTable table = service.GetSyncTable("someTable");
            JObject item1 = new JObject() { { "id", "abc" } };
            await table.InsertAsync(item1);
            await service.SyncContext.PushAsync();

            Assert.AreEqual(hijack.Requests[0].Headers.GetValues("X-ZUMO-FEATURES").First(), "TU,OL");
        }
開發者ID:RecursosOnline,項目名稱:azure-mobile-services,代碼行數:16,代碼來源:MobileServiceSyncContext.Test.cs

示例11: LookupAsyncGenericWithUserParameters

        public async Task LookupAsyncGenericWithUserParameters()
        {
            var userDefinedParameters = new Dictionary<string, string>() { { "state", "CA" } };

            TestHttpHandler hijack = new TestHttpHandler();
            IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
            IMobileServiceTable<StringType> table = service.GetTable<StringType>();

            hijack.SetResponseContent("{\"id\":12,\"String\":\"Hello\"}");

            StringType expected = await table.LookupAsync(12, userDefinedParameters);

            Assert.Contains(hijack.Request.RequestUri.ToString(), "12");
            Assert.Contains(hijack.Request.RequestUri.Query, "state=CA");
            Assert.AreEqual(12, expected.Id);
            Assert.AreEqual("Hello", expected.String);
        }
開發者ID:v-jiasi,項目名稱:azure-mobile-services,代碼行數:17,代碼來源:MobileServiceTable.Generic.Test.cs

示例12: ReadAsyncGeneric

        public async Task ReadAsyncGeneric()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("[{\"id\":12,\"String\":\"Hey\"}]");
            IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

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

            IEnumerable<StringType> results = await table.ReadAsync();
            StringType[] people = results.Cast<StringType>().ToArray();

            Assert.Contains(hijack.Request.RequestUri.ToString(), "StringType");

            Assert.AreEqual(1, people.Count());
            Assert.AreEqual(12, people[0].Id);
            Assert.AreEqual("Hey", people[0].String);
        }
開發者ID:v-jiasi,項目名稱:azure-mobile-services,代碼行數:17,代碼來源:MobileServiceTable.Generic.Test.cs

示例13: ReadAsync_ModifiesStringId_IfItContainsIsoDateValue

        [AsyncTestMethod] // this is the default buggy behavior that we've already shipped
        public async Task ReadAsync_ModifiesStringId_IfItContainsIsoDateValue()
        {
            var hijack = new TestHttpHandler();
            hijack.SetResponseContent(@"[{
                                        ""id"": ""2014-01-29T23:01:33.444Z"",
                                        ""__createdAt"": ""2014-01-29T23:01:33.444Z""
                                        }]");

            IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
            IMobileServiceTable<ToDoWithSystemPropertiesType> table = service.GetTable<ToDoWithSystemPropertiesType>();

            IEnumerable<ToDoWithSystemPropertiesType> results = await table.ReadAsync();
            ToDoWithSystemPropertiesType item = results.First();

            Assert.AreEqual(item.Id, "01/29/2014 23:01:33");
            Assert.AreEqual(item.CreatedAt, DateTime.Parse("2014-01-29T23:01:33.444Z"));
        }
開發者ID:rfaisal,項目名稱:azure-mobile-services,代碼行數:18,代碼來源:MobileServiceTable.Generic.Test.cs

示例14: ReadAsync

        public async Task ReadAsync()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("{\"Count\":1, People: [{\"Id\":\"12\", \"String\":\"Hey\"}] }");

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

            IMobileServiceTable table = service.GetTable("tests");
            JToken people = await table.ReadAsync("$filter=id eq 12");

            Assert.Contains(hijack.Request.RequestUri.ToString(), "tests");
            Assert.Contains(hijack.Request.RequestUri.ToString(), "$filter=id eq 12");

            Assert.AreEqual(1, (int)people["Count"]);
            Assert.AreEqual(12, (int)people["People"][0]["Id"]);
            Assert.AreEqual("Hey", (string)people["People"][0]["String"]);
        }
開發者ID:nberardi,項目名稱:azure-mobile-services,代碼行數:17,代碼來源:MobileServiceTable.Test.cs

示例15: ReadAsync_DoesNotModifyStringId_IfItContainsIsoDateValueAndSerializerIsConfiguredToNotParseDates

        [AsyncTestMethod] // user has to set the serializer setting to round trip dates in string fields correctly
        public async Task ReadAsync_DoesNotModifyStringId_IfItContainsIsoDateValueAndSerializerIsConfiguredToNotParseDates()
        {
            var hijack = new TestHttpHandler();
            hijack.SetResponseContent(@"[{
                                        ""id"": ""2014-01-29T23:01:33.444Z"",
                                        ""__createdAt"": ""2014-01-29T23:01:33.444Z""
                                        }]");

            IMobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
            service.SerializerSettings.DateParseHandling = DateParseHandling.None;
            IMobileServiceTable<ToDoWithSystemPropertiesType> table = service.GetTable<ToDoWithSystemPropertiesType>();

            IEnumerable<ToDoWithSystemPropertiesType> results = await table.ReadAsync();
            ToDoWithSystemPropertiesType item = results.First();

            Assert.AreEqual(item.Id, "2014-01-29T23:01:33.444Z");
            Assert.AreEqual(item.CreatedAt, DateTime.Parse("2014-01-29T23:01:33.444Z"));
        }
開發者ID:rfaisal,項目名稱:azure-mobile-services,代碼行數:19,代碼來源:MobileServiceTable.Generic.Test.cs


注:本文中的Microsoft.WindowsAzure.MobileServices.Test.TestHttpHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。