ReserveResponseData() public method

Reserve the HTTP headers and Body data from the HTTP Web Response object.
public ReserveResponseData ( HttpWebResponse httpResponse, ITestSite site ) : string
httpResponse System.Net.HttpWebResponse The HTTP Web Response object.
site ITestSite The ITestSite object is used in log.
return string
        /// <summary>
        /// The method is used to send a HTTP request using PROPFIND method to the protocol server.
        /// As a result, it will return the "HttpWebResponse" object received from the protocol server.
        /// </summary>
        /// <param name="requestUri">The resource Request_URI for the HTTP request.</param>
        /// <param name="body">The body content in the HTTP request.</param>
        /// <param name="headersCollection">The collections for Name/Value pair of headers that would be inserted in the header of the HTTP request.</param>
        /// <returns>The "WDVMODUUResponse" Object that reserved data from the protocol server for the HTTP request.</returns>
        public WDVMODUUResponse PropFind(string requestUri, string body, NameValueCollection headersCollection)
        {
            // Construct an "HttpWebRequest" object based on the input request URI.
            HttpWebRequest httpWebRequest = this.ConstructHttpWebRequest(requestUri);

            // Specify the method in the HTTP request.
            httpWebRequest.Method = "PROPFIND";

            // Set the HTTP headers in the HTTP request from inputs.
            foreach (string name in headersCollection.AllKeys)
            {
                if (name.Equals("User-Agent"))
                {
                    httpWebRequest.UserAgent = headersCollection[name];
                }
                else if (name.Equals("ContentType"))
                {
                    httpWebRequest.ContentType = headersCollection[name];
                }
                else
                {
                    httpWebRequest.Headers.Set(name, headersCollection[name]);
                }
            }

            // Encode the body using UTF-8.
            byte[] bytes = Encoding.UTF8.GetBytes((string)body);

            // Set the HTTP header of content length.
            httpWebRequest.ContentLength = bytes.Length;

            // Get a reference to the request stream.
            Stream requestStream = httpWebRequest.GetRequestStream();

            // Write the request body to the request stream.
            requestStream.Write(bytes, 0, bytes.Length);

            // Close the Stream object to release the connection for further use.
            requestStream.Close();

            // Reserve the last HTTP Request Data.
            this.ReserveRequestData(httpWebRequest, body);

            // Send the PROPFIND method request and get the response from the protocol server.
            HttpWebResponse httpWebResponse = this.GetResponse(httpWebRequest);

            this.Site.Assert.IsNotNull(httpWebResponse, "The 'HttpWebResponse' object should not be null!");

            // Reserve the last HTTP Response Data.
            WDVMODUUResponse responseWDVMODUU = new WDVMODUUResponse();

            this.lastRawResponse = responseWDVMODUU.ReserveResponseData(httpWebResponse, this.Site);
            this.AssertWDVMODUUResponse(responseWDVMODUU);

            // Return the "WDVMODUUResponse" Object.
            return(responseWDVMODUU);
        }
        /// <summary>
        /// The method is used to send a HTTP request using DELETE method to the protocol server.
        /// As a result, it will return the "HttpWebResponse" object received from the protocol server.
        /// </summary>
        /// <param name="requestUri">The resource Request_URI for the HTTP request.</param>
        /// <param name="headersCollection">The collections for Name/Value pair of headers that would be inserted in the header of the HTTP request.</param>
        /// <returns>The "WDVMODUUResponse" Object that reserved data from the protocol server for the HTTP request.</returns>
        public WDVMODUUResponse Delete(string requestUri, NameValueCollection headersCollection)
        {
            // Construct an "HttpWebRequest" object based on the input request URI.
            HttpWebRequest httpWebRequest = this.ConstructHttpWebRequest(requestUri);

            // Specify the method in the HTTP request.
            httpWebRequest.Method = "DELETE";

            // Set the HTTP headers in the HTTP request from inputs.
            foreach (string name in headersCollection.AllKeys)
            {
                if (name.Equals("User-Agent"))
                {
                    httpWebRequest.UserAgent = headersCollection[name];
                }
                else if (name.Equals("ContentType"))
                {
                    httpWebRequest.ContentType = headersCollection[name];
                }
                else
                {
                    httpWebRequest.Headers.Set(name, headersCollection[name]);
                }
            }

            // Reserve the last HTTP Request Data.
            this.ReserveRequestData(httpWebRequest, null);

            // Send the DELETE method request and get the response from the protocol server.
            HttpWebResponse httpWebResponse = this.GetResponse(httpWebRequest);

            this.Site.Assert.IsNotNull(httpWebResponse, "The 'HttpWebResponse' object should not be null!");

            // Reserve the last HTTP Response Data.
            WDVMODUUResponse responseWDVMODUU = new WDVMODUUResponse();

            this.lastRawResponse = responseWDVMODUU.ReserveResponseData(httpWebResponse, this.Site);
            this.AssertWDVMODUUResponse(responseWDVMODUU);

            // Return the "WDVMODUUResponse" Object.
            return(responseWDVMODUU);
        }
        /// <summary>
        /// Get the HTTP response via sending the HTTP request in input parameter "httpRequest".
        /// </summary>
        /// <param name="httpRequest">The HTTP request that will send to the protocol server.</param>
        /// <returns>The HTTP response that received from the protocol server.</returns>
        private HttpWebResponse GetResponse(HttpWebRequest httpRequest)
        {
            HttpWebResponse httpWebResponse = null;

            try
            {
                httpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
            }
            catch (WebException webExceptiion)
            {
                this.Site.Log.Add(LogEntryKind.Comment, "Test Comment: Get following web exception from the server: \r\n{0}", webExceptiion.Message);
                httpWebResponse = (HttpWebResponse)webExceptiion.Response;
                WDVMODUUResponse response = new WDVMODUUResponse();
                this.lastRawResponse = response.ReserveResponseData(httpWebResponse, this.Site);

                // Throw the web exception to test cases.
                throw webExceptiion;
            }

            this.ValidateAndCaptureTransport(httpWebResponse);
            return(httpWebResponse);
        }
        public void MSWDVMODUU_S01_TC01_XVirusInfectedHeader_Get()
        {
            // Prerequisites for this test case:
            //     The server has installed valid virus scanner software, and a fake virus file that can be detected 
            //     by the virus scanner software has existed in a URI under the server. 
            //     The URI should be set as the value property "Server_FakeVirusInfectedFileUri_Get" in PTF configuration file.

            // Get the URI of the fake virus file in the server from the property "Server_FakeVirusInfectedFileUri_Get".
            string requestUri = Common.GetConfigurationPropertyValue("Server_FakeVirusInfectedFileUri_Get", this.Site);

            // Construct the request headers.
            NameValueCollection headersCollection = new NameValueCollection();
            headersCollection.Add("Cache-Control", "no-cache");
            headersCollection.Add("Depth", "0");
            headersCollection.Add("Pragma", "no-cache");
            headersCollection.Add("ProtocolVersion", "HTTP/1.1");
            headersCollection.Add("Translate", "f");

            // Call HTTP GET method with the URI of the fake virus file in the server.
            WDVMODUUResponse response = null;
            HttpWebResponse httpWebResponse = null;
            try
            {
                response = this.Adapter.Get(requestUri, headersCollection);
                this.Site.Assert.Fail("Failed: The virus file should not be get successfully! \r\n The last request is:\r\n {0} The last response is: \r\n {1}", this.Adapter.LastRawRequest, this.Adapter.LastRawResponse);
            }
            catch (WebException webException)
            {
                this.Site.Assert.IsNotNull(webException.Response, "The 'Response' in the caught web exception should not be null!");
                httpWebResponse = (HttpWebResponse)webException.Response;
                if (httpWebResponse.StatusCode != HttpStatusCode.Conflict)
                {
                    // The expected web exception is "Conflict", if the caught web exception is not "Conflict", then throw the web exception to the framework.
                    throw;
                }

                response = new WDVMODUUResponse();
                response.ReserveResponseData(httpWebResponse, this.Site);
            }

            this.Site.Log.Add(
                TestTools.LogEntryKind.Comment,
                string.Format("In Method 'MSWDVMODUU_S01_TC01_XVirusInfectedHeader_Get', the request URI is {0}. In the response, the status code is '{1}'; the status description is '{2}'.", requestUri, response.StatusCode, response.StatusDescription));

            #region Verify Requirements

            // Confirm the server fails the request and respond with a message containing HTTP status code "409 CONFLICT", and then capture MS-WDVMODUU_R77.
            bool isResponseStatusCode409CONFLICT = false;
            if ((response.StatusCode == HttpStatusCode.Conflict) && (string.Compare(response.StatusDescription, "CONFLICT", true) == 0))
            {
                isResponseStatusCode409CONFLICT = true;
            }

            if (isResponseStatusCode409CONFLICT == false)
            {
                // Log some information to help users to know why the response does not include "409 CONFLICT". 
                string helpDebugInformation = @"The status code in the HTTP response is not ""409 CONFLICT"", make sure following conditions are matched, and see more help information under section 1.2.1 in the test suite specification: \r\n ";
                helpDebugInformation += @"1. A valid virus scanner software has been installed in the protocol server, and the virus scanner software must be active when a document is downloaded from the protocol server. \r\n";
                helpDebugInformation += @"2. The fake virus infected file that can be detected by the valid virus scanner software exists in the URI under the protocol server, as specified by the PTF property ""Server_FakeVirusInfectedFileUri_Get"".";
                this.Site.Log.Add(TestTools.LogEntryKind.TestFailed, helpDebugInformation);
            }

            this.Site.CaptureRequirementIfIsTrue(
                isResponseStatusCode409CONFLICT,
                77,
                @"[In X-Virus-Infected Header] If this [X-Virus-Infected] header is returned by a WebDAV server in response to an HTTP [PUT or a] GET request, the server MUST fail the request and respond with a message containing HTTP status code ""409 CONFLICT"".");

            // Confirm the server does not return the fake virus file in the response with "409 CONFLICT" error condition, and then capture MS-WDVMODUU_R78.
            bool isContentBodyEmpty = false;
            if (response.ContentLength == 0)
            {
                isContentBodyEmpty = true;
            }

            this.Site.CaptureRequirementIfIsTrue(
                isResponseStatusCode409CONFLICT && isContentBodyEmpty,
                78,
                @"[In X-Virus-Infected Header] [If X-Virus-Infected Header is returned] The server MUST NOT return the infected file to the client following a GET request ""409 CONFLICT"" error condition.");

            // Confirm the server returns the X-Virus-Infected header in the response, and then capture MS-WDVMODUU_R74.
            bool isXVirusInfectedHeaderReturned = false;
            foreach (string headerName in response.HttpHeaders.AllKeys)
            {
                if (string.Compare(headerName, "X-Virus-Infected", true) == 0)
                {
                    isXVirusInfectedHeaderReturned = true;
                    break;
                }
            }

            this.Site.CaptureRequirementIfIsTrue(
               isXVirusInfectedHeaderReturned,
               74,
               @"[In X-Virus-Infected Header] A WebDAV server returns the X-Virus-Infected header in response to an HTTP GET [or a PUT] request to indicate that the requested file is infected with a virus.");

            // Get the X-Virus-Infected header and its value.
            string[] headerAndValues = response.HttpHeaders.ToString().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            string virusInfectedHeaderAndValue = string.Empty;
            foreach (string headerAndValue in headerAndValues)
            {
                if (headerAndValue.ToLower().IndexOf("x-virus-infected") == 0)
                {
                    virusInfectedHeaderAndValue = headerAndValue;
                    break;
                }
            }

            this.Site.Assert.IsTrue(virusInfectedHeaderAndValue != string.Empty, "The X-Virus-Infected header and its value should not be empty string!");

            // Define a regular expression pattern for the syntax: "x-virus-infected" ":" Virus-Name Virus-Name = 1*TEXT
            // "x-virus-infected" is matching for the header name: "x-virus-infected"
            // ":" is matching the colon which must exist. 
            // "\s*" is matching the leading white spaces
            // ".*" is matching the name characters other than \r\n 
            string virusHeaderPattern = string.Format(@"x-virus-infected:\s*.*");

            // Check the format of X-Virus-Infected header and its value in the response.
            Site.Log.Add(TestTools.LogEntryKind.Comment, "The X-Virus-Infected header and its value is {0}", virusInfectedHeaderAndValue);
            bool isRightXVirusHeader = Regex.IsMatch(virusInfectedHeaderAndValue, virusHeaderPattern, RegexOptions.IgnoreCase);
            Site.Assert.IsTrue(isRightXVirusHeader, "The format of X-Virus-Infected header should be correct.");

            // Capture MS-WDVMODUU_R7, MS-WDVMODUU_R4, and MS-WDVMODUU_R5, if the format of X-Virus-Infected header and its value is correct.
            this.Site.CaptureRequirementIfIsTrue(
               isXVirusInfectedHeaderReturned && isRightXVirusHeader,
               4,
               @"[In MODUU Extension Headers] The extension headers in this protocol conform to the form and behavior of other custom HTTP 1.1 headers, as specified in [RFC2616] section 4.2.");

            this.Site.CaptureRequirementIfIsTrue(
               isXVirusInfectedHeaderReturned && isRightXVirusHeader,
               5,
               @"[In MODUU Extension Headers] They [The extension headers] are consistent with the WebDAV verbs and headers, as specified in [RFC2518] sections 8 and 9.");

            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned && isRightXVirusHeader,
                7,
                @"[In X-Virus-Infected Header] If returned, the X-Virus-Infected header MUST take the following form:
X-Virus-Infected Header = ""x-virus-infected"" "":"" Virus-Name
Virus-Name = 1*TEXT");

            #endregion
        }
        public void MSWDVMODUU_S01_TC02_XVirusInfectedHeader_Put()
        {
            // Prerequisites for this test case:
            //     The server has installed valid virus scanner software.
            //     And in the client test environment, under the local output path there is a fake virus file that can be detected by the valid virus scanner software. 
            //     The fake virus file name should be set as the value of property "Client_FakeVirusInfectedFileName" in PTF configuration file.

            // Get the URI of the fake virus file from the property "Server_FakeVirusInfectedFileUri_Put", 
            // the URI will be used as Request-URI in the HTTP PUT method.
            string requestUri = Common.GetConfigurationPropertyValue("Server_FakeVirusInfectedFileUri_Put", this.Site);

            // The fake virus file is under the local output path, and its name is the value of property "Client_FakeVirusInfectedFileName" in PTF configuration file.
            string fakeVirusInfectedFileName = Common.GetConfigurationPropertyValue("Client_FakeVirusInfectedFileName", this.Site);

            // Assert the fake virus infected file is existed in the local folder.
            if (File.Exists(fakeVirusInfectedFileName) == false)
            {
                this.Site.Assert.Fail("The file '{0}' was not found in local output path(such as: <Solution Directory>\\TestSuite\\Resources\\), prepare a fake virus infected file under the local output path, and make sure the name of the file is same as the value of PTF property \"Client_FakeVirusInfectedFileName\".", fakeVirusInfectedFileName);
            }

            // Read the contents of fake virus file in the client. 
            byte[] bytes = GetLocalFileContent(fakeVirusInfectedFileName);

            // Construct the request headers.
            NameValueCollection headersCollection = new NameValueCollection();
            headersCollection.Add("Cache-Control", "no-cache");
            headersCollection.Add("Pragma", "no-cache");
            headersCollection.Add("ProtocolVersion", "HTTP/1.1");

            // Call HTTP PUT method to upload the fake virus file to the server.
            WDVMODUUResponse response = null;
            HttpWebResponse httpWebResponse = null;
            try
            {
                response = this.Adapter.Put(requestUri, bytes, headersCollection);
                this.ArrayListForDeleteFile.Add(requestUri);
                this.Site.Assert.Fail("Failed: The virus file should not be put successfully! \r\n The last request is:\r\n {0} The last response is: \r\n {1}", this.Adapter.LastRawRequest, this.Adapter.LastRawResponse);
            }
            catch (WebException webException)
            {
                this.Site.Assert.IsNotNull(webException.Response, "The 'Response' in the caught web exception should not be null!");
                httpWebResponse = (HttpWebResponse)webException.Response;
                if (httpWebResponse.StatusCode != HttpStatusCode.Conflict)
                {
                    // The expected web exception is "Conflict", if the caught web exception is not "Conflict", then throw the web exception to the framework.
                    throw;
                }

                response = new WDVMODUUResponse();
                response.ReserveResponseData(httpWebResponse, this.Site);
            }

            this.Site.Log.Add(
                TestTools.LogEntryKind.Comment,
                string.Format("In Method 'MSWDVMODUU_S01_TC01_XVirusInfectedHeader_Put', the request URI is {0}. In the response, the status code is '{1}'; the status description is '{2}'.", requestUri, response.StatusCode, response.StatusDescription));

            #region Verify Requirements

            // Confirm the server fails the request and respond with a message containing HTTP status code "409 CONFLICT", and then capture MS-WDVMODUU_R76.
            bool isResponseStatusCode409CONFLICT = false;
            if ((response.StatusCode == HttpStatusCode.Conflict)
                && (string.Compare(response.StatusDescription, "CONFLICT", true) == 0))
            {
                isResponseStatusCode409CONFLICT = true;
            }

            if (isResponseStatusCode409CONFLICT == false)
            {
                // Log some information to help users to know why the response does not include "409 CONFLICT". 
                string helpDebugInformation = @"The status code in the HTTP response is not ""409 CONFLICT"", make sure following conditions are matched, and see more help information under section 1.2.1 in the test suite specification: \r\n ";
                helpDebugInformation += @"1. A valid virus scanner software has been installed in the protocol server, and virus scanner software must be active when a document is uploaded to the protocol server. \r\n";
                helpDebugInformation += @"2. The fake virus infected file " + fakeVirusInfectedFileName + " can be detected by the valid virus scanner software in the protocol server. \r\n";
                helpDebugInformation += @"3. The URI in the PTF property ""Server_FakeVirusInfectedFileUri_Put"" is an addressable path in the protocol server that the test case has permission to upload a file.";
                this.Site.Log.Add(TestTools.LogEntryKind.TestFailed, helpDebugInformation);
            }

            this.Site.CaptureRequirementIfIsTrue(
                isResponseStatusCode409CONFLICT,
                76,
                @"[In X-Virus-Infected Header] If this [X-Virus-Infected ] header is returned by a WebDAV server in response to an HTTP PUT[ or a GET] request, the server MUST fail the request and respond with a message containing HTTP status code ""409 CONFLICT"".");

            // Confirm the server returns the X-Virus-Infected header in the response, and then capture MS-WDVMODUU_R75.
            bool isXVirusInfectedHeaderReturned = false;
            foreach (string headerName in response.HttpHeaders.AllKeys)
            {
                if (string.Compare(headerName, "X-Virus-Infected", true) == 0)
                {
                    isXVirusInfectedHeaderReturned = true;
                    break;
                }
            }

            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned,
                75,
                @"[In X-Virus-Infected Header] A WebDAV server returns the X-Virus-Infected header in response to an HTTP [GET or a ]PUT request to indicate that the requested file is infected with a virus.");

            // Get the X-Virus-Infected header and its value into a string.
            string[] headerAndValues = response.HttpHeaders.ToString().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            string virusInfectedHeaderAndValue = string.Empty;
            foreach (string headerAndValue in headerAndValues)
            {
                if (headerAndValue.ToLower().IndexOf("x-virus-infected") == 0)
                {
                    virusInfectedHeaderAndValue = headerAndValue;
                    break;
                }
            }

            this.Site.Assert.IsTrue(virusInfectedHeaderAndValue != string.Empty, "The X-Virus-Infected header and its value should not be empty string!");

            // Define a regular expression pattern for the syntax: "x-virus-infected" ":" Virus-Name Virus-Name = 1*TEXT
            // "x-virus-infected" is matching for the header name: "x-virus-infected"
            // ":" is matching the colon which must exist. 
            // "\s*" is matching the leading white spaces
            // ".*" is matching the name characters other than \r\n 
            string virusHeaderPattern = string.Format(@"^x-virus-infected:\s*.*");

            // Check the format of X-Virus-Infected header and its value in the response.
            Site.Log.Add(TestTools.LogEntryKind.Comment, "The X-Virus-Infected header and its value is {0}", virusInfectedHeaderAndValue);
            bool isRightXVirusHeader = Regex.IsMatch(virusInfectedHeaderAndValue, virusHeaderPattern, RegexOptions.IgnoreCase);
            Site.Assert.IsTrue(isRightXVirusHeader, "The format of X-Virus-Infected header should be correct.");

            // Capture MS-WDVMODUU_R7, MS-WDVMODUU_R4, and MS-WDVMODUU_R5, if the format of X-Virus-Infected header and its value is correct.
            this.Site.CaptureRequirementIfIsTrue(
               isXVirusInfectedHeaderReturned && isRightXVirusHeader,
               4,
               @"[In MODUU Extension Headers] The extension headers in this protocol conform to the form and behavior of other custom HTTP 1.1 headers, as specified in [RFC2616] section 4.2.");

            this.Site.CaptureRequirementIfIsTrue(
               isXVirusInfectedHeaderReturned && isRightXVirusHeader,
               5,
               @"[In MODUU Extension Headers] They [The extension headers] are consistent with the WebDAV verbs and headers, as specified in [RFC2518] sections 8 and 9.");

            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned && isRightXVirusHeader,
                7,
                @"[In X-Virus-Infected Header] If returned, the X-Virus-Infected header MUST take the following form:
