Example #1
0
        public async Task ListVlans_Paged_Success()
        {
            CloudControlClient client = CreateCloudControlClientWithUserAccount(request =>
            {
                MessageAssert.AcceptsMediaType(request,
                                               "application/json"
                                               );
                MessageAssert.HasRequestUri(request,
                                            CreateApiUri($"caas/2.4/{TestOrganizationId}/network/vlan?networkDomainId=909dd855-4b2c-49a9-8151-46969a1a9380&pageNumber=1&pageSize=250")
                                            );

                return(request.CreateResponse(HttpStatusCode.OK,
                                              responseBody: TestResponses.ListVlans_Success,
                                              mediaType: "application/json"
                                              ));
            });

            using (client)
            {
                Vlans vlans = await client.ListVlans(
                    networkDomainId : new Guid("909dd855-4b2c-49a9-8151-46969a1a9380"),
                    paging : new Paging
                {
                    PageNumber = 1,
                    PageSize   = 250
                }
                    );

                Assert.NotNull(vlans);
                Assert.Equal(1, vlans.TotalCount);
                Assert.Equal(1, vlans.Items.Count);
            }
        }
        public async Task ListNetworkDomains_Paged_Success()
        {
            CloudControlClient client = CreateCloudControlClientWithUserAccount(request =>
            {
                MessageAssert.AcceptsMediaType(request,
                                               "application/json"
                                               );
                MessageAssert.HasRequestUri(request,
                                            CreateApiUri($"caas/2.4/{TestOrganizationId}/network/networkDomain?datacenterId=AU9&pageNumber=1&pageSize=250")
                                            );

                return(request.CreateResponse(HttpStatusCode.OK,
                                              responseBody: TestResponses.ListNetworkDomains_Success,
                                              mediaType: "application/json"
                                              ));
            });

            using (client)
            {
                NetworkDomainQuery query  = NetworkDomainQuery.ByDatacenter("AU9");
                Paging             paging = new Paging
                {
                    PageNumber = 1,
                    PageSize   = 250
                };

                NetworkDomains networkDomains = await client.ListNetworkDomains(query, paging);

                Assert.NotNull(networkDomains);
                Assert.Equal(2, networkDomains.TotalCount);
                Assert.Equal(2, networkDomains.Items.Count);
            }
        }
Example #3
0
 public void TypedRequest_ExpectXml_Sets_AcceptHeader()
 {
     RequestAssert.Message(TypedBaseRequest.ExpectXml(), HttpMethod.Get, requestMessage =>
     {
         MessageAssert.AcceptsMediaType(requestMessage, WellKnownMediaTypes.Xml);
     });
 }
        public async Task Get_Account_Success()
        {
            CloudControlClient client = CreateCloudControlClient(request =>
            {
                MessageAssert.AcceptsMediaType(request, "text/xml");
                MessageAssert.HasRequestUri(request,
                                            CreateApiUri("oec/0.9/myaccount")
                                            );

                return(request.CreateResponse(HttpStatusCode.OK, MyAccountXml, mediaType: "text/xml"));
            });

            using (client)
            {
                UserAccount account = await client.GetAccount();

                Assert.NotNull(account);
                Assert.Equal("test_user", account.UserName);
                Assert.Equal("Test User", account.FullName);
                Assert.Equal("Test", account.FirstName);
                Assert.Equal("User", account.LastName);
                Assert.Equal("*****@*****.**", account.EmailAddress);
                Assert.Equal("Department 1", account.Department);
                Assert.Equal(TestOrganizationId, account.OrganizationId);
            }
        }
Example #5
0
        public async Task Request_PostAsJson_RelativeUri()
        {
            HttpClient client = JsonTestClients.ExpectJson(
                new Uri(BaseUri, "foo/bar"), HttpMethod.Post, responseBody: 1234,
                assertion: async request =>
            {
                MessageAssert.AcceptsMediaType(request, WellKnownMediaTypes.Json);

                await MessageAssert.BodyIsAsync(request, "\"1234\"");
            }
                );

            using (client)
            {
                HttpRequest request =
                    BaseRequest.WithRelativeUri("foo/bar")
                    .UseJson().ExpectJson();

                int responseBody = await
                                   client.PostAsJsonAsync(request,
                                                          postBody : 1234.ToString()
                                                          )
                                   .ReadContentAsAsync <int>();

                Assert.Equal(1234, responseBody);
            }
        }
 public void Request_ExpectJson_Sets_AcceptHeader()
 {
     RequestAssert.Message(BaseRequest.ExpectJson(), HttpMethod.Get, requestMessage =>
     {
         MessageAssert.AcceptsMediaType(requestMessage, WellKnownMediaTypes.Json);
     });
 }
        public async Task CreateNetworkDomain_Success()
        {
            CloudControlClient client = CreateCloudControlClientWithUserAccount(async request =>
            {
                MessageAssert.AcceptsMediaType(request,
                                               "application/json"
                                               );
                MessageAssert.HasRequestUri(request,
                                            CreateApiUri($"caas/2.4/{TestOrganizationId}/network/deployNetworkDomain")
                                            );

                JObject expectedRequestBody = (JObject)JToken.Parse(
                    TestRequests.CreateNetworkDomain_Success
                    );

                JObject actualRequestBody = (JObject)JToken.Parse(
                    await request.Content.ReadAsStringAsync()
                    );

                Assert.Equal(
                    expectedRequestBody.ToString(Formatting.Indented).Trim(),
                    actualRequestBody.ToString(Formatting.Indented).Trim()
                    );

                return(request.CreateResponse(HttpStatusCode.OK,
                                              responseBody: TestResponses.CreateNetworkDomain_Success,
                                              mediaType: "application/json"
                                              ));
            });

            using (client)
            {
                Guid expectedNetworkDomainId = new Guid("f14a871f-9a25-470c-aef8-51e13202e1aa");
                Guid actualNetworkDomainId   = await client.CreateNetworkDomain(
                    datacenterId : "AU9",
                    name : "A Network Domain",
                    description : "This is a network domain",
                    type : NetworkDomainType.Essentials
                    );

                Assert.Equal(
                    expectedNetworkDomainId,
                    actualNetworkDomainId
                    );
            }
        }
Example #8
0
        public async Task Request_Post_RelativeUri_ExpectJson()
        {
            HttpClient client = JsonTestClients.ExpectJson(
                new Uri(BaseUri, "foo/bar"), HttpMethod.Post,
                responseBody: "Success!",
                assertion: async request =>
            {
                MessageAssert.AcceptsMediaType(request, WellKnownMediaTypes.Json);

                await MessageAssert.BodyIsAsync(request,
                                                "{\"Foo\":\"Bar\",\"Baz\":1234}"
                                                );
            }
                );

            using (client)
            {
                HttpRequest request =
                    BaseRequest.WithRelativeUri("foo/bar")
                    .UseJson().ExpectJson();

                HttpResponseMessage response = await
                                               client.PostAsJsonAsync(request,
                                                                      postBody : new
                {
                    Foo = "Bar",
                    Baz = 1234
                }
                                                                      );

                using (response)
                {
                    Assert.True(response.IsSuccessStatusCode);
                    Assert.NotNull(response.Content?.Headers?.ContentType);
                    Assert.Equal(WellKnownMediaTypes.Json, response.Content.Headers.ContentType.MediaType);

                    string responseBody = await response.ReadContentAsAsync <string>();

                    Assert.Equal("Success!", responseBody);
                }
            }
        }