public void TestSecureGetEndPoint() { Dictionary <string, string> httpHeader = new Dictionary <string, string>(); httpHeader.Add("Accept", "application/json"); //httpHeader.Add("Authorization", "Basic YWRtaW46d2VsY29tZQ=="); string authHeader = Base64StringConverter.GetBase64String("admin", "welcome"); authHeader = "Basic " + authHeader; httpHeader.Add("Authorization", authHeader); RestResponse restResponse = HttpClientHelper.PerformGetRequest(getUrl, httpHeader); // List<JsonRootObject> jsonRootObject = JsonConvert.DeserializeObject<List<JsonRootObject>>(restResponse.ResponseContent); // Console.WriteLine(jsonRootObject[0].ToString()); Assert.AreEqual(200, restResponse.StatusCode); List <JsonRootObject> jsonData = ResponseDataHelper.DeserializeJsonResponse <List <JsonRootObject> >(restResponse.ResponseContent); Console.WriteLine(jsonData.ToString()); }
public void TestPutUsingJsonData() { int id = random.Next(1000); string jsonData = "{" + "\"BrandName\": \"Alienware\"," + "\"Features\": {" + "\"Feature\": [" + "\"8th Generation Intel® Core™ i5-8300H\"," + "\"Windows 10 Home 64-bit English\"," + "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," + "\"8GB, 2x4GB, DDR4, 2666MHz\"" + "]" + "}," + "\"Id\": " + id + "," + "\"LaptopName\": \"Alienware M17\"" + "}"; Dictionary <string, string> headers = new Dictionary <string, string>() { { "Accept", "application/json" } }; restResponse = HttpClientHelper.PerformPostRequest(postUrl, jsonData, jsonMediaType, headers); Assert.AreEqual(200, restResponse.StatusCode); jsonData = "{" + "\"BrandName\": \"Alienware\"," + "\"Features\": {" + "\"Feature\": [" + "\"8th Generation Intel® Core™ i5-8300H\"," + "\"Windows 10 Home 64-bit English\"," + "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," + "\"1 TB of SSD\"," + "\"8GB, 2x4GB, DDR4, 2666MHz\"" + "]" + "}," + "\"Id\": " + id + "," + "\"LaptopName\": \"Alienware M17\"" + "}"; using (HttpClient httpClient = new HttpClient()) { HttpContent httpContent = new StringContent(jsonData, Encoding.UTF8, jsonMediaType); Task <HttpResponseMessage> httpResponseMessage = httpClient.PutAsync(putUrl, httpContent); restResponse = new RestResponse((int)httpResponseMessage.Result.StatusCode, httpResponseMessage.Result.Content.ReadAsStringAsync().Result); Assert.AreEqual(200, restResponse.StatusCode); } restResponse = HttpClientHelper.PerformGetRequest(getUrl + id, headers); Assert.AreEqual(200, restResponse.StatusCode); JsonRootObject jsonObject = ResponseDataHelper.DeserializeJsonResponse <JsonRootObject>(restResponse.ResponseContent); Assert.IsTrue(jsonObject.Features.Feature.Contains("1 TB of SSD"), "item not found"); }
public void GetUsingHelperMethod() { Dictionary <string, string> httpHeader = new Dictionary <string, string>(); httpHeader.Add("Accept", "application/json"); RestResponse restResponse = HttpClientHelper.PerformGetRequest(getUrl, httpHeader); List <Root> rootObj = ResponseDataHelper.DeserializeJsonResponse <List <Root> >(restResponse.ResponseData); Console.WriteLine(rootObj.ToString()); }
private void SendGetRequest() { Dictionary <string, string> httpHeader = new Dictionary <string, string>(); httpHeader.Add("Accept", "application/json"); restResponse = httpClientHelperAsync.PerformGetRequest(delayGetUrl, httpHeader).GetAwaiter().GetResult(); List <Root> rootObj = ResponseDataHelper.DeserializeJsonResponse <List <Root> >(restResponse.ResponseData); Console.WriteLine(rootObj.ToString()); }
public void CheckForecastLongitude() { RestResponse restResponse = GetRestReponse(); WeatherInfo jsonData = ResponseDataHelper.DeserializeJsonResponse <WeatherInfo>(restResponse.ResponseContent); string actualLongitude = jsonData.Info.Longitude.ToString(); Assert.AreEqual(Longitude, actualLongitude, $"\n Ошибка! Значение долготы (в градусах) в ответе не соответствует заданному." + $"\n Ожидаемое значение: \"{Longitude}\"" + $"\n Фактическое значение: \"{actualLongitude}\"\n"); }
public void GetUsingHelperClass() { Dictionary <string, string> httpHeader = new Dictionary <string, string>() { { "Accept", "application/json" } }; RestResponse restResponse = HttpClientHelper.PerformGetRequest(getUrl, httpHeader); List <JsonRootObject> jsonData = ResponseDataHelper.DeserializeJsonResponse <List <JsonRootObject> >(restResponse.responseContent); }
public void CheckForecastDuration() { RestResponse restResponse = GetRestReponse(); WeatherInfo jsonData = ResponseDataHelper.DeserializeJsonResponse <WeatherInfo>(restResponse.ResponseContent); var actualForecastsCount = jsonData.Forecasts.Count; Assert.AreEqual(Limit, actualForecastsCount, $"\n Ошибка! Количество прогнозов в ответе не соответствует заданному." + $"\n Ожидаемое значение: \"{Limit}\"" + $"\n Фактическое значение: \"{actualForecastsCount}\"\n"); }
public void CheckForecastTimeZoneAbbrevation() { var expectedAbbr = "MSK"; RestResponse restResponse = GetRestReponse(); WeatherInfo jsonData = ResponseDataHelper.DeserializeJsonResponse <WeatherInfo>(restResponse.ResponseContent); string actualAbbr = jsonData.Info.TimeZoneInfo.Abbreviation.ToString(); Assert.AreEqual(expectedAbbr, actualAbbr, $"\n Ошибка! Cокращенное название часового пояса в ответе не соответствует заданному." + $"\n Ожидаемое значение: \"{expectedAbbr}\"" + $"\n Фактическое значение: \"{actualAbbr}\"\n"); }
public void CheckForecastSummerTimeAttribute() { var expectedSummerTimeAttribute = false; RestResponse restResponse = GetRestReponse(); WeatherInfo jsonData = ResponseDataHelper.DeserializeJsonResponse <WeatherInfo>(restResponse.ResponseContent); bool actualSummerTimeAttribute = jsonData.Info.TimeZoneInfo.IsSummerTime; Assert.AreEqual(expectedSummerTimeAttribute, actualSummerTimeAttribute, $"\n Ошибка! Признак летнего времени в ответе не соответствует заданному." + $"\n Ожидаемое значение: \"{expectedSummerTimeAttribute}\"" + $"\n Фактическое значение: \"{actualSummerTimeAttribute}\"\n"); }
public void CheckForecastSeason() { var expectedSeason = GetSeason(DateTime.Now); RestResponse restResponse = GetRestReponse(); WeatherInfo jsonData = ResponseDataHelper.DeserializeJsonResponse <WeatherInfo>(restResponse.ResponseContent); string actualSeason = jsonData.Fact.Season.ToString(); Assert.AreEqual(expectedSeason, actualSeason, $"\n Ошибка! Время года в данном населенном пункте в ответе не соответствует актуальному." + $"\n Ожидаемое значение: \"{expectedSeason}\"" + $"\n Фактическое значение: \"{actualSeason}\"\n"); }
public void CheckForecastUrl() { string expectedUrl = "https://yandex.ru/pogoda/moscow"; RestResponse restResponse = GetRestReponse(); WeatherInfo jsonData = ResponseDataHelper.DeserializeJsonResponse <WeatherInfo>(restResponse.ResponseContent); string actualUrl = jsonData.Info.CitySiteUrl.ToString(); Assert.AreEqual(expectedUrl, actualUrl, $"\n Ошибка! Значение страницы населенного пункта на сайте в ответе не соответствует заданному." + $"\n Ожидаемое значение: \"{expectedUrl}\"" + $"\n Фактическое значение: \"{actualUrl}\"\n"); }
public void CheckForecastTimeZoneName() { var expectedName = "Europe/Moscow"; RestResponse restResponse = GetRestReponse(); WeatherInfo jsonData = ResponseDataHelper.DeserializeJsonResponse <WeatherInfo>(restResponse.ResponseContent); string actualName = jsonData.Info.TimeZoneInfo.Name.ToString(); Assert.AreEqual(expectedName, actualName, $"\n Ошибка! Наименование часового пояса в ответе не соответствует заданному." + $"\n Ожидаемое значение: \"{expectedName}\"" + $"\n Фактическое значение: \"{actualName}\"\n"); }
public void CheckForecastTimeZoneOffset() { var expectedOffset = 10800; RestResponse restResponse = GetRestReponse(); WeatherInfo jsonData = ResponseDataHelper.DeserializeJsonResponse <WeatherInfo>(restResponse.ResponseContent); int actualOffset = jsonData.Info.TimeZoneInfo.Offset; Assert.AreEqual(expectedOffset, actualOffset, $"\n Ошибка! Значение часового пояса (в секундах) в ответе не соответствует заданному." + $"\n Ожидаемое значение: \"{expectedOffset}\"" + $"\n Фактическое значение: \"{actualOffset}\"\n"); }
public void TestPutWithJsonAndHelperClass() { int id = random.Next(1000); string jsonData = "{" + "\"BrandName\": \"Alienware\"," + "\"Features\": {" + "\"Feature\": [" + "\"8th Generation Intel® Core™ i5-8300H\"," + "\"Windows 10 Home 64-bit English\"," + "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," + "\"8GB, 2x4GB, DDR4, 2666MHz\"" + "]" + "}," + "\"Id\": " + id + "," + "\"LaptopName\": \"Alienware M17\"" + "}"; Dictionary <string, string> headers = new Dictionary <string, string>() { { "Accept", "application/json" } }; restResponse = HttpClientHelper.PerformPostRequest(postUrl, jsonData, jsonMediaType, headers); Assert.Equal(200, restResponse.StatusCode); jsonData = "{" + "\"BrandName\": \"Alienware\"," + "\"Features\": {" + "\"Feature\": [" + "\"8th Generation Intel® Core™ i5-8300H\"," + "\"Windows 10 Home 64-bit English\"," + "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," + "\"1 TB of SSD\"," + "\"8GB, 2x4GB, DDR4, 2666MHz\"" + "]" + "}," + "\"Id\": " + id + "," + "\"LaptopName\": \"Alienware M17\"" + "}"; restResponse = HttpClientHelper.PerformPutRequest(putUrl, jsonData, jsonMediaType, headers); Assert.Equal(200, restResponse.StatusCode); restResponse = HttpClientHelper.PerformGetRequest(getUrl + id, headers); Assert.Equal(200, restResponse.StatusCode); JsonRootObject jsonObject = ResponseDataHelper.DeserializeJsonResponse <JsonRootObject> (restResponse.responseContent); Assert.Contains("1 TB of SSD", jsonObject.Features.Feature); }
public void CheckForecastMoonText() { RestResponse restResponse = GetRestReponse(); WeatherInfo jsonData = ResponseDataHelper.DeserializeJsonResponse <WeatherInfo>(restResponse.ResponseContent); string moonCode = jsonData.Forecasts[1].MoonPhaseCode.ToString(); string actualMoonText = jsonData.Forecasts[1].MoonPhaseName.ToString(); var expectedMoonText = $"moon-code-{moonCode}"; Assert.AreEqual(expectedMoonText, actualMoonText, $"\n Ошибка! В ответе код фазы луны на второй день не соответствует текстовому коду." + $"\n Ожидаемое значение: \"{expectedMoonText}\"" + $"\n Фактическое значение: \"{actualMoonText}\"\n");; }
public void ThenUserGetTheEmployeeDetailsWithStatusCodeAs(int statusCode, Table table) { Assert.AreEqual(restResponse.StatusCode, statusCode); getEmployeeById = ResponseDataHelper.DeserializeJsonResponse <GetEmployeeByIdRoot>(restResponse.ResponseData); var employeeList = table.CreateSet <Employee>(); var employeeData = employeeList.ToList(); Assert.AreEqual(getEmployeeById.data.id, employeeData[0].id); Assert.AreEqual(getEmployeeById.data.employee_name, employeeData[0].employee_name); Assert.IsTrue(getEmployeeById.data.employee_age.Equals(employeeData[0].employee_age)); Assert.AreEqual(getEmployeeById.data.employee_salary, employeeData[0].employee_salary); Assert.AreEqual(getEmployeeById.data.profile_image, employeeData[0].profile_image); }
public void GetUsingHelperMethod() { Dictionary <string, string> httpHeader = new Dictionary <string, string>(); httpHeader.Add("Accept", "application/json"); RestResponse restResponse = HttpClientHelper.PerformGetRequest(getUrl, httpHeader); // List<JsonRootObject> jsonRootObject = JsonConvert.DeserializeObject<List<JsonRootObject>>(restResponse.ResponseContent); // Console.WriteLine(jsonRootObject[0].ToString()); List <JsonRootObject> jsonData = ResponseDataHelper.DeserializeJsonResponse <List <JsonRootObject> >(restResponse.ResponseContent); Console.WriteLine(jsonData.ToString()); }
public void ThenEmpolyeeListShouldBeReturnedWithStatusCode(int statusCode, Table table) { Assert.AreEqual(restResponse.StatusCode, statusCode); var employee = table.CreateSet <Employee>(); var emloyeedata = employee.ToList(); getEmployeeRoot = ResponseDataHelper.DeserializeJsonResponse <GetEmployeeRoot>(restResponse.ResponseData); for (int i = 0; i < 24; i++) { Assert.AreEqual(getEmployeeRoot.data[i].id, emloyeedata[i].id); Assert.AreEqual(getEmployeeRoot.data[i].employee_name, emloyeedata[i].employee_name); Assert.IsTrue(getEmployeeRoot.data[i].employee_age.Equals(emloyeedata[i].employee_age)); Assert.AreEqual(getEmployeeRoot.data[i].employee_salary, emloyeedata[i].employee_salary); Assert.AreEqual(getEmployeeRoot.data[i].profile_image, emloyeedata[i].profile_image); } }
private void SendGetRequest() { Dictionary <string, string> httpHeader = new Dictionary <string, string>(); httpHeader.Add("Accept", "application/json"); RestResponse restResponse = httpClientAsyncHelper.PerformGetRequest(delayGetUrl, httpHeader).GetAwaiter().GetResult(); //List<JsonRootObject> jsonRootObject = JsonConvert.DeserializeObject<List<JsonRootObject>>(restResponse.ResponseContent); //Console.WriteLine(jsonRootObject[0].ToString()); Assert.AreEqual(200, restResponse.StatusCode); List <JsonRootObject> jsonData = ResponseDataHelper.DeserializeJsonResponse <List <JsonRootObject> >(restResponse.ResponseContent); Console.WriteLine(jsonData[0].ToString()); }
public void TestPutMethodUsingHelperClass_Json() { int id = random.Next(1000); string jsonData = "{" + "\"BrandName\": \"Alienware\"," + "\"Features\": {" + "\"Feature\": [" + "\"8th Generation Intel® Core™ i5-8300H\"," + "\"Windows 10 Home 64-bit English\"," + "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," + "\"8GB, 2x4GB, DDR4, 2666MHz\"" + "]" + "}," + "\"Id\": " + id + "," + "\"LaptopName\": \"Alienware M17\"" + "}"; Dictionary <string, string> httpHeaders = new Dictionary <string, string>() { { "Accept", jsonMediaType } }; restResponse = HttpClientHelper.PerformPostRequest(postUrl, httpHeaders, jsonData, jsonMediaType); Assert.AreEqual(200, restResponse.StatusCode); jsonData = "{" + "\"BrandName\": \"Alienware\"," + "\"Features\": {" + "\"Feature\": [" + "\"8th Generation Intel® Core™ i5-8300H\"," + "\"Windows 10 Home 64-bit English\"," + "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," + "\"8GB, 2x4GB, DDR4, 2666MHz\"," + "\"1TB of SSD\"" + "]" + "}," + "\"Id\": " + id + "," + "\"LaptopName\": \"Alienware M17\"" + "}"; restResponse = HttpClientHelper.PerformPutRequest(putUrl, httpHeaders, jsonData, jsonMediaType); Assert.AreEqual(200, restResponse.StatusCode); restResponse = HttpClientHelper.PerformGetRequest(getUrl + id, httpHeaders); Assert.AreEqual(200, restResponse.StatusCode); Root jsonObj = ResponseDataHelper.DeserializeJsonResponse <Root>(restResponse.ResponseData); Assert.IsTrue(jsonObj.Features.Feature.Contains("1TB of SSD"), "Item not found"); }
public void TestSecureGetEndPoint() { string authHeader = Base64StringConverter.GetBase64String("admin", "welcome"); authHeader = "Basic " + authHeader; Dictionary <string, string> httpHeader = new Dictionary <string, string> { { "Accept", "application/json" }, { "Authorization", authHeader } }; //{"Authorization", "Basic YWRtaW46d2VsY29tZQ==" } RestResponse restResponse = HttpClientHelper.PerformGetRequest(secureGetUrl, httpHeader); Assert.Equal(200, restResponse.StatusCode); List <JsonRootObject> jsonData = ResponseDataHelper.DeserializeJsonResponse <List <JsonRootObject> >(restResponse.responseContent); }
public void PutEndPointTestusingPuttAsync() { int id = 965; string jsonData = "{" + "\"BrandName\": \"Gadhaware\"," + "\"Features\": {" + "\"Feature\": [" + "\"8th Generation Intel® Core™ i5-8300H\"," + "\"Windows 10 Home 64-bit English\"," + "\"NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6\"," + "\"8GB, 2x4GB, DDR4, 2666MHz\"" + "]" + "}," + "\"Id\":" + id + "," + "\"LaptopName\": \"Alienware M17\"" + "}"; using (HttpClient httpclient = new HttpClient()) { HttpContent httpcontent = new StringContent(jsonData, Encoding.UTF8, jsonMediaType); Task <HttpResponseMessage> httpResponse = httpclient.PutAsync(putUrl, httpcontent); using (HttpResponseMessage httpResponseMessage = httpResponse.Result) { restResponse = new RestResponse((int)httpResponseMessage.StatusCode, httpResponseMessage.Content.ReadAsStringAsync().Result); Console.WriteLine(restResponse.ToString()); Assert.AreEqual(200, restResponse.StatusCode); Assert.IsNotNull(restResponse.ResponseData, "Response data is not null/empty"); httpclient.DefaultRequestHeaders.Add("Accept", jsonMediaType); Task <HttpResponseMessage> httpGetResponse = httpclient.GetAsync(getUrl + id); restResponseForGet = new RestResponse((int)httpGetResponse.Result.StatusCode, httpGetResponse.Result.Content.ReadAsStringAsync().Result); Console.WriteLine(httpGetResponse.Result.Content.ReadAsStringAsync().Result); JsonRootObject jsonRootObject = ResponseDataHelper.DeserializeJsonResponse <JsonRootObject>(restResponseForGet.ResponseData); Assert.AreEqual(200, restResponseForGet.StatusCode); Assert.AreEqual("Gadhaware", jsonRootObject.BrandName); } } }
public void ThenUserGetStatusAs(string status) { deleteEmpolyee = ResponseDataHelper.DeserializeJsonResponse <DeleteEmployeeRoot>(restResponse.ResponseData); Assert.AreEqual(deleteEmpolyee.status, status); }
public void ThenUserGetTheNameAs(string name) { createEmployeeRoot = ResponseDataHelper.DeserializeJsonResponse <CreateEmployeeRoot>(restResponse.ResponseData); Assert.AreEqual(createEmployeeRoot.data.name, name); }