예제 #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);
            }
        }
예제 #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);
            }
        }
예제 #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);
     });
 }
예제 #7
0
        private void CheckSerialization(Envelope envelope, params Attachment[] attachments)
        {
            var message     = Messages.Create(envelope, attachments);
            var mimeEntity  = As4MessageToMimeEntity.Serialize(message);
            var contentType = mimeEntity.ContentType;
            var stream      = new MemoryStream();

            mimeEntity.WriteTo(stream, true);
            stream.Position = 0;
            var decodedEntity  = MimeEntity.Load(contentType, stream);
            var decodedMessage = MimeEntityToAs4Message.Deserialize(decodedEntity);

            MessageAssert.AreEqual(message, decodedMessage);
        }
예제 #8
0
        private void CheckSendAndReceive(As4Message expectedRequest)
        {
            Action <As4Message> handler = actualMessage =>
            {
                MessageAssert.AreEqual(expectedRequest, actualMessage);
            };

            using (Servers.Create(Url, handler))
            {
                var client = new As4Client();
                var result = client.Send(new Uri(Url), expectedRequest);
                Assert.IsNull(result);
            }
        }
예제 #9
0
        private void CheckSendAndReceive(As4Message expectedRequest, As4Message expectedResponse)
        {
            Func <As4Message, As4Message> handler = actualRequest =>
            {
                MessageAssert.AreEqual(expectedRequest, actualRequest);
                return(expectedResponse);
            };

            using (Servers.Create(Url, handler))
            {
                var client         = new As4Client();
                var actualResponse = client.Send(new Uri(Url), expectedRequest);
                MessageAssert.AreEqual(expectedResponse, actualResponse);
            }
        }
        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
                    );
            }
        }
예제 #11
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);
                }
            }
        }
예제 #12
0
파일: KRPCTest.cs 프로젝트: key50/My_kRPC
        public void GetServices()
        {
            var services = global::KRPC.Service.KRPC.KRPC.GetServices();

            Assert.IsNotNull(services);
            Assert.AreEqual(4, services.ServicesList.Count);

            var service = services.ServicesList.First(x => x.Name == "KRPC");

            Assert.AreEqual(67, service.Procedures.Count);
            Assert.AreEqual(2, service.Classes.Count);
            Assert.AreEqual(1, service.Enumerations.Count);

            int foundProcedures = 0;

            foreach (var proc in service.Procedures)
            {
                if (proc.Name == "GetClientID")
                {
                    MessageAssert.HasReturnType(proc, typeof(byte[]));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "GetClientName")
                {
                    MessageAssert.HasReturnType(proc, typeof(string));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "GetStatus")
                {
                    MessageAssert.HasReturnType(proc, typeof(global::KRPC.Service.Messages.Status));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "GetServices")
                {
                    MessageAssert.HasReturnType(proc, typeof(global::KRPC.Service.Messages.Services));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "AddStream")
                {
                    MessageAssert.HasReturnType(proc, typeof(global::KRPC.Service.Messages.Stream));
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, typeof(global::KRPC.Service.Messages.ProcedureCall), "call");
                    MessageAssert.HasParameterWithDefaultValue(proc, 1, typeof(bool), "start", true);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "StartStream")
                {
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, typeof(ulong), "id");
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "SetStreamRate")
                {
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasParameters(proc, 2);
                    MessageAssert.HasParameter(proc, 0, typeof(ulong), "id");
                    MessageAssert.HasParameter(proc, 1, typeof(float), "rate");
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "RemoveStream")
                {
                    MessageAssert.HasNoReturnType(proc);
                    MessageAssert.HasParameters(proc, 1);
                    MessageAssert.HasParameter(proc, 0, typeof(ulong), "id");
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "get_Clients")
                {
                    MessageAssert.HasReturnType(proc, typeof(IList <global::KRPC.Utils.Tuple <byte[], string, string> >));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else if (proc.Name == "get_CurrentGameScene")
                {
                    MessageAssert.HasReturnType(proc, typeof(global::KRPC.Service.KRPC.KRPC.GameScene));
                    MessageAssert.HasNoParameters(proc);
                    MessageAssert.HasDocumentation(proc);
                }
                else
                {
                    foundProcedures--;
                }
                foundProcedures++;
            }
            Assert.AreEqual(10, foundProcedures);

            bool foundEnumeration = false;

            foreach (var enumeration in service.Enumerations)
            {
                if (enumeration.Name == "GameScene")
                {
                    foundEnumeration = true;
                    MessageAssert.HasDocumentation(enumeration,
                                                   "<doc>\n<summary>\nThe game scene. See <see cref=\"M:KRPC.CurrentGameScene\" />.\n</summary>\n</doc>");
                    MessageAssert.HasValues(enumeration, 5);
                    MessageAssert.HasValue(enumeration, 0, "SpaceCenter", 0,
                                           "<doc>\n<summary>\nThe game scene showing the Kerbal Space Center buildings.\n</summary>\n</doc>");
                    MessageAssert.HasValue(enumeration, 1, "Flight", 1,
                                           "<doc>\n<summary>\nThe game scene showing a vessel in flight (or on the launchpad/runway).\n</summary>\n</doc>");
                    MessageAssert.HasValue(enumeration, 2, "TrackingStation", 2,
                                           "<doc>\n<summary>\nThe tracking station.\n</summary>\n</doc>");
                    MessageAssert.HasValue(enumeration, 3, "EditorVAB", 3,
                                           "<doc>\n<summary>\nThe Vehicle Assembly Building.\n</summary>\n</doc>");
                    MessageAssert.HasValue(enumeration, 4, "EditorSPH", 4,
                                           "<doc>\n<summary>\nThe Space Plane Hangar.\n</summary>\n</doc>");
                }
            }
            Assert.IsTrue(foundEnumeration);

            int foundExceptions = 0;

            foreach (var exception in service.Exceptions)
            {
                if (exception.Name == "InvalidOperationException")
                {
                    MessageAssert.HasDocumentation(exception,
                                                   "<doc>\n<summary>\nA method call was made to a method that is invalid\ngiven the current state of the object.\n</summary>\n</doc>");
                }
                else if (exception.Name == "ArgumentException")
                {
                    MessageAssert.HasDocumentation(exception,
                                                   "<doc>\n<summary>\nA method was invoked where at least one of the passed arguments does not\nmeet the parameter specification of the method.\n</summary>\n</doc>");
                }
                else if (exception.Name == "ArgumentNullException")
                {
                    MessageAssert.HasDocumentation(exception,
                                                   "<doc>\n<summary>\nA null reference was passed to a method that does not accept it as a valid argument.\n</summary>\n</doc>");
                }
                else if (exception.Name == "ArgumentOutOfRangeException")
                {
                    MessageAssert.HasDocumentation(exception,
                                                   "<doc>\n<summary>\nThe value of an argument is outside the allowable range of values as defined by the invoked method.\n</summary>\n</doc>");
                }
                foundExceptions++;
            }
            Assert.AreEqual(4, foundExceptions);
        }