public void ReturnCorrectWebPurifyCheckResponseForGetListRequest(string method, string[] words) { // arrange if (words == null) { words = new string[0]; } var expectedResponse = new WebPurifyGetListResponse { Words = words }; var xml = @"<?xml version=""1.0"" encoding=""utf-8"" ?> <rsp stat=""ok""> <method>webpurify.live.getblacklist</method> <format>rest</format> {0} <api_key>api_key</api_key> </rsp>"; var wordString = string.Empty; foreach (var word in words) { wordString += "<word>" + word + "</word>\r\n"; } xml = string.Format(xml, wordString); // act var resultResponse = WebPurifyCreateResponse.CreateWebPurifyGetListResponse(XDocument.Parse(xml)); // assert Assert.AreEqual(expectedResponse.Words, resultResponse.Words); }
public void ReturnCorrectWebPurifyCheckResponseForErrorRequest(string code, string msg) { // arrange var expectedResponse1 = new WebPurifyCheckResponse { ErrorCode = code, ErrorMessage = msg }; var expectedResponse2 = new WebPurifyReplaceResponse { ErrorCode = code, ErrorMessage = msg }; var expectedResponse3 = new WebPurifyManageListResponse { ErrorCode = code, ErrorMessage = msg }; var expectedResponse4 = new WebPurifyGetListResponse { ErrorCode = code, ErrorMessage = msg }; var xml = @"<?xml version=""1.0"" encoding=""utf-8""?> <rsp stat=""fail""> <err code=""{0}"" msg=""{1}"" /> <text>string</text> </rsp>"; xml = string.Format(xml, code, msg); // act var resultResponse1 = WebPurifyCreateResponse.CreateWebPurifyCheckResponse(XDocument.Parse(xml)); var resultResponse2 = WebPurifyCreateResponse.CreateWebPurifyReplaceResponse(XDocument.Parse(xml)); var resultResponse3 = WebPurifyCreateResponse.CreateWebPurifyManageListResponse(XDocument.Parse(xml)); var resultResponse4 = WebPurifyCreateResponse.CreateWebPurifyGetListResponse(XDocument.Parse(xml)); // assert Assert.AreEqual(expectedResponse1.ErrorCode, resultResponse1.ErrorCode); Assert.AreEqual(expectedResponse2.ErrorCode, resultResponse2.ErrorCode); Assert.AreEqual(expectedResponse3.ErrorCode, resultResponse3.ErrorCode); Assert.AreEqual(expectedResponse4.ErrorCode, resultResponse4.ErrorCode); Assert.AreEqual(expectedResponse1.ErrorMessage, resultResponse1.ErrorMessage); Assert.AreEqual(expectedResponse2.ErrorMessage, resultResponse2.ErrorMessage); Assert.AreEqual(expectedResponse3.ErrorMessage, resultResponse3.ErrorMessage); Assert.AreEqual(expectedResponse4.ErrorMessage, resultResponse4.ErrorMessage); }