示例#1
0
        public void ReturnCorrectWebPurifyCheckResponseForManageListRequest(
            WebPurifyListMethod method, WebPurifyListType type, string word, bool success)
        {
            // arrange
            var expectedResponse = new WebPurifyManageListResponse {
                Success = success
            };

            // act
            var resultResponse = _request.ManageList(WebPurifyListMethod.Add, WebPurifyListType.White, word);

            // assert
            Assert.AreEqual(expectedResponse.Success, resultResponse.Success);
        }
示例#2
0
        /// <summary>
        /// The create web purify manage list response.
        /// </summary>
        /// <param name="xml">
        /// The xml returned from the REST request to Web Purify.
        /// </param>
        /// <returns>
        /// WebPurifyManageListResponse object
        /// </returns>
        public static WebPurifyManageListResponse CreateWebPurifyManageListResponse(XContainer xml)
        {
            if (xml.Elements("rsp").FirstOrDefault().Attribute(XName.Get("stat")).Value == "fail")
            {
                return(CreateWebPurifyResponseForError <WebPurifyManageListResponse>(
                           xml.Elements("rsp").FirstOrDefault(), new WebPurifyManageListResponse()));
            }

            string success  = xml.Elements("rsp").Select(x => x.Element("success").Value).FirstOrDefault();
            var    response = new WebPurifyManageListResponse {
                Success = success == "1"
            };

            return(response);
        }
示例#3
0
        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);
        }
示例#4
0
        public void ReturnCorrectWebPurifyCheckResponseForManageListRequest(string method, bool success)
        {
            // arrange
            var expectedResponse = new WebPurifyManageListResponse {
                Success = success
            };
            var xml =
                @"<?xml version=""1.0"" encoding=""utf-8"" ?>
                <rsp stat=""ok"">
                  <method>w{0}</method>
                  <format>rest</format>
                  <success>{1}</success>
                  <api_key>api_key</api_key>
                </rsp>";

            xml = string.Format(xml, method, WebPurifyUrlParameters.ToUrl(success));

            // act
            var resultResponse = WebPurifyCreateResponse.CreateWebPurifyManageListResponse(XDocument.Parse(xml));

            // assert
            Assert.AreEqual(expectedResponse.Success, resultResponse.Success);
        }
        public void ReturnCorrectWebPurifyCheckResponseForManageListRequest(
            WebPurifyListMethod method, WebPurifyListType type, string word, bool success)
        {
            // arrange
            var expectedResponse = new WebPurifyManageListResponse { Success = success };

            // act
            var resultResponse = _request.ManageList(WebPurifyListMethod.Add, WebPurifyListType.White, word);

            // assert
            Assert.AreEqual(expectedResponse.Success, resultResponse.Success);
        }
        public void ReturnCorrectWebPurifyCheckResponseForManageListRequest(string method, bool success)
        {
            // arrange
            var expectedResponse = new WebPurifyManageListResponse { Success = success };
            var xml =
                @"<?xml version=""1.0"" encoding=""utf-8"" ?>
                <rsp stat=""ok"">
                  <method>w{0}</method>
                  <format>rest</format>
                  <success>{1}</success>
                  <api_key>api_key</api_key>
                </rsp>";
            xml = string.Format(xml, method, WebPurifyUrlParameters.ToUrl(success));

            // act
            var resultResponse = WebPurifyCreateResponse.CreateWebPurifyManageListResponse(XDocument.Parse(xml));

            // assert
            Assert.AreEqual(expectedResponse.Success, resultResponse.Success);
        }
        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);
        }