Ejemplo n.º 1
0
        public void pretty_print_xml_with_doctype()
        {
            var input  = "<?xml version=\"1.0\"?><root><hello>world</hello></root>";
            var output = IorContentType.GetPrettyPrintedContent(IorMediaTypeCategory.Xml, input);

            output.Should().Be("<?xml version=\"1.0\"?>\r\n<root>\r\n  <hello>world</hello>\r\n</root>");
        }
Ejemplo n.º 2
0
        public void pretty_print_xml_malformed_forgives()
        {
            var input  = "<root><hello>world</h></root>";
            var output = IorContentType.GetPrettyPrintedContent(IorMediaTypeCategory.Xml, input);

            output.Should().Be(input);
        }
Ejemplo n.º 3
0
        public void ctor_sets_category()
        {
            var ict = new IorContentType("text/xml");

            ict.MediaType.Should().Be("text/xml");
            ict.MediaTypeCategory.Should().Be(IorMediaTypeCategory.Xml);
        }
Ejemplo n.º 4
0
        public void pretty_print_other()
        {
            var input  = "hello world";
            var output = IorContentType.GetPrettyPrintedContent(IorMediaTypeCategory.Text, input);

            output.Should().Be(input);
        }
Ejemplo n.º 5
0
        public void pretty_print_html()
        {
            var input  = "<html><body>hello world</body></html>";
            var output = IorContentType.GetPrettyPrintedContent(IorMediaTypeCategory.Html, input);

            output.Should().Be("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\">\r\n<html>\r\n  <head>\r\n    <title>\r\n    </title>\r\n  </head>\r\n  <body>\r\n    hello world\r\n  </body>\r\n</html>\r\n");
        }
Ejemplo n.º 6
0
        public void pretty_print_json_malformed_forgives()
        {
            var input  = "{ x: 23 + 3 }";
            var output = IorContentType.GetPrettyPrintedContent(IorMediaTypeCategory.Json, input);

            output.Should().Be(input);
        }
Ejemplo n.º 7
0
        public void pretty_print_json()
        {
            var input  = "{ x: 23 }";
            var output = IorContentType.GetPrettyPrintedContent(IorMediaTypeCategory.Json, input);

            output.Should().Be("{\r\n  \"x\": 23\r\n}");
        }
Ejemplo n.º 8
0
 public void parse_media_type_category()
 {
     IorContentType.GetMediaTypeCategory("text/xml").Should().Be(IorMediaTypeCategory.Xml);
     IorContentType.GetMediaTypeCategory("text/html").Should().Be(IorMediaTypeCategory.Html);
     IorContentType.GetMediaTypeCategory("text/json").Should().Be(IorMediaTypeCategory.Json);
     IorContentType.GetMediaTypeCategory("text/plain").Should().Be(IorMediaTypeCategory.Text);
     IorContentType.GetMediaTypeCategory("image/jpg").Should().Be(IorMediaTypeCategory.Application);
     IorContentType.GetMediaTypeCategory("application/octet-stream").Should().Be(IorMediaTypeCategory.Application);
 }
 public void get_file_ext()
 {
     IorContentType.GetFileExtension(IorMediaTypeCategory.Xml, "text/xml").Should().Be("xml");
     IorContentType.GetFileExtension(IorMediaTypeCategory.Html, "text/html").Should().Be("html");
     IorContentType.GetFileExtension(IorMediaTypeCategory.Json, "text/json").Should().Be("json");
     IorContentType.GetFileExtension(IorMediaTypeCategory.Text, "text/plain").Should().Be("txt");
     IorContentType.GetFileExtension(IorMediaTypeCategory.Application, "image/jpg").Should().Be("jpg");
     IorContentType.GetFileExtension(IorMediaTypeCategory.Other, "text/csv").Should().Be("csv");
     IorContentType.GetFileExtension(IorMediaTypeCategory.Other, "text/css").Should().Be("css");
     IorContentType.GetFileExtension(IorMediaTypeCategory.Other, "application/javascript").Should().Be("js");
     IorContentType.GetFileExtension(IorMediaTypeCategory.Other, "application/python").Should().Be("");
 }
