Example #1
0
        public void Check_Resource(string resourceName)
        {
            //Prepares a GET request for the first data from a resource API endpoint
            var response = restClient.Get(new RestRequest(resourceName + "/1"));

            //Prepares an output of the summarization of the request and response for each test
            string output = ResponseSummarization.GetInfo(response);

            //Asserts if it was successful
            Assert.That(response.IsSuccessful);

            //Outputs the summarization of the request and response even if the test succeeded for logging purposes
            Console.WriteLine(output);
        }
Example #2
0
        public void Validate_Location_Area_Of_A_Pokemon()
        {
            //Prepares a GET request for the first data from a resource API endpoint
            var response = restClient.Get(new RestRequest("pokemon/pikachu"));

            //Asserts if the request was successful
            Assert.That(response.IsSuccessful,
                        "Expected true for response.IsSuccessful but status received was: " +
                        response.StatusCode + "\n\n" +
                        ResponseSummarization.GetInfo(response));

            //Gets the location area for Pikachu and prepares it for issuing a GET Request for its endpoint
            var location_area_encounters_Method = JToken.Parse(response.Content)["location_area_encounters"].ToString();

            location_area_encounters_Method = location_area_encounters_Method.Substring(location_area_encounters_Method.IndexOf("/v2/") + 4);

            //Issues a GET Request for its locationAreas
            var locationAreaEncounterResponse = restClient.Get(new RestRequest(location_area_encounters_Method));

            //Asserts if the request was successful
            Assert.That(locationAreaEncounterResponse.IsSuccessful,
                        "Expected true for response.IsSuccessful but status received was: " +
                        locationAreaEncounterResponse.StatusCode + "\n\n" +
                        ResponseSummarization.GetInfo(locationAreaEncounterResponse));

            //Validates if each Location Area indeed has chances of encountering Pikachu
            foreach (JToken locationArea in JToken.Parse(locationAreaEncounterResponse.Content))
            {
                //Issues a GET Request for each location area
                var locationAreaResponse = restClient.Get(new RestRequest(
                                                              locationArea["location_area"]["url"].ToString().Substring(locationArea["location_area"]["url"].ToString().IndexOf("/v2/") + 4)
                                                              ));

                //Asserts if the request was successful
                Assert.That(locationAreaResponse.IsSuccessful,
                            "Expected true for response.IsSuccessful but status received was: " +
                            locationAreaResponse.StatusCode + "\n\n" +
                            ResponseSummarization.GetInfo(locationAreaResponse));

                //Asserts if the area indeed has chances of encountering Pikachu
                Assert.That(locationAreaResponse.Content.Contains("pikachu") &&
                            new List <JToken>(JToken.Parse(locationAreaResponse.Content).SelectTokens("$..pokemon.name")).Contains("pikachu"),
                            "Expected to find Pikachu as one of the Pokemons encountered in this location area but just encountered: \n" +
                            JsonConvert.SerializeObject(JToken.Parse(locationAreaResponse.Content).SelectTokens("$..pokemon.name"), Formatting.Indented));
            }
        }
Example #3
0
        public void Check_Endpoint(string resourceName)
        {
            //Sends a GET request for the resourceName gotten from GetAllResoruces IEnumerale
            var response = restClient.Get(new RestRequest(resourceName));

            //Prepares an output of the summarization of the request and response for each test
            string output = ResponseSummarization.GetInfo(response);

            //Asserts the response was successful
            Assert.That(response.IsSuccessful, output);

            //Asserts the content body matches the expected jSchema for it, if not, grabs the errors
            Assert.That(JToken.Parse(response.Content).IsValid(apiPaginationjSchema, out IList <string> errorMessages)
                        , output + "\n" + string.Join("\n", errorMessages));

            //Outputs the summarization of the request and response even if the test succeeded for logging purposes
            Console.WriteLine(output);
        }
Example #4
0
        public void Search_For_A_Pokemon_By_Its_Name()
        {
            //Prepares a GET request for the searching for a pokemon by its name
            var response = restClient.Get(new RestRequest("pokemon/pikachu"));

            //Prepares an output of the summarization of the request and response for each test
            string output = ResponseSummarization.GetInfo(response);

            //Asserts if the request was successful
            Assert.That(response.IsSuccessful,
                        "Expected true for response.IsSuccessful but status received was: " +
                        response.StatusCode);

            //Parses response.Content to JToken for easier json manipulation
            var contentJToken = JToken.Parse(response.Content);

            //Asserts the returned pokemon is indeed Pikachu, if not returns which one it returned
            Assert.That(contentJToken["name"].ToString().Equals("pikachu"),
                        "Expected returned pokemon should have been Pikachu but was: " +
                        contentJToken["name"].ToString());

            //Outputs the summarization of the request and response even if the test succeeded for logging purposes
            Console.WriteLine(output);
        }