X-Virus-Infected Header = ""x-virus-infected"" "":"" Virus-Name
Virus-Name = 1*TEXT");

            #endregion
        }
        /// <summary>
        /// Get the HTTP response via sending the HTTP request in input parameter "httpRequest".
        /// </summary>
        /// <param name="httpRequest">The HTTP request that will send to the protocol server.</param>
        /// <returns>The HTTP response that received from the protocol server.</returns>
        private HttpWebResponse GetResponse(HttpWebRequest httpRequest)
        {
            HttpWebResponse httpWebResponse = null;
            try
            {
                httpWebResponse = (HttpWebResponse)httpRequest.GetResponse();
            }
            catch (WebException webExceptiion)
            {
                this.Site.Log.Add(LogEntryKind.Comment, "Test Comment: Get following web exception from the server: \r\n{0}", webExceptiion.Message);
                httpWebResponse = (HttpWebResponse)webExceptiion.Response;
                WDVMODUUResponse response = new WDVMODUUResponse();
                this.lastRawResponse = response.ReserveResponseData(httpWebResponse, this.Site);

                // Throw the web exception to test cases.
                throw webExceptiion;
            }

            this.ValidateAndCaptureTransport(httpWebResponse);
            return httpWebResponse;
        }
        /// <summary>
        /// The method is used to send a HTTP request using DELETE method to the protocol server.
        /// As a result, it will return the "HttpWebResponse" object received from the protocol server.
        /// </summary>
        /// <param name="requestUri">The resource Request_URI for the HTTP request.</param>
        /// <param name="headersCollection">The collections for Name/Value pair of headers that would be inserted in the header of the HTTP request.</param>
        /// <returns>The "WDVMODUUResponse" Object that reserved data from the protocol server for the HTTP request.</returns>
        public WDVMODUUResponse Delete(string requestUri, NameValueCollection headersCollection)
        {
            // Construct an "HttpWebRequest" object based on the input request URI.
            HttpWebRequest httpWebRequest = this.ConstructHttpWebRequest(requestUri);

            // Specify the method in the HTTP request.
            httpWebRequest.Method = "DELETE";

            // Set the HTTP headers in the HTTP request from inputs.
            foreach (string name in headersCollection.AllKeys)
            {
                if (name.Equals("User-Agent"))
                {
                    httpWebRequest.UserAgent = headersCollection[name];
                }
                else if (name.Equals("ContentType"))
                {
                    httpWebRequest.ContentType = headersCollection[name];
                }
                else
                {
                    httpWebRequest.Headers.Set(name, headersCollection[name]);
                }
            }

            // Reserve the last HTTP Request Data.
            this.ReserveRequestData(httpWebRequest, null);

            // Send the DELETE method request and get the response from the protocol server.
            HttpWebResponse httpWebResponse = this.GetResponse(httpWebRequest);
            this.Site.Assert.IsNotNull(httpWebResponse, "The 'HttpWebResponse' object should not be null!");

            // Reserve the last HTTP Response Data.
            WDVMODUUResponse responseWDVMODUU = new WDVMODUUResponse();
            this.lastRawResponse = responseWDVMODUU.ReserveResponseData(httpWebResponse, this.Site);
            this.AssertWDVMODUUResponse(responseWDVMODUU);

            // Return the "WDVMODUUResponse" Object.
            return responseWDVMODUU;
        }
        /// <summary>
        /// The method is used to send a HTTP request using PUT method to the protocol server.
        /// As a result, it will return the "HttpWebResponse" object received from the protocol server.
        /// </summary>
        /// <param name="requestUri">The resource Request_URI for the HTTP request.</param>
        /// <param name="body">The body content in the HTTP request.</param>
        /// <param name="headersCollection">The collections for Name/Value pair of headers that would be inserted in the header of the HTTP request.</param>
        /// <returns>The "WDVMODUUResponse" Object that reserved data from the protocol server for the HTTP request.</returns>
        public WDVMODUUResponse Put(string requestUri, byte[] body, NameValueCollection headersCollection)
        {
            // Construct an "HttpWebRequest" object based on the input request URI.
            HttpWebRequest httpWebRequest = this.ConstructHttpWebRequest(requestUri);

            // Specify the method in the HTTP request.
            httpWebRequest.Method = "PUT";

            // Set the HTTP headers in the HTTP request from inputs.
            foreach (string name in headersCollection.AllKeys)
            {
                if (name.Equals("User-Agent"))
                {
                    httpWebRequest.UserAgent = headersCollection[name];
                }
                else if (name.Equals("ContentType"))
                {
                    httpWebRequest.ContentType = headersCollection[name];
                }
                else
                {
                    httpWebRequest.Headers.Set(name, headersCollection[name]);
                }
            }

            // Set the content header length. 
            httpWebRequest.ContentLength = body.Length;

            // Get a reference to the request stream.
            Stream requestStream = httpWebRequest.GetRequestStream();

            // Write the request body to the request stream.
            requestStream.Write(body, 0, body.Length);

            // Close the Stream object to release the connection.
            requestStream.Close();

            // Reserve the last HTTP Request Data.
            this.ReserveRequestData(httpWebRequest, Encoding.UTF8.GetString(body));

            // Send the PUT method request and get the response from the protocol server.
            HttpWebResponse httpWebResponse = this.GetResponse(httpWebRequest);
            this.Site.Assert.IsNotNull(httpWebResponse, "The 'HttpWebResponse' object should not be null!");

            // Reserve the last HTTP Response Data.
            WDVMODUUResponse responseWDVMODUU = new WDVMODUUResponse();
            this.lastRawResponse = responseWDVMODUU.ReserveResponseData(httpWebResponse, this.Site);
            this.AssertWDVMODUUResponse(responseWDVMODUU);

            // Return the "WDVMODUUResponse" Object.
            return responseWDVMODUU;
        }
        public void MSWDVMODUU_S04_TC01_MSBinDiffHeader_Put()
        {
            // Get the request URI from the property "Server_TestTxtFileUri_Put".
            string requestUri = Common.GetConfigurationPropertyValue("Server_TestTxtFileUri_Put", this.Site);

            // Get file name from the property "Client_TestTxtFileName", and read its content into byte array.
            byte[] bytesTxtFile = GetLocalFileContent(Common.GetConfigurationPropertyValue("Client_TestTxtFileName", this.Site));

            // Construct the request headers.
            NameValueCollection headersCollection = new NameValueCollection();
            headersCollection.Add("MS-BinDiff", "1.0");
            headersCollection.Add("Cache-Control", "no-cache");
            headersCollection.Add("Pragma", "no-cache");
            headersCollection.Add("ProtocolVersion", "HTTP/1.1");


            // Call HTTP PUT method to upload the file to the server.
            WDVMODUUResponse response = null;
            HttpWebResponse httpWebResponse = null;

            try
            {
                response = this.Adapter.Put(requestUri, bytesTxtFile, headersCollection);
                this.ArrayListForDeleteFile.Add(requestUri);
                this.Site.Assert.Fail("Failed: The file should not be put successfully! \r\n The last request is:\r\n {0} The last response is: \r\n {1}", this.Adapter.LastRawRequest, this.Adapter.LastRawResponse);
            }
            catch (WebException webException)
            {
                this.Site.Assert.IsNotNull(webException.Response, "The 'Response' in the caught web exception should not be null!");
                httpWebResponse = (HttpWebResponse)webException.Response;
                if (httpWebResponse.StatusCode != HttpStatusCode.UnsupportedMediaType)
                {
                    // The expected web exception is "Unsupported Media Type", if the caught web exception is not "Unsupported Media Type", then throw the web exception to the framework.
                    throw;
                }

                response = new WDVMODUUResponse();
                response.ReserveResponseData(httpWebResponse, this.Site);
            }

            this.Site.Log.Add(
                TestTools.LogEntryKind.Comment,
                string.Format("In Method 'MSWDVMODUU_S04_TC01_MSBinDiffHeader_Put', the request URI is {0}. In the response, the status code is '{1}'; the status description is '{2}'.", requestUri, response.StatusCode, response.StatusDescription));

            #region Verify Requirements

            // Confirm the server fails the request and respond with a message containing HTTP status code "415 UNSUPPORTED MEDIA TYPE", and then capture MS-WDVMODUU_R901.
            bool isResponseStatusCode415UNSUPPORTEDMEDIATYPE = false;
            if ((response.StatusCode == HttpStatusCode.UnsupportedMediaType)
                && (string.Compare(response.StatusDescription, "UNSUPPORTED MEDIA TYPE", true) == 0))
            {
                isResponseStatusCode415UNSUPPORTEDMEDIATYPE = true;
            }

            if (isResponseStatusCode415UNSUPPORTEDMEDIATYPE == false)
            {
                // Log some information to help users to know why the response does not include "415 UNSUPPORTED MEDIA TYPE". 
                string helpDebugInformation = @"The status code in the HTTP response is not ""415 UNSUPPORTED MEDIA TYPE""\r\n ";
                this.Site.Log.Add(TestTools.LogEntryKind.TestFailed, helpDebugInformation);
            }

            this.Site.CaptureRequirementIfIsTrue(
                isResponseStatusCode415UNSUPPORTEDMEDIATYPE,
                901,
                @"[In MS-BinDiff Header] If the MS-BinDiff header is included in an HTTP PUT request, the server MUST fail the request and response with a message containing HTTP status code ""415 UNSUPPORTED MEDIA TYPE"".");

            #endregion
        }