Ejemplo n.º 10
0
        private void initTxtRequestBody()
        {
            txtRequestBody.FindReplace.Window.Text = "Find / Replace - Request Body";
            txtRequestBody.Margins[0].Width        = 22;

            //note: style 32 is default style

            /*ns.StyleSetFore(1, ScintillaNET.Utilities.ColorToRgb(Color.Black));
             * ns.StyleSetFont(1, "Monospace");
             * ns.StyleSetSize(1, 12);
             * ns.setst*/

            var cm = txtRequestBody.ContextMenu;

            cm.MenuItems.Add("-");
            Action <ScintillaNET.Scintilla, IorMediaTypeCategory> format = (tb, hmtc) => {
                if (tb.Selection.Length > 0)
                {
                    var original = tb.Selection.Text;
                    var pretty   = IorContentType.GetPrettyPrintedContent(hmtc, tb.Selection.Text);
                    var startPos = tb.Selection.Start;
                    if (original != pretty)
                    {
                        tb.Selection.Text = pretty;
                        tb.GoTo.Position(startPos);
                    }
                }
                else
                {
                    var original = tb.Text;
                    var pretty   = IorContentType.GetPrettyPrintedContent(hmtc, tb.Text);
                    if (original != pretty)
                    {
                        tb.Text = pretty;
                        tb.GoTo.Position(0);
                    }
                }
            };

            var miFx = new MenuItem("Format XML", (s, ea) => { resetLogStats(); format(txtRequestBody, IorMediaTypeCategory.Xml); });

            miFx.Shortcut     = Shortcut.CtrlShiftX;
            miFx.ShowShortcut = true;
            cm.MenuItems.Add(miFx);

            var miFj = new MenuItem("Format JSON", (s, ea) => { resetLogStats(); format(txtRequestBody, IorMediaTypeCategory.Json); });

            miFj.Shortcut     = Shortcut.CtrlShiftJ;
            miFj.ShowShortcut = true;
            cm.MenuItems.Add(miFj);
        }
Ejemplo n.º 11
0
        public void get_file_ext()
        {
            var localhost = new Uri("http://localhost");

            IorContentType.GetFileExtension(IorMediaTypeCategory.Xml, "text/xml", localhost).Should().Be("xml");
            IorContentType.GetFileExtension(IorMediaTypeCategory.Html, "text/html", localhost).Should().Be("html");
            IorContentType.GetFileExtension(IorMediaTypeCategory.Json, "text/json", localhost).Should().Be("json");
            IorContentType.GetFileExtension(IorMediaTypeCategory.Text, "text/plain", localhost).Should().Be("txt");
            IorContentType.GetFileExtension(IorMediaTypeCategory.Application, "image/jpg", localhost).Should().Be("jpg");
            IorContentType.GetFileExtension(IorMediaTypeCategory.Other, "text/csv", localhost).Should().Be("csv");
            IorContentType.GetFileExtension(IorMediaTypeCategory.Other, "text/css", localhost).Should().Be("css");
            IorContentType.GetFileExtension(IorMediaTypeCategory.Other, "application/javascript", localhost).Should().Be("js");
            IorContentType.GetFileExtension(IorMediaTypeCategory.Other, "application/python", localhost).Should().Be("");
            IorContentType.GetFileExtension(IorMediaTypeCategory.Application, "application/zip", localhost).Should().Be("zip");

            var imgUri = new Uri("http://localhost/test.img");

            IorContentType.GetFileExtension(IorMediaTypeCategory.Application, "application/octet-stream", imgUri).Should().Be("img");
        }
Ejemplo n.º 12
0
        public void ctor_forgives_illegal_comma_sep_content_type()
        {
            var ict = new IorContentType("text/xml, application/xml");

            ict.MediaType.Should().Be("text/xml");
        }
Ejemplo n.º 13
0
        public void ctor_forgive_illegal_content_type_fallback()
        {
            var ict = new IorContentType("R#O@IJ@#R");

            ict.MediaType.Should().Be("application/octet-stream");
        }
Ejemplo n.º 14
0
        public void default_ctor()
        {
            var ict = new IorContentType();

            ict.MediaType.Should().Be("application/octet-stream");
        }