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


C# Http.HttpResponseAbstraction類代碼示例

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


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

示例1: ExceptionthrownWhenGettingAStorageFolderThatDoesNotExistAndCannotBeInferred

        public async Task ExceptionthrownWhenGettingAStorageFolderThatDoesNotExistAndCannotBeInferred()
        {
            var containerName = "TestContainer";
            var folderName = "a/b/c/";
            var headers = new HttpHeadersAbstraction()
            {
                {"X-Container-Bytes-Used", "1234"},
                {"X-Container-Object-Count", "1"}
            };

            var payload = @"[]";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
            this.StorageServiceRestClient.Responses.Enqueue(restResp);

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
            var resp = await client.GetStorageFolder(containerName, folderName);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:20,代碼來源:StorageServicePocoClientTests.cs

示例2: CanGetNetworksWithOkResponse

        public async Task CanGetNetworksWithOkResponse()
        {
            var payload = @"{
                ""networks"": [
                    {
                        ""status"": ""ACTIVE"",
                        ""subnets"": [
                            ""d3839504-ec4c-47a4-b7c7-07af079a48bb""
                        ],
                        ""name"": ""myNetwork"",
                        ""router:external"": false,
                        ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
                        ""admin_state_up"": true,
                        ""shared"": false,
                        ""id"": ""12345""
                    }
                ]
            }";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
            this.NetworkServiceRestClient.Responses.Enqueue(restResp);

            var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
            var result = await client.GetNetworks();

            Assert.IsNotNull(result);

            var networks = result.ToList();
            Assert.AreEqual(1, networks.Count());

            var network = networks.First();
            Assert.AreEqual("myNetwork", network.Name);
            Assert.AreEqual("12345", network.Id);
            Assert.AreEqual(NetworkStatus.Active, network.Status);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:37,代碼來源:NetworkServicePocoClientTests.cs

示例3: CannotAuthenticateWithNotFoundResponse

        public async Task CannotAuthenticateWithNotFoundResponse()
        {
            var creds = GetValidCredentials();

            var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NotFound);
            this.RestClient.Response = restResp;

            var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
            await client.Authenticate();
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:10,代碼來源:IdentityServicePocoClientTests.cs

示例4: CanCreateFloatingIpWithCreatedResponse

        public async Task CanCreateFloatingIpWithCreatedResponse()
        {
            var payload = @"{
                ""floatingip"":
                    {
                        ""router_id"": ""fafac59b-a94a-4525-8700-f4f448e0ac97"",
                        ""status"": ""ACTIVE"",
                        ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
                        ""floating_network_id"": ""3eaab3f7-d3f2-430f-aa73-d07f39aae8f4"",
                        ""fixed_ip_address"": ""10.0.0.2"",
                        ""floating_ip_address"": ""172.0.0.1"",
                        ""port_id"": ""9da94672-6e6b-446c-9579-3dd5484b31fd"",
                        ""id"": ""12345""
                    }
            }";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.Created);
            this.NetworkServiceRestClient.Responses.Enqueue(restResp);

            var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
            var result = await client.CreateFloatingIp("12345");

            Assert.IsNotNull(result);

            Assert.AreEqual("12345", result.Id);
            Assert.AreEqual("172.0.0.1", result.FloatingIpAddress);
            Assert.AreEqual(FloatingIpStatus.Active, result.Status);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:30,代碼來源:NetworkServicePocoClientTests.cs

示例5: CanDeleteFloatingIpWithNoContentResponse

        public async Task CanDeleteFloatingIpWithNoContentResponse()
        {
            
            var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
            this.NetworkServiceRestClient.Responses.Enqueue(restResp);

            var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
            await client.DeleteFloatingIp("12345");
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:9,代碼來源:NetworkServicePocoClientTests.cs

示例6: CanDeleteComputeServerMetadataWithOkResponse

        public async Task CanDeleteComputeServerMetadataWithOkResponse()
        {
            var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.OK);
            this.ComputeServiceRestClient.Responses.Enqueue(restResp);

            var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
            await client.DeleteServerMetadata("1", "item1");
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:8,代碼來源:ComputeServicePocoClientTests.cs

示例7: CanGetComputeImageWithOkResponse

        public async Task CanGetComputeImageWithOkResponse()
        {
            var created = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
            var updated = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
            var payload = @"{
                                    ""image"" : {
                                        ""name"": ""image1"",
                                        ""status"": ""ACTIVE"",
                                        ""updated"": ""2014-06-30T16:56:32Z"",
                                        ""created"": ""2014-05-30T16:56:32Z"",
                                        ""minRam"": 512,
                                        ""minDisk"": 10,
                                        ""progress"": 100,
                                        ""links"": [
                                            {
                                                ""href"": ""http://someuri.com/v2/images/12345"",
                                                ""rel"": ""self""
                                            },
                                            {
                                                ""href"": ""http://someuri.com/images/12345"",
                                                ""rel"": ""bookmark""
                                            }
                                        ],
                                        ""id"": ""12345""
                                    }
                                }";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
            this.ComputeServiceRestClient.Responses.Enqueue(restResp);

            var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
            var result = await client.GetImage("12345");

            Assert.IsNotNull(result);
            Assert.AreEqual("image1", result.Name);
            Assert.AreEqual("ACTIVE", result.Status);
            Assert.AreEqual("12345", result.Id);
            Assert.AreEqual(512, result.MinimumRamSize);
            Assert.AreEqual(10, result.MinimumDiskSize);
            Assert.AreEqual(100, result.UploadProgress);
            Assert.AreEqual(created.ToLongTimeString(), result.CreateDate.ToLongTimeString());
            Assert.AreEqual(updated.ToLongTimeString(), result.LastUpdated.ToLongTimeString());
            Assert.AreEqual(new Uri("http://someuri.com/images/12345"), result.PermanentUri);
            Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), result.PublicUri);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:47,代碼來源:ComputeServicePocoClientTests.cs