Esempio n. 10
0
        public void MSWDVMODUU_S01_TC01_XVirusInfectedHeader_Get()
        {
            // Prerequisites for this test case:
            //     The server has installed valid virus scanner software, and a fake virus file that can be detected
            //     by the virus scanner software has existed in a URI under the server.
            //     The URI should be set as the value property "Server_FakeVirusInfectedFileUri_Get" in PTF configuration file.

            // Get the URI of the fake virus file in the server from the property "Server_FakeVirusInfectedFileUri_Get".
            string requestUri = Common.GetConfigurationPropertyValue("Server_FakeVirusInfectedFileUri_Get", this.Site);

            // Construct the request headers.
            NameValueCollection headersCollection = new NameValueCollection();

            headersCollection.Add("Cache-Control", "no-cache");
            headersCollection.Add("Depth", "0");
            headersCollection.Add("Pragma", "no-cache");
            headersCollection.Add("ProtocolVersion", "HTTP/1.1");
            headersCollection.Add("Translate", "f");

            // Call HTTP GET method with the URI of the fake virus file in the server.
            WDVMODUUResponse response        = null;
            HttpWebResponse  httpWebResponse = null;

            try
            {
                response = this.Adapter.Get(requestUri, headersCollection);
                this.Site.Assert.Fail("Failed: The virus file should not be get successfully! \r\n The last request is:\r\n {0} The last response is: \r\n {1}", this.Adapter.LastRawRequest, this.Adapter.LastRawResponse);
            }
            catch (WebException webException)
            {
                this.Site.Assert.IsNotNull(webException.Response, "The 'Response' in the caught web exception should not be null!");
                httpWebResponse = (HttpWebResponse)webException.Response;
                if (httpWebResponse.StatusCode != HttpStatusCode.Conflict)
                {
                    // The expected web exception is "Conflict", if the caught web exception is not "Conflict", then throw the web exception to the framework.
                    throw;
                }

                response = new WDVMODUUResponse();
                response.ReserveResponseData(httpWebResponse, this.Site);
            }

            this.Site.Log.Add(
                TestTools.LogEntryKind.Comment,
                string.Format("In Method 'MSWDVMODUU_S01_TC01_XVirusInfectedHeader_Get', the request URI is {0}. In the response, the status code is '{1}'; the status description is '{2}'.", requestUri, response.StatusCode, response.StatusDescription));

            #region Verify Requirements

            // Confirm the server fails the request and respond with a message containing HTTP status code "409 CONFLICT", and then capture MS-WDVMODUU_R77.
            bool isResponseStatusCode409CONFLICT = false;
            if ((response.StatusCode == HttpStatusCode.Conflict) && (string.Compare(response.StatusDescription, "CONFLICT", true) == 0))
            {
                isResponseStatusCode409CONFLICT = true;
            }

            if (isResponseStatusCode409CONFLICT == false)
            {
                // Log some information to help users to know why the response does not include "409 CONFLICT".
                string helpDebugInformation = @"The status code in the HTTP response is not ""409 CONFLICT"", make sure following conditions are matched, and see more help information under section 1.2.1 in the test suite specification: \r\n ";
                helpDebugInformation += @"1. A valid virus scanner software has been installed in the protocol server, and the virus scanner software must be active when a document is downloaded from the protocol server. \r\n";
                helpDebugInformation += @"2. The fake virus infected file that can be detected by the valid virus scanner software exists in the URI under the protocol server, as specified by the PTF property ""Server_FakeVirusInfectedFileUri_Get"".";
                this.Site.Log.Add(TestTools.LogEntryKind.TestFailed, helpDebugInformation);
            }

            this.Site.CaptureRequirementIfIsTrue(
                isResponseStatusCode409CONFLICT,
                77,
                @"[In X-Virus-Infected Header] If this [X-Virus-Infected] header is returned by a WebDAV server in response to an HTTP [PUT or a] GET request, the server MUST fail the request and respond with a message containing HTTP status code ""409 CONFLICT"".");

            // Confirm the server does not return the fake virus file in the response with "409 CONFLICT" error condition, and then capture MS-WDVMODUU_R78.
            bool isContentBodyEmpty = false;
            if (response.ContentLength == 0)
            {
                isContentBodyEmpty = true;
            }

            this.Site.CaptureRequirementIfIsTrue(
                isResponseStatusCode409CONFLICT && isContentBodyEmpty,
                78,
                @"[In X-Virus-Infected Header] [If X-Virus-Infected Header is returned] The server MUST NOT return the infected file to the client following a GET request ""409 CONFLICT"" error condition.");

            // Confirm the server returns the X-Virus-Infected header in the response, and then capture MS-WDVMODUU_R74.
            bool isXVirusInfectedHeaderReturned = false;
            foreach (string headerName in response.HttpHeaders.AllKeys)
            {
                if (string.Compare(headerName, "X-Virus-Infected", true) == 0)
                {
                    isXVirusInfectedHeaderReturned = true;
                    break;
                }
            }

            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned,
                74,
                @"[In X-Virus-Infected Header] A WebDAV server returns the X-Virus-Infected header in response to an HTTP GET [or a PUT] request to indicate that the requested file is infected with a virus.");

            // Get the X-Virus-Infected header and its value.
            string[] headerAndValues             = response.HttpHeaders.ToString().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            string   virusInfectedHeaderAndValue = string.Empty;
            foreach (string headerAndValue in headerAndValues)
            {
                if (headerAndValue.ToLower().IndexOf("x-virus-infected") == 0)
                {
                    virusInfectedHeaderAndValue = headerAndValue;
                    break;
                }
            }

            this.Site.Assert.IsTrue(virusInfectedHeaderAndValue != string.Empty, "The X-Virus-Infected header and its value should not be empty string!");

            // Define a regular expression pattern for the syntax: "x-virus-infected" ":" Virus-Name Virus-Name = 1*TEXT
            // "x-virus-infected" is matching for the header name: "x-virus-infected"
            // ":" is matching the colon which must exist.
            // "\s*" is matching the leading white spaces
            // ".*" is matching the name characters other than \r\n
            string virusHeaderPattern = string.Format(@"x-virus-infected:\s*.*");

            // Check the format of X-Virus-Infected header and its value in the response.
            Site.Log.Add(TestTools.LogEntryKind.Comment, "The X-Virus-Infected header and its value is {0}", virusInfectedHeaderAndValue);
            bool isRightXVirusHeader = Regex.IsMatch(virusInfectedHeaderAndValue, virusHeaderPattern, RegexOptions.IgnoreCase);
            Site.Assert.IsTrue(isRightXVirusHeader, "The format of X-Virus-Infected header should be correct.");

            // Capture MS-WDVMODUU_R7, MS-WDVMODUU_R4, and MS-WDVMODUU_R5, if the format of X-Virus-Infected header and its value is correct.
            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned && isRightXVirusHeader,
                4,
                @"[In MODUU Extension Headers] The extension headers in this protocol conform to the form and behavior of other custom HTTP 1.1 headers, as specified in [RFC2616] section 4.2.");

            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned && isRightXVirusHeader,
                5,
                @"[In MODUU Extension Headers] They [The extension headers] are consistent with the WebDAV verbs and headers, as specified in [RFC2518] sections 8 and 9.");

            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned && isRightXVirusHeader,
                7,
                @"[In X-Virus-Infected Header] If returned, the X-Virus-Infected header MUST take the following form:
