public ActionResult UserLogin([FromBody] UserLoginDto userLogin) { var response = new ResponseDataHelper <UserInfoDto>(); try { var user = _userLogic.GetUserByLoginName(userLogin.LoginName); if (user == null) { response.ResponseCode = -1; response.ResponseMessage = "登录名不存在"; } else if (user.Password != userLogin.Password) { response.ResponseCode = -1; response.ResponseMessage = "密码不正确"; } else { response.ResponseCode = 0; response.ResponseMessage = "登录成功"; response.ResponseData = UserInfoDto.CreateFromUser(user); HttpContext.Session.SetString("CurrentUser", JsonConvert.SerializeObject(user)); } } catch (Exception e) { response.ResponseCode = -1; response.ResponseMessage = e.Message; } return(Json(response)); }
public void PutEndPointTestusingClientHelper() { int id = 965; string jsonData = "{" + "\"BrandName\": \"Ramware\"," + "\"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\"" + "}"; HttpContent httpcontent = new StringContent(jsonData, Encoding.UTF8, jsonMediaType); RestResponse restResponse = HttpClientHelper.PerformPutRequest(putUrl, jsonData, jsonMediaType, null); Assert.AreEqual(200, restResponse.StatusCode); RestResponse restResponseForGet = HttpClientHelper.PerformGetRequest(getUrl + id, null); Laptop laptop = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponseForGet.ResponseData); Assert.AreEqual(200, restResponseForGet.StatusCode); Assert.AreEqual("Ramware", laptop.BrandName); }
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 TestPostEndPointWithHelperClass() { 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> httpHeader = new Dictionary <string, string>(); httpHeader.Add("Accept", jsonMediaType); restResponse = HttpClientHelper.PerformPostRequest(postUrl, httpHeader, jsonData, jsonMediaType); Assert.AreEqual(200, restResponse.StatusCode); Laptop xmlData = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseData); Console.WriteLine(xmlData.ToString()); }
public void TestSecurePostEndPoint() { int id = random.Next(1000); string xmlData = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5-8300H</Feature>" + "<Feature>Windows 10 Home 64-bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "</Features>" + "<Id>" + id + "</Id>" + "<LaptopName>Alienware M17</LaptopName>" + "</Laptop>"; Dictionary <string, string> httpHeader = new Dictionary <string, string>(); httpHeader.Add("Accept", xmlMediaType); string authHeader = "Basic " + Base64StringConverter.GetBase64String("admin", "welcome"); httpHeader.Add("Authorization", authHeader); restResponse = HttpClientHelper.PerformPostRequest(securePostUrl, httpHeader, xmlData, xmlMediaType); Assert.AreEqual(200, restResponse.StatusCode); Laptop xmlObj = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseData); Console.WriteLine(xmlObj.ToString()); }
private void SendPostRequest() { int id = random.Next(1000); string xmlData = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5 - 8300H</Feature>" + "<Feature>Windows 10 Home 64 - bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "</Features>" + "<Id> " + id + "</Id>" + "<LaptopName>Alienware M17</LaptopName>" + "</Laptop>"; Dictionary <string, string> httpHeader = new Dictionary <string, string>() { { "Accept", "application/xml" } }; RestResponse restResponse = httpAsyncClientHelper.PerformPostRequest(delayPostUrl, xmlData, xmlMediaType, httpHeader).GetAwaiter().GetResult(); //HttpContent httpContent = new StringContent(xmlData, Encoding.UTF8, xmlMediaType); //httpAsyncClientHelper.PerformPostRequest(postUrl, httpContent, httpHeader); Assert.Equal(200, restResponse.StatusCode); Laptop xmlDatat = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.responseContent); }
public ActionResult AddUser([FromBody] AddUserInfoDto userInfo) { var response = new ResponseDataHelper <UserInfoDto>(); try { //var user= var user = _userLogic.GetUserByLoginName(userInfo.LoginName); if (user == null) { user = _userLogic.AddUser(userInfo.ToUser()); response.ResponseData = UserInfoDto.CreateFromUser(user); } else { response.ResponseCode = -1; response.ResponseMessage = "登录名已存在"; } } catch (Exception e) { response.ResponseCode = -1; response.ResponseMessage = e.Message; } return(Json(response)); }
public void SecurePostUsingHTTPClientHelper() { string contentxml = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5-8300H</Feature>" + "<Feature>Windows 10 Home 64-bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "</Features>" + "<Id>" + id.ToString() + "</Id>" + "<LaptopName>Alienware M16</LaptopName>" + "</Laptop>"; string authheader = Base64StringConverter.getBase64String("admin", "welcome"); authheader = "Basic " + authheader; Dictionary <string, string> header = new Dictionary <string, string> { { "Accept", "application/xml" }, { "Authorization", authheader } }; restResponse = HttpClientHelper.PerformPostRequest(secureposturl, contentxml, xmldataformat, header); Assert.AreEqual(200, restResponse.StatusCode); restResponse = HttpClientHelper.PerformGetRequest(securegeturl + id, header); Assert.AreEqual(200, restResponse.StatusCode); Laptop xmlresponsedata = ResponseDataHelper.DeserializeXMLResponse <Laptop>(restResponse.ResponseContent); Console.WriteLine(xmlresponsedata.ToString()); Assert.AreEqual("Alienware", xmlresponsedata.BrandName); }
public void postdata(int id) { string contentxml = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5-8300H</Feature>" + "<Feature>Windows 10 Home 64-bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "</Features>" + "<Id>" + id.ToString() + "</Id>" + "<LaptopName>Alienware M16</LaptopName>" + "</Laptop>"; Dictionary <string, string> header = new Dictionary <string, string> { { "Accept", "application/xml" } }; restResponse = HttpClientHelper.PerformPostRequest(posturl, contentxml, xmldataformat, header); Assert.AreEqual(200, restResponse.StatusCode); Laptop xmlresponsedata = ResponseDataHelper.DeserializeXMLResponse <Laptop>(restResponse.ResponseContent); Console.WriteLine(xmlresponsedata.ToString()); }
public void TestPostUsingHelperClass() { int id = random.Next(1000); string xmlData = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5 - 8300H</Feature>" + "<Feature>Windows 10 Home 64 - bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "</Features>" + "<Id>" + id + "</Id>" + "<LaptopName>Alienware M17</LaptopName>" + "</Laptop>"; Dictionary <string, string> headers = new Dictionary <string, string>() { { "Accept", "application/xml" } }; restResponse = HttpClientHelper.PerformPostRequest(postUrl, xmlData, xmlMediaType, headers); //HttpContent httpContent = new StringContent(xmlData, Encoding.UTF8, xmlMediaType); Assert.AreEqual(200, restResponse.StatusCode); Laptop xmlDatat = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.ResponseContent); Console.WriteLine(xmlData.ToString()); }
public void testSecureHTTPClientHelper_xml() { string contentxml = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5-8300H</Feature>" + "<Feature>Windows 10 Home 64-bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "</Features>" + "<Id>" + id.ToString() + "</Id>" + "<LaptopName>Alienware M16</LaptopName>" + "</Laptop>"; string authheader = Base64StringConverter.getBase64String("admin", "welcome"); authheader = "Basic " + authheader; Dictionary <string, string> header = new Dictionary <string, string> { { "Accept", "application/xml" }, { "Authorization", authheader } }; restResponse = HttpClientHelper.PerformPostRequest(secureposturl, contentxml, xmldataformat, header); Assert.AreEqual(200, restResponse.StatusCode); contentxml = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5-8300H</Feature>" + "<Feature>Windows 10 Home 64-bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "<Feature>1 TB is added</Feature>" + "</Features>" + "<Id>" + id.ToString() + "</Id>" + "<LaptopName>Alienware M16</LaptopName>" + "</Laptop>"; //using (HttpClient httpClient = new HttpClient()) //{ // HttpContent httpContent = new StringContent(contentxml, Encoding.UTF8, xmldataformat); // 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.PerformPutRequest(secureputurl, contentxml, xmldataformat, header); Assert.AreEqual(200, restResponse.StatusCode); restResponse = HttpClientHelper.PerformGetRequest(securegeturl + id, header); Assert.AreEqual(200, restResponse.StatusCode); Laptop xmlresponsedata = ResponseDataHelper.DeserializeXMLResponse <Laptop>(restResponse.ResponseContent); //Console.WriteLine(xmlresponsedata.Features.Feature.ToString()); Assert.IsTrue(xmlresponsedata.Features.Feature.Contains("1 TB is added"), "Failed to add data"); }
public void testPutUsingJSON() { string contentjson = "{" + "\"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 M16\"" + "}"; Dictionary <string, string> header = new Dictionary <string, string> { { "Accept", "application/json" } }; restResponse = HttpClientHelper.PerformPostRequest(posturl, contentjson, jsondataformat, header); Assert.AreEqual(200, restResponse.StatusCode); contentjson = "{" + "\"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\"," + "\"1 TB SSD added\"" + "]" + "}," + "\"Id\": " + id + "," + "\"LaptopName\": \"Alienware M16\"" + "}"; using (HttpClient httpClient = new HttpClient()) { HttpContent httpContent = new StringContent(contentjson, Encoding.UTF8, jsondataformat); 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, header); Assert.AreEqual(200, restResponse.StatusCode); //Laptop xmlresponsedata = ResponseDataHelper.DeserializeXMLResponse<Laptop>(restResponse.ResponseContent); ////Console.WriteLine(xmlresponsedata.Features.Feature.ToString()); //Assert.IsTrue(xmlresponsedata.Features.Feature.Contains("1 TB is added"), "Failed to add data"); JsonRootObject JSONresponsedata = ResponseDataHelper.DeserializeJSONResponse <JsonRootObject>(restResponse.ResponseContent); Console.WriteLine(JSONresponsedata.Features.Feature); Assert.IsTrue(JSONresponsedata.Features.Feature.Contains("1 TB SSD added")); }
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 TestPutUsingXmlData() { int id = random.Next(1000); string xmlData = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5 - 8300H</Feature>" + "<Feature>Windows 10 Home 64 - bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "</Features>" + "<Id>" + id + "</Id>" + "<LaptopName>Alienware M17</LaptopName>" + "</Laptop>"; Dictionary <string, string> headers = new Dictionary <string, string>() { { "Accept", "application/xml" } }; restResponse = HttpClientHelper.PerformPostRequest(postUrl, xmlData, xmlMediaType, headers); Assert.Equal(200, restResponse.StatusCode); xmlData = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5 - 8300H</Feature>" + "<Feature>Windows 10 Home 64 - bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "<Feature>1 TB of SSD</Feature>" + "</Features>" + "<Id>" + id + "</Id>" + "<LaptopName>Alienware M17</LaptopName>" + "</Laptop>"; using (HttpClient httpClient = new HttpClient()) { HttpContent httpContent = new StringContent(xmlData, Encoding.UTF8, xmlMediaType); Task <HttpResponseMessage> httpResponseMessage = httpClient.PutAsync(putUrl, httpContent); restResponse = new RestResponse((int)httpResponseMessage.Result.StatusCode, httpResponseMessage.Result.Content.ReadAsStringAsync().Result); Assert.Equal(200, restResponse.StatusCode); } restResponse = HttpClientHelper.PerformGetRequest(getUrl + id, headers); Assert.Equal(200, restResponse.StatusCode); Laptop xmlObj = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.responseContent); Assert.Contains("1 TB of SSD", xmlObj.Features.Feature); }
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 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()); }
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); }
private static void SendErrorResponse(IWebSocketConnection socket, string errorInfo) { Logger.Instance().ErrorWithFormat("{0}:{1}, {2}", socket.ConnectionInfo.ClientIpAddress, socket.ConnectionInfo, errorInfo); var header = string.Format("{0}={1}", ServerDefines.CommandType, ServerDefines.Error); var headerBytes = Encoding.UTF8.GetBytes(header); var bodyBytes = string.IsNullOrEmpty(errorInfo) ? null : Encoding.UTF8.GetBytes(errorInfo); var bytes = ResponseDataHelper.GenerateResponseData(headerBytes, bodyBytes); socket.Send(bytes); }
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 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 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 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 TestSecurePutEndPoint() { int id = random.Next(1000); string xmlData = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5 - 8300H</Feature>" + "<Feature>Windows 10 Home 64 - bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "</Features>" + "<Id>" + id + "</Id>" + "<LaptopName>Alienware M17</LaptopName>" + "</Laptop>"; string authHeader = Base64StringConverter.GetBase64String("admin", "welcome"); authHeader = "Basic " + authHeader; Dictionary <string, string> headers = new Dictionary <string, string>() { { "Accept", "application/xml" }, { "Authorization", authHeader } }; restResponse = HttpClientHelper.PerformPostRequest(securePostUrl, xmlData, xmlMediaType, headers); Assert.Equal(200, restResponse.StatusCode); xmlData = "<Laptop>" + "<BrandName>Alienware</BrandName>" + "<Features>" + "<Feature>8th Generation Intel® Core™ i5 - 8300H</Feature>" + "<Feature>Windows 10 Home 64 - bit English</Feature>" + "<Feature>NVIDIA® GeForce® GTX 1660 Ti 6GB GDDR6</Feature>" + "<Feature>8GB, 2x4GB, DDR4, 2666MHz</Feature>" + "<Feature>1 TB of SSD</Feature>" + "</Features>" + "<Id>" + id + "</Id>" + "<LaptopName>Alienware M17</LaptopName>" + "</Laptop>"; restResponse = HttpClientHelper.PerformPutRequest(securePutUrl, xmlData, xmlMediaType, headers); Assert.Equal(200, restResponse.StatusCode); restResponse = HttpClientHelper.PerformGetRequest(secureGetUrl + id, headers); Assert.Equal(200, restResponse.StatusCode); Laptop xmlObj = ResponseDataHelper.DeserializeXmlResponse <Laptop>(restResponse.responseContent); Assert.Contains("1 TB of SSD", xmlObj.Features.Feature); }
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 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 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 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); }