当前位置: 首页>>代码示例>>C#>>正文


C# MobileServiceClient.InvokeApiAsync方法代码示例

本文整理汇总了C#中MobileServiceClient.InvokeApiAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MobileServiceClient.InvokeApiAsync方法的具体用法?C# MobileServiceClient.InvokeApiAsync怎么用?C# MobileServiceClient.InvokeApiAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MobileServiceClient的用法示例。


在下文中一共展示了MobileServiceClient.InvokeApiAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: InvokeCustomAPI_ErrorStringAndNoContentType

        public async Task InvokeCustomAPI_ErrorStringAndNoContentType()
        {
            TestHttpHandler hijack = new TestHttpHandler();

            hijack.Response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest);
            hijack.Response.Content = new StringContent("message", Encoding.UTF8, null);
            hijack.Response.Content.Headers.ContentType = null;

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

            try
            {
                await service.InvokeApiAsync("testapi");
                Assert.Fail("Invoke API should have thrown");
            }
            catch (Exception e)
            {
                Assert.AreEqual(e.Message, "The request could not be completed.  (Bad Request)");
            }
        }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:20,代码来源:MobileServiceClient.Test.cs

示例2: InvokeCustomAPISimple

        public async Task InvokeCustomAPISimple()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            MobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack);
            MobileAppUriValidator mobileAppUriValidator = new MobileAppUriValidator(service);

            hijack.SetResponseContent("{\"id\":3}");

            IntType expected = await service.InvokeApiAsync<IntType>("calculator/add?a=1&b=2");

            Assert.AreEqual(hijack.Request.RequestUri.LocalPath, mobileAppUriValidator.GetApiUriPath("calculator/add"));
            Assert.AreEqual(hijack.Request.RequestUri.Query, "?a=1&b=2");
            Assert.AreEqual(3, expected.Id);
        }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:14,代码来源:MobileServiceClient.Test.cs

示例3: InvokeCustomAPIResponseWithParamsBodyAndHeader

        public async Task InvokeCustomAPIResponseWithParamsBodyAndHeader()
        {
            TestHttpHandler hijack = new TestHttpHandler();

            hijack.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
            hijack.Response.Content = new StringContent("{\"id\":\"2\"}", Encoding.UTF8, "application/json");
            var myParams = new Dictionary<string, string>() { { "a", "1" }, { "b", "2" } };

            HttpContent content = new StringContent("{\"test\" : \"one\"}", Encoding.UTF8, "application/json");
            MobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
            var myHeaders = new Dictionary<string, string>() { { "x-zumo-test", "test" } };

            HttpResponseMessage response = await service.InvokeApiAsync("calculator/add", content, HttpMethod.Post, myHeaders, myParams);

            Assert.AreEqual(myHeaders.Count, 1); // my headers should not be modified
            Assert.AreEqual(myHeaders["x-zumo-test"], "test");

            Assert.AreEqual(hijack.Request.RequestUri.LocalPath, "/api/calculator/add");
            Assert.AreEqual(hijack.Request.Headers.GetValues("x-zumo-test").First(), "test");
            Assert.IsNotNull(hijack.Request.Content);
            Assert.Contains(hijack.Request.RequestUri.Query, "?a=1&b=2");
            Assert.Contains(response.Content.ReadAsStringAsync().Result, "{\"id\":\"2\"}");
        }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:23,代码来源:MobileServiceClient.Test.cs

示例4: InvokeGenericCustomAPIWithNullResponse_Success

        public async Task InvokeGenericCustomAPIWithNullResponse_Success()
        {
            TestHttpHandler hijack = new TestHttpHandler();

            hijack.Response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
            hijack.Response.Content = null;

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

            IntType expected = await service.InvokeApiAsync<IntType>("testapi");
            Assert.AreEqual(hijack.Request.RequestUri.LocalPath, "/api/testapi");
            Assert.AreEqual(expected, null);
        }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:13,代码来源:MobileServiceClient.Test.cs

示例5: InvokeCustomAPIGetWithParams

        public async Task InvokeCustomAPIGetWithParams()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("{\"id\":3}");
            MobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

            var myParams = new Dictionary<string, string>() { { "a", "1" }, { "b", "2" } };
            IntType expected = await service.InvokeApiAsync<IntType>("calculator/add", HttpMethod.Get, myParams);

            Assert.Contains(hijack.Request.RequestUri.Query, "?a=1&b=2");
        }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:11,代码来源:MobileServiceClient.Test.cs

示例6: InvokeCustomAPIPostWithBodyJToken

        public async Task InvokeCustomAPIPostWithBodyJToken()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("{\"id\":3}");
            MobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

            var myParams = new Dictionary<string, string>() { { "a", "1" }, { "b", "2" } };
            JObject body = JToken.Parse("{\"test\":\"one\"}") as JObject;
            JToken expected = await service.InvokeApiAsync("calculator/add", body, HttpMethod.Post, myParams);

            Assert.Contains(hijack.Request.RequestUri.Query, "?a=1&b=2");
            Assert.IsNotNull(hijack.Request.Content);
        }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:13,代码来源:MobileServiceClient.Test.cs

示例7: InvokeCustomAPIResponse

        public async Task InvokeCustomAPIResponse()
        {
            TestHttpHandler hijack = new TestHttpHandler();

            hijack.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Accepted);
            hijack.Response.Content = new StringContent("{\"id\":\"2\"}", Encoding.UTF8, "application/json");

            MobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack);
            MobileAppUriValidator mobileAppUriValidator = new MobileAppUriValidator(service);
            HttpResponseMessage response = await service.InvokeApiAsync("calculator/add?a=1&b=2", null, HttpMethod.Post, null, null);

            Assert.AreEqual(hijack.Request.RequestUri.LocalPath, mobileAppUriValidator.GetApiUriPath("calculator/add"));
            Assert.AreEqual(hijack.Request.RequestUri.Query, "?a=1&b=2");
            Assert.Contains(response.Content.ReadAsStringAsync().Result, "{\"id\":\"2\"}");
        }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:15,代码来源:MobileServiceClient.Test.cs

