예제 #1
0
        public void CreateAPostUsingTheWrongDataTypes()
        {
            string payload = @"
            { 
              ""id"": ""test"", 
              ""userId"": ""test"", 
              ""title"": 1, 
              ""body"": 1 
            }";

            ResponseContext responseContext = new RestAssured()
                                              .Given()
                                              .Name(Name)
                                              .Header("Content-Type", "application/json")
                                              .Body(payload)
                                              .When()
                                              .Post("https://jsonplaceholder.typicode.com/posts")
                                              .Then();

            ResponseContext testStatus = responseContext.TestStatus(
                "Verify a Post resource cannot be created with an empty Body with HTTP POST",
                x =>
            {
                if (x == 201)
                {
                    Assert.Pass("An expected failure occured due to a known issue with the API - wrong data types in Body");
                }
                else
                {
                    Assert.Fail();
                }

                return(x != 201);
            });
        }
예제 #2
0
        public void CreateANewPost()
        {
            var    postDto = new PostBuilder().Build();
            string payload = JsonConvert.SerializeObject(postDto);

            ResponseContext responseContext = new RestAssured()
                                              .Given()
                                              .Name(Name)
                                              .Header("Content-Type", "application/json")
                                              .Body(payload)
                                              .When()
                                              .Post("https://jsonplaceholder.typicode.com/posts")
                                              .Then();

            responseContext.TestBody(
                "Verify a new Post resource can be created with HTTP POST by confirming the Id returned in the response",
                x =>
            {
                int.TryParse(x.id.ToString(), out int actualId);
                Assert.AreEqual(101, actualId);
                return(x.id == 101);
            });

            responseContext.TestStatus(
                "Verify a new Post resource can be created with HTTP POST by confirming the response HTTP status code",
                x =>
            {
                Assert.AreEqual(201, x);
                return(x == 201);
            });


            responseContext.AssertAll();
        }
예제 #3
0
        public void DeleteAnExistingPost()
        {
            var responseContext = new RestAssured()
                                  .Given()
                                  .Name(Name)
                                  .Header("Content-Type", "application/json")
                                  .When()
                                  .Delete("https://jsonplaceholder.typicode.com/posts/1")
                                  .Then();

            responseContext.TestStatus(
                "Verify an existing Post resource can be deleted with HTTP DELETE by confirming the response HTTP status code",
                x =>
            {
                Assert.AreEqual(200, x);
                return(x == 200);
            })
            .Assert("Verify");
        }