X-Virus-Infected Header = ""x-virus-infected"" "":"" Virus-Name
Virus-Name = 1*TEXT");

            #endregion
        }
Esempio n. 11
0
        public void MSWDVMODUU_S01_TC02_XVirusInfectedHeader_Put()
        {
            // Prerequisites for this test case:
            //     The server has installed valid virus scanner software.
            //     And in the client test environment, under the local output path there is a fake virus file that can be detected by the valid virus scanner software.
            //     The fake virus file name should be set as the value of property "Client_FakeVirusInfectedFileName" in PTF configuration file.

            // Get the URI of the fake virus file from the property "Server_FakeVirusInfectedFileUri_Put",
            // the URI will be used as Request-URI in the HTTP PUT method.
            string requestUri = Common.GetConfigurationPropertyValue("Server_FakeVirusInfectedFileUri_Put", this.Site);

            // The fake virus file is under the local output path, and its name is the value of property "Client_FakeVirusInfectedFileName" in PTF configuration file.
            string fakeVirusInfectedFileName = Common.GetConfigurationPropertyValue("Client_FakeVirusInfectedFileName", this.Site);

            // Assert the fake virus infected file is existed in the local folder.
            if (File.Exists(fakeVirusInfectedFileName) == false)
            {
                this.Site.Assert.Fail("The file '{0}' was not found in local output path(such as: <Solution Directory>\\TestSuite\\Resources\\), prepare a fake virus infected file under the local output path, and make sure the name of the file is same as the value of PTF property \"Client_FakeVirusInfectedFileName\".", fakeVirusInfectedFileName);
            }

            // Read the contents of fake virus file in the client.
            byte[] bytes = GetLocalFileContent(fakeVirusInfectedFileName);

            // Construct the request headers.
            NameValueCollection headersCollection = new NameValueCollection();

            headersCollection.Add("Cache-Control", "no-cache");
            headersCollection.Add("Pragma", "no-cache");
            headersCollection.Add("ProtocolVersion", "HTTP/1.1");

            // Call HTTP PUT method to upload the fake virus file to the server.
            WDVMODUUResponse response        = null;
            HttpWebResponse  httpWebResponse = null;

            try
            {
                response = this.Adapter.Put(requestUri, bytes, headersCollection);
                this.ArrayListForDeleteFile.Add(requestUri);
                this.Site.Assert.Fail("Failed: The virus file should not be put successfully! \r\n The last request is:\r\n {0} The last response is: \r\n {1}", this.Adapter.LastRawRequest, this.Adapter.LastRawResponse);
            }
            catch (WebException webException)
            {
                this.Site.Assert.IsNotNull(webException.Response, "The 'Response' in the caught web exception should not be null!");
                httpWebResponse = (HttpWebResponse)webException.Response;
                if (httpWebResponse.StatusCode != HttpStatusCode.Conflict)
                {
                    // The expected web exception is "Conflict", if the caught web exception is not "Conflict", then throw the web exception to the framework.
                    throw;
                }

                response = new WDVMODUUResponse();
                response.ReserveResponseData(httpWebResponse, this.Site);
            }

            this.Site.Log.Add(
                TestTools.LogEntryKind.Comment,
                string.Format("In Method 'MSWDVMODUU_S01_TC01_XVirusInfectedHeader_Put', the request URI is {0}. In the response, the status code is '{1}'; the status description is '{2}'.", requestUri, response.StatusCode, response.StatusDescription));

            #region Verify Requirements

            // Confirm the server fails the request and respond with a message containing HTTP status code "409 CONFLICT", and then capture MS-WDVMODUU_R76.
            bool isResponseStatusCode409CONFLICT = false;
            if ((response.StatusCode == HttpStatusCode.Conflict) &&
                (string.Compare(response.StatusDescription, "CONFLICT", true) == 0))
            {
                isResponseStatusCode409CONFLICT = true;
            }

            if (isResponseStatusCode409CONFLICT == false)
            {
                // Log some information to help users to know why the response does not include "409 CONFLICT".
                string helpDebugInformation = @"The status code in the HTTP response is not ""409 CONFLICT"", make sure following conditions are matched, and see more help information under section 1.2.1 in the test suite specification: \r\n ";
                helpDebugInformation += @"1. A valid virus scanner software has been installed in the protocol server, and virus scanner software must be active when a document is uploaded to the protocol server. \r\n";
                helpDebugInformation += @"2. The fake virus infected file " + fakeVirusInfectedFileName + " can be detected by the valid virus scanner software in the protocol server. \r\n";
                helpDebugInformation += @"3. The URI in the PTF property ""Server_FakeVirusInfectedFileUri_Put"" is an addressable path in the protocol server that the test case has permission to upload a file.";
                this.Site.Log.Add(TestTools.LogEntryKind.TestFailed, helpDebugInformation);
            }

            this.Site.CaptureRequirementIfIsTrue(
                isResponseStatusCode409CONFLICT,
                76,
                @"[In X-Virus-Infected Header] If this [X-Virus-Infected ] header is returned by a WebDAV server in response to an HTTP PUT[ or a GET] request, the server MUST fail the request and respond with a message containing HTTP status code ""409 CONFLICT"".");

            // Confirm the server returns the X-Virus-Infected header in the response, and then capture MS-WDVMODUU_R75.
            bool isXVirusInfectedHeaderReturned = false;
            foreach (string headerName in response.HttpHeaders.AllKeys)
            {
                if (string.Compare(headerName, "X-Virus-Infected", true) == 0)
                {
                    isXVirusInfectedHeaderReturned = true;
                    break;
                }
            }

            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned,
                75,
                @"[In X-Virus-Infected Header] A WebDAV server returns the X-Virus-Infected header in response to an HTTP [GET or a ]PUT request to indicate that the requested file is infected with a virus.");

            // Get the X-Virus-Infected header and its value into a string.
            string[] headerAndValues             = response.HttpHeaders.ToString().Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
            string   virusInfectedHeaderAndValue = string.Empty;
            foreach (string headerAndValue in headerAndValues)
            {
                if (headerAndValue.ToLower().IndexOf("x-virus-infected") == 0)
                {
                    virusInfectedHeaderAndValue = headerAndValue;
                    break;
                }
            }

            this.Site.Assert.IsTrue(virusInfectedHeaderAndValue != string.Empty, "The X-Virus-Infected header and its value should not be empty string!");

            // Define a regular expression pattern for the syntax: "x-virus-infected" ":" Virus-Name Virus-Name = 1*TEXT
            // "x-virus-infected" is matching for the header name: "x-virus-infected"
            // ":" is matching the colon which must exist.
            // "\s*" is matching the leading white spaces
            // ".*" is matching the name characters other than \r\n
            string virusHeaderPattern = string.Format(@"^x-virus-infected:\s*.*");

            // Check the format of X-Virus-Infected header and its value in the response.
            Site.Log.Add(TestTools.LogEntryKind.Comment, "The X-Virus-Infected header and its value is {0}", virusInfectedHeaderAndValue);
            bool isRightXVirusHeader = Regex.IsMatch(virusInfectedHeaderAndValue, virusHeaderPattern, RegexOptions.IgnoreCase);
            Site.Assert.IsTrue(isRightXVirusHeader, "The format of X-Virus-Infected header should be correct.");

            // Capture MS-WDVMODUU_R7, MS-WDVMODUU_R4, and MS-WDVMODUU_R5, if the format of X-Virus-Infected header and its value is correct.
            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned && isRightXVirusHeader,
                4,
                @"[In MODUU Extension Headers] The extension headers in this protocol conform to the form and behavior of other custom HTTP 1.1 headers, as specified in [RFC2616] section 4.2.");

            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned && isRightXVirusHeader,
                5,
                @"[In MODUU Extension Headers] They [The extension headers] are consistent with the WebDAV verbs and headers, as specified in [RFC2518] sections 8 and 9.");

            this.Site.CaptureRequirementIfIsTrue(
                isXVirusInfectedHeaderReturned && isRightXVirusHeader,
                7,
                @"[In X-Virus-Infected Header] If returned, the X-Virus-Infected header MUST take the following form:
X-Virus-Infected Header = ""x-virus-infected"" "":"" Virus-Name
Virus-Name = 1*TEXT");

            #endregion
        }
        public void MSWDVMODUU_S04_TC01_MSBinDiffHeader_Put()
        {
            // Get the request URI from the property "Server_TestTxtFileUri_Put".
            string requestUri = Common.GetConfigurationPropertyValue("Server_TestTxtFileUri_Put", this.Site);

            // Get file name from the property "Client_TestTxtFileName", and read its content into byte array.
            byte[] bytesTxtFile = GetLocalFileContent(Common.GetConfigurationPropertyValue("Client_TestTxtFileName", this.Site));

            // Construct the request headers.
            NameValueCollection headersCollection = new NameValueCollection();

            headersCollection.Add("MS-BinDiff", "1.0");
            headersCollection.Add("Cache-Control", "no-cache");
            headersCollection.Add("Pragma", "no-cache");
            headersCollection.Add("ProtocolVersion", "HTTP/1.1");


            // Call HTTP PUT method to upload the file to the server.
            WDVMODUUResponse response        = null;
            HttpWebResponse  httpWebResponse = null;

            try
            {
                response = this.Adapter.Put(requestUri, bytesTxtFile, headersCollection);
                this.ArrayListForDeleteFile.Add(requestUri);
                this.Site.Assert.Fail("Failed: The file should not be put successfully! \r\n The last request is:\r\n {0} The last response is: \r\n {1}", this.Adapter.LastRawRequest, this.Adapter.LastRawResponse);
            }
            catch (WebException webException)
            {
                this.Site.Assert.IsNotNull(webException.Response, "The 'Response' in the caught web exception should not be null!");
                httpWebResponse = (HttpWebResponse)webException.Response;
                if (httpWebResponse.StatusCode != HttpStatusCode.UnsupportedMediaType)
                {
                    // The expected web exception is "Unsupported Media Type", if the caught web exception is not "Unsupported Media Type", then throw the web exception to the framework.
                    throw;
                }

                response = new WDVMODUUResponse();
                response.ReserveResponseData(httpWebResponse, this.Site);
            }

            this.Site.Log.Add(
                TestTools.LogEntryKind.Comment,
                string.Format("In Method 'MSWDVMODUU_S04_TC01_MSBinDiffHeader_Put', the request URI is {0}. In the response, the status code is '{1}'; the status description is '{2}'.", requestUri, response.StatusCode, response.StatusDescription));

            #region Verify Requirements

            // Confirm the server fails the request and respond with a message containing HTTP status code "415 UNSUPPORTED MEDIA TYPE", and then capture MS-WDVMODUU_R901.
            bool isResponseStatusCode415UNSUPPORTEDMEDIATYPE = false;
            if ((response.StatusCode == HttpStatusCode.UnsupportedMediaType) &&
                (string.Compare(response.StatusDescription, "UNSUPPORTED MEDIA TYPE", true) == 0))
            {
                isResponseStatusCode415UNSUPPORTEDMEDIATYPE = true;
            }

            if (isResponseStatusCode415UNSUPPORTEDMEDIATYPE == false)
            {
                // Log some information to help users to know why the response does not include "415 UNSUPPORTED MEDIA TYPE".
                string helpDebugInformation = @"The status code in the HTTP response is not ""415 UNSUPPORTED MEDIA TYPE""\r\n ";
                this.Site.Log.Add(TestTools.LogEntryKind.TestFailed, helpDebugInformation);
            }

            this.Site.CaptureRequirementIfIsTrue(
                isResponseStatusCode415UNSUPPORTEDMEDIATYPE,
                901,
                @"[In MS-BinDiff Header] If the MS-BinDiff header is included in an HTTP PUT request, the server MUST fail the request and response with a message containing HTTP status code ""415 UNSUPPORTED MEDIA TYPE"".");

            #endregion
        }