상속: IResponseWriter
        public void StringResponseWriter_Write_WebServerContext_WritesContent()
        {
            //------------Setup for test--------------------------
            string content;
            NameValueCollection boundVars;
            NameValueCollection queryStr;
            NameValueCollection headers;
            var request = WebServerRequestTests.CreateHttpRequest(out content, out boundVars, out queryStr, out headers);

            var context = new WebServerContext(request, boundVars);

            const string NewContent = "Hello world";

            var responseWriter = new StringResponseWriter(NewContent, ContentTypes.Plain);

            //------------Execute Test---------------------------
            responseWriter.Write(context);

            //------------Assert Results-------------------------
            Assert.AreEqual(ContentTypes.Plain, context.ResponseMessage.Content.Headers.ContentType);
            Assert.IsInstanceOfType(context.ResponseMessage.Content, typeof(StringContent));
            var task = context.ResponseMessage.Content.ReadAsStringAsync();
            task.Wait();

            Assert.AreEqual(NewContent, task.Result);
        }
        public void StringResponseWriter_Constructor_ContentTypeIsNullString_ThrowsFormatException()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var responseWriter = new StringResponseWriter("XXX", (string)null);

            //------------Assert Results-------------------------
        }
        public void StringResponseWriter_Constructor_ContentTypeIsNullMediaTypeHeaderValue_ThrowsArgumentNullException()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var responseWriter = new StringResponseWriter("XXX", (MediaTypeHeaderValue)null);

            //------------Assert Results-------------------------
        }
예제 #4
0
 static IResponseWriter GetApisJson(string basePath)
 {
     var apiBuilder = new ApisJsonBuilder(ServerAuthorizationService.Instance, ResourceCatalog.Instance);
     var apis = apiBuilder.BuildForPath(basePath);
     var converter = new JsonSerializer();
     StringBuilder result = new StringBuilder();
     var jsonTextWriter = new JsonTextWriter(new StringWriter(result)) { Formatting = Formatting.Indented };
     converter.Serialize(jsonTextWriter, apis);
     jsonTextWriter.Flush();
     var apisJson = result.ToString();
     var stringResponseWriter = new StringResponseWriter(apisJson, ContentTypes.Json,false);
     return stringResponseWriter;
 }
        public void StringResponseWriter_Write_LargeContentWebServerContext_WritesContentAndUpdateContentDisposition()
        {
            //------------Setup for test--------------------------
            string content;
            NameValueCollection boundVars;
            NameValueCollection queryStr;
            NameValueCollection headers;
            var request = WebServerRequestTests.CreateHttpRequest(out content, out boundVars, out queryStr, out headers);

            var context = new WebServerContext(request, boundVars);

            var contentType = ContentTypes.Xml;
            var largeContent = CreateLargeContent(contentType);

            var responseWriter = new StringResponseWriter(largeContent, contentType);

            //------------Execute Test---------------------------
            responseWriter.Write(context);

            //------------Assert Results-------------------------
            Assert.AreEqual(ContentTypes.ForceDownload, context.ResponseMessage.Content.Headers.ContentType);
            Assert.AreEqual("attachment", context.ResponseMessage.Content.Headers.ContentDisposition.DispositionType);
            Assert.AreEqual("attachment; filename=Output.xml", context.ResponseMessage.Content.Headers.ContentDisposition.ToString());

            Assert.IsInstanceOfType(context.ResponseMessage.Content, typeof(StringContent));
            var task = context.ResponseMessage.Content.ReadAsStringAsync();
            task.Wait();

            Assert.AreEqual(largeContent, task.Result);
        }