コード例 #1
0
 public void ResponseBuilder_returns_500_error_on_empty_data()
 {
     var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
     var rb = new ResponseBuilder(r);
     rb.Response.Data = null;
     rb.GetResponseBytes();
     Assert.AreEqual(500, rb.Response.HttpResponseCode, "On nulled data response didn't have 500 Error");
 }
コード例 #2
0
        public void Has_Accept_range_bytes()
        {
            var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
            r.AcceptsRanges = true;

            var hc = new ResponseHeaderCreator(r);
            var headers = hc.Create();

            Assert.IsTrue(headers.Contains("Accept-Ranges: bytes"), "Accept range was not set");
        }
コード例 #3
0
        public void Has_ContentEncoding_tag()
        {
            var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
            r.ContentEncoding = "gzip";

            var hc = new ResponseHeaderCreator(r);
            var headers = hc.Create();

            Assert.IsTrue(headers.Contains("Content-Encoding: " + r.ContentEncoding));
        }
コード例 #4
0
ファイル: Mother.cs プロジェクト: taraspikh/cs-webserver
        public static Response CreateSampleResponse()
        {
            //create sample data for Response
            var data = Encoding.UTF8.GetBytes("This is just a test data!");

            //create Response
            var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);

            return r;
        }
コード例 #5
0
        public void Has_LastModified_tag()
        {
            var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
            r.LastModified = DateTime.Now;

            var hc = new ResponseHeaderCreator(r);
            var headers = hc.Create();

            Assert.IsTrue(headers.Contains("Last-Modified: " + string.Format("{0:r}", r.LastModified)));
        }
コード例 #6
0
        public void Has_ConnectionStatus_when_it_is_set()
        {
            var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
            r.ConnectionStatus = "close";

            var hc = new ResponseHeaderCreator(r);
            var headers = hc.Create();

            Assert.IsTrue(headers.Contains("Connection: close"));
        }
コード例 #7
0
        public void Creates_heading_HTTP_version()
        {
            var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
            var hc = new ResponseHeaderCreator(r);
            var headers = hc.Create();

            Assert.IsTrue(headers.Exists(h =>
                h.Contains(WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10) ||
                h.Contains(WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion11)));
        }
コード例 #8
0
 /// <summary>
 /// Constructor
 /// </summary>
 public ResponseBuilder(Response response)
 {
     _response = response;
 }
コード例 #9
0
        public void Has_Set_Cookie_tag()
        {
            var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
            r.Cookies.Add("test", "cookie");

            var hc = new ResponseHeaderCreator(r);
            var headers = hc.Create();

            Assert.IsTrue(headers.Contains(string.Format("Set-Cookie: {0}={1}", "test", "cookie")));
        }
コード例 #10
0
        public void Has_Location_tag()
        {
            var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
            r.Location = "/";

            var hc = new ResponseHeaderCreator(r);
            var headers = hc.Create();

            Assert.IsTrue(headers.Contains("Location: " + r.Location));
        }
コード例 #11
0
 public void Http_code_status_is_200_by_default()
 {
     Response target = new Response();
     const int data = 200;
     Assert.AreEqual(target.HttpResponseCode, data);
 }
コード例 #12
0
 public void HTTPVersion_is_1_0_by_default()
 {
     Response target = new Response();
     const string version = "HTTP/1.0";
     Assert.AreEqual(target.HttpVersion, version);
 }
コード例 #13
0
 public void Returns_more_than_1_item()
 {
     var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
     var hc = new ResponseHeaderCreator(r);
     var headers = hc.Create();
     Assert.IsTrue(headers.Count > 0);
 }
コード例 #14
0
 public void Is_not_null()
 {
     var r = new Response();
     var hc = new ResponseHeaderCreator(r);
     Assert.IsNotNull(hc);
 }
コード例 #15
0
        public void Has_Set_Cookie_tag_with_Expired_and_Path()
        {
            var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
            var expirationDate = DateTime.Now.AddDays(2);

            var c = new Cookie("test", "cookie");
            c.Expires = expirationDate;
            c.Path = "/";
            r.Cookies.Add(c);

            var hc = new ResponseHeaderCreator(r);
            var headers = hc.Create();

            Assert.IsTrue(headers.Contains(string.Format(CultureInfo.InvariantCulture, "Set-Cookie: {0}={1}; Path={2}; Expires={3:r}", "test", "cookie", c.Path, expirationDate)));
        }
コード例 #16
0
 public void ResponseConstructorTest()
 {
     Response target = new Response();
     Assert.IsTrue(target != null, "Response can't be created");
 }
コード例 #17
0
 public void ResponseBuilder_can_be_created()
 {
     var r = new Response("text/html", WebServer.BusinessLogic.Helpers.WebserverConstants.HttpVersion10, data);
     var rb = new ResponseBuilder(r);
     Assert.IsTrue(rb != null, "ResponseBuilder was not created properly");
 }
コード例 #18
0
 public void Data_is_null_on_creation_of_Response()
 {
     Response target = new Response();
     Assert.AreEqual(target.Data, null);
 }
コード例 #19
0
 public void Http_code_description_is_OK_by_default()
 {
     Response target = new Response();
     const string data = "OK";
     Assert.AreEqual(target.HttpResponseCodeDescription, data);
 }