Inheritance: ICommunicationRequest
Beispiel #1
0
 public WebServerContext(HttpRequestMessage request)
 {
     _request        = request;
     ResponseMessage = request.CreateResponse();
     Request         = new WebServerRequest(request);
     Response        = new WebServerResponse(ResponseMessage);
 }
Beispiel #2
0
 public WebServerContext(HttpRequestMessage request, NameValueCollection requestPaths)
 {
     _request        = request;
     ResponseMessage = request.CreateResponse();
     Request         = new WebServerRequest(request, requestPaths);
     Response        = new WebServerResponse(ResponseMessage);
 }
 public WebServerContext(HttpRequestMessage request)
 {
     _request = request;
     ResponseMessage = request.CreateResponse();
     Request = new WebServerRequest(request);
     Response = new WebServerResponse(ResponseMessage);
 }
 public WebServerContext(HttpRequestMessage request, NameValueCollection requestPaths)
 {
     _request = request;
     ResponseMessage = request.CreateResponse();
     Request = new WebServerRequest(request, requestPaths);
     Response = new WebServerResponse(ResponseMessage);
 } 
        public void WebServerRequest_Constructor_BoundVariablesIsNull_ThrowsArgumentNullException()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
#pragma warning disable 168
            var webServerRequest = new WebServerRequest(new HttpRequestMessage(), null);
#pragma warning restore 168

            //------------Assert Results-------------------------
        }
        public void WebServerRequest_Constructor_PropertiesInitialized()
        {
            //------------Setup for test--------------------------            
            string content;
            NameValueCollection boundVars;
            NameValueCollection queryStr;
            NameValueCollection headers;
            var request = CreateHttpRequest(out content, out boundVars, out queryStr, out headers);

            //------------Execute Test---------------------------
            var webServerRequest = new WebServerRequest(request, boundVars);

            //------------Assert Results-------------------------
            VerifyProperties(request, webServerRequest, content, queryStr, boundVars);
        }
        public static void VerifyProperties(HttpRequestMessage httpRequest, WebServerRequest webRequest, string expectedContent, NameValueCollection queryStr, NameValueCollection boundVars)
        {
            var encoding = httpRequest.Content.GetContentEncoding();

            Assert.AreEqual(httpRequest.Method.Method, webRequest.Method);
            Assert.AreEqual(httpRequest.RequestUri.OriginalString, webRequest.Uri.OriginalString);
            Assert.AreEqual(httpRequest.Content.Headers.ContentLength, webRequest.ContentLength);
            Assert.AreEqual(httpRequest.Content.Headers.ContentType.ToString(), webRequest.ContentType);
            Assert.AreEqual(encoding, webRequest.ContentEncoding);

            CollectionAssert.AreEqual(queryStr, webRequest.QueryString);
            CollectionAssert.AreEqual(boundVars, webRequest.BoundVariables);

            var buffer = new byte[webRequest.ContentLength];
            using(var stream = webRequest.InputStream)
            {
                stream.Read(buffer, 0, webRequest.ContentLength);
            }
            var content = encoding.GetString(buffer);

            Assert.AreEqual(expectedContent, content);
        }