示例8: InvokeApiAsync_DoesNotAppendApiPath_IfApiStartsWithSlash

        public async Task InvokeApiAsync_DoesNotAppendApiPath_IfApiStartsWithSlash()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            var service = new MobileServiceClient("http://www.test.com", "secret...", hijack);
            hijack.SetResponseContent("{\"id\":3}");

            await service.InvokeApiAsync<IntType>("/calculator/add?a=1&b=2", HttpMethod.Get, null);

            Assert.AreEqual(hijack.Request.RequestUri.LocalPath, "/calculator/add");
            Assert.Contains(hijack.Request.RequestUri.Query, "a=1&b=2");
        }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:11,代码来源:MobileServiceClient.Test.cs

示例9: InvokeCustomAPIGetWithODataParams

        public async Task InvokeCustomAPIGetWithODataParams()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("{\"id\":3}");
            MobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack);

            var myParams = new Dictionary<string, string>() { { "$select", "one,two" }, { "$take", "1" } };
            IntType expected = await service.InvokeApiAsync<IntType>("calculator/add", HttpMethod.Get, myParams);

            Assert.Contains(hijack.Request.RequestUri.Query, "?%24select=one%2Ctwo&%24take=1");
        }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:11,代码来源:MobileServiceClient.Test.cs

示例10: InvokeCustomAPIPostWithBody

        public async Task InvokeCustomAPIPostWithBody()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("{\"id\":3}");
            MobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack);

            var myParams = new Dictionary<string, string>() { { "a", "1" }, { "b", "2" } };
            var body = "{\"test\" : \"one\"}";
            IntType expected = await service.InvokeApiAsync<string, IntType>("calculator/add", body, HttpMethod.Post, myParams);

            Assert.AreEqual(hijack.Request.RequestUri.Query, "?a=1&b=2");
            Assert.IsNotNull(hijack.Request.Content);
        }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:13,代码来源:MobileServiceClient.Test.cs

示例11: InvokeCustomAPIGetWithParamsJToken

        public async Task InvokeCustomAPIGetWithParamsJToken()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("{\"id\":3}");
            MobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack);

            var myParams = new Dictionary<string, string>() { { "a", "1" }, { "b", "2" } };
            JToken expected = await service.InvokeApiAsync("calculator/add", HttpMethod.Get, myParams);

            Assert.AreEqual(hijack.Request.RequestUri.Query, "?a=1&b=2");
        }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:11,代码来源:MobileServiceClient.Test.cs

示例12: InvokeCustomAPIGetJToken

        public async Task InvokeCustomAPIGetJToken()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("{\"id\":3}");
            MobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack);
            MobileAppUriValidator mobileAppUriValidator = new MobileAppUriValidator(service);

            JToken expected = await service.InvokeApiAsync("calculator/add?a=1&b=2", HttpMethod.Get, null);

            Assert.AreEqual(hijack.Request.RequestUri.LocalPath, mobileAppUriValidator.GetApiUriPath("calculator/add"));
            Assert.AreEqual(hijack.Request.RequestUri.Query, "?a=1&b=2");
            Assert.AreEqual(3, (int)expected["id"]);
        }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:13,代码来源:MobileServiceClient.Test.cs

示例13: InvokeCustomAPIPostJTokenBooleanPrimative

        public async Task InvokeCustomAPIPostJTokenBooleanPrimative()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("{\"id\":3}");
            MobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack);
            hijack.OnSendingRequest = async request =>
            {
                string content = await request.Content.ReadAsStringAsync();
                Assert.AreEqual(content, "true");

                return request;
            };

            JToken expected = await service.InvokeApiAsync("calculator/add", new JValue(true));
        }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:15,代码来源:MobileServiceClient.Test.cs

示例14: InvokeCustomAPIPostJToken

        public async Task InvokeCustomAPIPostJToken()
        {
            TestHttpHandler hijack = new TestHttpHandler();
            hijack.SetResponseContent("{\"id\":3}");
            MobileServiceClient service = new MobileServiceClient("http://www.test.com", "secret...", hijack);

            JObject body = JToken.Parse("{\"test\":\"one\"}") as JObject;
            JToken expected = await service.InvokeApiAsync("calculator/add", body);
            Assert.IsNotNull(hijack.Request.Content);
        }
开发者ID:RecursosOnline,项目名称:azure-mobile-services,代码行数:10,代码来源:MobileServiceClient.Test.cs

示例15: InvokeCustomAPIWithEmptyStringResponse_Success

        public async Task InvokeCustomAPIWithEmptyStringResponse_Success()
        {
            TestHttpHandler hijack = new TestHttpHandler();

            hijack.Response = new HttpResponseMessage(System.Net.HttpStatusCode.OK);
            hijack.Response.Content = new StringContent("", Encoding.UTF8, "application/json");

            MobileServiceClient service = new MobileServiceClient(MobileAppUriValidator.DummyMobileApp, hijack);
            MobileAppUriValidator mobileAppUriValidator = new MobileAppUriValidator(service);

            JToken expected = await service.InvokeApiAsync("testapi");
            Assert.AreEqual(hijack.Request.RequestUri.LocalPath, mobileAppUriValidator.GetApiUriPath("testapi"));
            Assert.AreEqual(expected, null);
        }
开发者ID:Azure,项目名称:azure-mobile-apps-net-client,代码行数:14,代码来源:MobileServiceClient.Test.cs


注:本文中的MobileServiceClient.InvokeApiAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。