示例8: CanGetComputeServerMetadataWithOkResponse

        public async Task CanGetComputeServerMetadataWithOkResponse()
        {
            var metadata = new Dictionary<string, string>() { { "item1", "value1" }, { "item2", "value2" } };
            var content = TestHelper.CreateStream(GenerateMetadataPayload(metadata));

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
            this.ComputeServiceRestClient.Responses.Enqueue(restResp);

            var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
            var respData = await client.GetServerMetadata("1");

            Assert.AreEqual(2, respData.Count);
            Assert.AreEqual("value1", respData["item1"]);
            Assert.AreEqual("value2", respData["item2"]);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:15,代碼來源:ComputeServicePocoClientTests.cs

示例9: CanCreateComputeServerWithOkResponse

        public async Task CanCreateComputeServerWithOkResponse()
        {
            var serverId = "98765";
            var keyName = "MyKey";
            var publicUrl = "http://15.125.87.81:8774/v2/ffe683d1060449d09dac0bf9d7a371cd/servers/" + serverId;
            var permUrl = "http://15.125.87.81:8774/ffe683d1060449d09dac0bf9d7a371cd/servers/" + serverId;
            var adminPassword = "ABCDEF";
            var serverFixture = @"{{
                ""server"": {{
                    ""security_groups"": [
                        {{
                            ""name"": ""default""
                        }},
                        {{
                            ""name"": ""MyGroup""
                        }}
                    ],
                    ""OS-DCF:diskConfig"": ""MANUAL"",
                    ""id"": ""{0}"",
                    ""links"": [
                        {{
                            ""href"": ""{1}"",
                            ""rel"": ""self""
                        }},
                        {{
                            ""href"": ""{2}"",
                            ""rel"": ""bookmark""
                        }}
                    ],
                    ""adminPass"": ""{3}""
                }}
            }}";

            var payload = string.Format(serverFixture, serverId, publicUrl, permUrl, adminPassword);
            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
            this.ComputeServiceRestClient.Responses.Enqueue(restResp);

            var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
            var result = await client.CreateServer("MyServer", "12345", "1", "54321", keyName, new List<string>() { "MyGroup" });

            Assert.IsNotNull(result);

            Assert.AreEqual(serverId, result.Id);
            Assert.AreEqual(adminPassword, result.AdminPassword);
            Assert.AreEqual(new Uri(publicUrl), result.PublicUri);
            Assert.AreEqual(new Uri(permUrl), result.PermanentUri);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:49,代碼來源:ComputeServicePocoClientTests.cs

