Esempio n. 1
0
 /// <summary>
 /// Constructor that loads the "BaseEnvironment.json" parameters
 /// </summary>
 public ScenarioContext()
 {
     try
     {
         BaseEnvironmentObj = RetrieveTestData.GetResourceAsJObject("BaseEnvironment.json");
     }
     catch (System.Exception e)
     {
         Console.WriteLine("Some is wrong with the BaseEnvironment.json file. It must be present on root of the test project");
         throw new System.Exception(e.Message);
     }
 }
        public void TC_02_AssertActionPOSTApiValuesByID_OK(string tesCaseName, string resourcePath, HttpStatusCode expectedResult)
        {
            //Arrange
            uriBuilder.Path = resourcePath;

            var paramsBody = RetrieveTestData.GetRequestParameters(scenarioContext.BaseEnvironmentObj["testDataPath"]["filePath"].ToString(), tesCaseName);

            //Act
            var response = _httpPostRequest.MakePostRequet(uriBuilder, paramsBody);

            //Assert
            Assert.Equal(expectedResult, response.StatusCode);
        }
        public void TC_08_AssertJsonSchema(string testCaseName, string resourcePath, string schemaFilePath)
        {
            //Arrange
            uriBuilder.Path = resourcePath;

            var schemaString = RetrieveTestData.GetResourceAsString(schemaFilePath);

            //Act
            var response = _httpGetRequest.MakeGetRequest(uriBuilder);

            //Assert
            var result = SchemaAssertions.ValidateJsonSchema(schemaString, response);

            Assert.True(result);
        }
        public void TC_07_AssertReturnedData(string testCaseName, string resourcePath)
        {
            //Arrange
            uriBuilder.Path = resourcePath;

            var expectedObj = RetrieveTestData.GetRequestParameters <ParamsBodyTest>(scenarioContext.BaseEnvironmentObj["testDataPath"]["filePath"].ToString(),
                                                                                     testCaseName);

            //Act
            var response = _httpGetRequest.MakeGetRequest(uriBuilder, HttpMethod.GET);

            //Assert
            var result = ResponseContentAssertions.AssertResponseDataObject <ParamsBodyTest>(response, expectedObj);

            Assert.True(result);
        }
        public void TC_06_AssertActionGETApiValuesByID_OK_WithToken(string resourcePath, HttpStatusCode expectedResult)
        {
            //Arrange
            uriBuilder.Path = resourcePath;

            UriBuilder oauthURI = new UriBuilder(scenarioContext.BaseEnvironmentObj["endpoints"]["service_2"].ToString())
            {
                Path = "/token"
            };

            var paramsBody = RetrieveTestData.GetResourceAsJObject(scenarioContext.BaseEnvironmentObj["testDataPath"]["filePath"].ToString());

            var _jwtToken = _oauthAuthentication.BearerAuthentication(oauthURI, paramsBody);

            //Act
            var response = _httpGetRequest.MakeGetRequest(uriBuilder, HttpMethod.GET, _jwtToken);

            //Assert
            var result = StatusCodeAssertions.AssertStatusCode(response.StatusCode, expectedResult);

            Assert.True(result);
        }