示例10: CanGetComputeKeyPairWithNonAuthoritativeResponse

        public async Task CanGetComputeKeyPairWithNonAuthoritativeResponse()
        {
            var content = TestHelper.CreateStream(KeyPairPayload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
            this.ComputeServiceRestClient.Responses.Enqueue(restResp);

            var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
            var keyPair = await client.GetKeyPair("MyKey");

            Assert.IsNotNull(keyPair);
            Assert.AreEqual("MyKey", keyPair.Name);
            Assert.AreEqual("ABCDEF", keyPair.PublicKey);
            Assert.AreEqual("12345", keyPair.Fingerprint);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:15,代碼來源:ComputeServicePocoClientTests.cs

示例11: CanGetComputeFlavorsWithNonAuthoritativeResponse

        public async Task CanGetComputeFlavorsWithNonAuthoritativeResponse()
        {
            var payload = @"{
                            ""flavors"": [
                                {
                                    ""id"": ""1"",
                                    ""links"": [
                                        {
                                            ""href"": ""http://someuri.com/v2/flavors/1"",
                                            ""rel"": ""self""
                                        },
                                        {
                                            ""href"": ""http://someuri.com/flavors/1"",
                                            ""rel"": ""bookmark""
                                        }
                                    ],
                                    ""name"": ""m1.tiny""
                                }
                            ]
                        }";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
            this.ComputeServiceRestClient.Responses.Enqueue(restResp);

            var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
            var result = await client.GetFlavors();

            Assert.IsNotNull(result);

            var flavors = result.ToList();
            Assert.AreEqual(1, flavors.Count());

            var flavor = flavors.First();
            Assert.AreEqual("m1.tiny", flavor.Name);
            Assert.AreEqual("1", flavor.Id);
            Assert.AreEqual(new Uri("http://someuri.com/v2/flavors/1"), flavor.PublicUri);
            Assert.AreEqual(new Uri("http://someuri.com/flavors/1"), flavor.PermanentUri);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:40,代碼來源:ComputeServicePocoClientTests.cs

示例12: CanGetComputeKeyPairsWithOkResponse

        public async Task CanGetComputeKeyPairsWithOkResponse()
        {
            var content = TestHelper.CreateStream(KeyPairsPayload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
            this.ComputeServiceRestClient.Responses.Enqueue(restResp);

            var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
            var result = await client.GetKeyPairs();

            Assert.IsNotNull(result);

            var pairs = result.ToList();
            Assert.AreEqual(1, pairs.Count());

            var keyPair = pairs.First();
            Assert.AreEqual("MyKey", keyPair.Name);
            Assert.AreEqual("ABCDEF", keyPair.PublicKey);
            Assert.AreEqual("12345", keyPair.Fingerprint);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:20,代碼來源:ComputeServicePocoClientTests.cs

示例13: CanGetComputeImagesWithOkResponse

        public async Task CanGetComputeImagesWithOkResponse()
        {
            var payload = @"{
                            ""images"": [
                                {
                                    ""id"": ""12345"",
                                    ""links"": [
                                        {
                                            ""href"": ""http://someuri.com/v2/images/12345"",
                                            ""rel"": ""self""
                                        },
                                        {
                                            ""href"": ""http://someuri.com/images/12345"",
                                            ""rel"": ""bookmark""
                                        }
                                    ],
                                    ""name"": ""image1""
                                }
                            ]
                        }";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
            this.ComputeServiceRestClient.Responses.Enqueue(restResp);

            var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
            var result = await client.GetImages();

            Assert.IsNotNull(result);

            var images = result.ToList();
            Assert.AreEqual(1, images.Count());

            var image = images.First();
            Assert.AreEqual("image1", image.Name);
            Assert.AreEqual("12345", image.Id);
            Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
            Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:40,代碼來源:ComputeServicePocoClientTests.cs

示例14: ExceptionthrownWhenGettingAStorageFolderAndServerError

        public async Task ExceptionthrownWhenGettingAStorageFolderAndServerError()
        {
            var containerName = "TestContainer";
            var fodlerName = "a/b/b/";

            var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
            this.StorageServiceRestClient.Responses.Enqueue(restResp);

            var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
            await client.GetStorageFolder(containerName, fodlerName);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:11,代碼來源:StorageServicePocoClientTests.cs

示例15: CanUpdateComputeServerMetadataWithOkResponse

        public async Task CanUpdateComputeServerMetadataWithOkResponse()
        {
            var metadata = new Dictionary<string, string>() { { "item1", "value1" }, { "item2", "value2" } };

            var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.OK);
            this.ComputeServiceRestClient.Responses.Enqueue(restResp);

            var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
            await client.UpdateServerMetadata("1", metadata);
        }
開發者ID:jasonzhuyx,項目名稱:openstack-sdk-dotnet,代碼行數:10,代碼來源:ComputeServicePocoClientTests.cs


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