コード例 #1
0
        public void CustomAttributes()
        {
            var container = new BookmarkFolder
            {
                new BookmarkLink("a", "b")
                {
                    Attributes = new Dictionary <string, string> {
                        { "custom", "1" }
                    }
                },
                new BookmarkFolder("folder")
                {
                    Attributes = new Dictionary <string, string> {
                        { "custom", "2" }, { "add_date", "ę" }
                    }
                }
            };
            var writter = new NetscapeBookmarksWritter(container);
            var reader  = new NetscapeBookmarksReader();
            var write1  = writter.ToString();
            var readed  = reader.Read(write1);

            Assert.AreEqual("1", readed.AllLinks.First().Attributes["custom"]);
            Assert.AreEqual("2", readed.GetAllItems <BookmarkFolder>().First().Attributes["custom"]);
            Assert.IsFalse(readed.GetAllItems <BookmarkFolder>().First().Attributes.ContainsKey("add_date"), "add_date is ignored attribute, it must not be written");
        }
コード例 #2
0
        public NetscapeWritterTests()
        {
            var emptyContainer = new BookmarkFolder();

            _writter = new NetscapeBookmarksWritter(emptyContainer);

            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
        }
コード例 #3
0
 public void EmptyContainer()
 {
     var emptyContainer = new BookmarkFolder();
     var writter = new NetscapeBookmarksWritter(emptyContainer);
     var reader = new NetscapeBookmarksReader();
     var write1 = writter.ToString();
     var readed = reader.Read(write1);
     writter = new NetscapeBookmarksWritter(readed);
     var write2 = writter.ToString();
     Assert.AreEqual(write1, write2, true);
 }
コード例 #4
0
 public void StreamUnicode()
 {
     var container = Helpers.GetSimpleStructure();
     container.Add(new BookmarkLink("test", "ƒ"));
     var ms = new MemoryStream();
     var writter = new NetscapeBookmarksWritter(container) { OutputEncoding = Encoding.Unicode };
     writter.Write(ms);
     ms = new MemoryStream(ms.GetBuffer());
     var reader = new NetscapeBookmarksReader { AutoDetectEncoding = true };
     var readed = reader.Read(ms);
     Assert.AreEqual(container.AllItems.Last().Title, readed.AllItems.Last().Title);
 }
コード例 #5
0
        public void EmptyContainer()
        {
            var emptyContainer = new BookmarkFolder();
            var writter        = new NetscapeBookmarksWritter(emptyContainer);
            var reader         = new NetscapeBookmarksReader();
            var write1         = writter.ToString();
            var readed         = reader.Read(write1);

            writter = new NetscapeBookmarksWritter(readed);
            var write2 = writter.ToString();

            Assert.AreEqual(write1, write2, true);
        }
コード例 #6
0
 public void OutputEncoding1()
 {
     var encoding = Encoding.BigEndianUnicode;
     var bookmarks = Helpers.GetSimpleStructure();
     var unicodeStr = Helpers.RandomUnicodeString(10240);
     bookmarks.Add(new BookmarkLink("http://example.com", "Unicode title test: <" + unicodeStr));
     var writter = new NetscapeBookmarksWritter(bookmarks) {OutputEncoding = encoding};
     using (var stream = new MemoryStream())
     {
         writter.Write(stream);
         var content = encoding.GetString(stream.ToArray());
         Assert.IsTrue(content.Contains("&lt;" + unicodeStr));
     }
 }
コード例 #7
0
 public void SimpleStructure()
 {
     var container = Helpers.GetSimpleStructure();
     container.Add(new BookmarkLink("test", "test123") {Description = "<br>"});
     var writter = new NetscapeBookmarksWritter(container);
     var reader = new NetscapeBookmarksReader();
     var write1 = writter.ToString();
     var readed = reader.Read(write1);
     writter = new NetscapeBookmarksWritter(readed);
     var write2 = writter.ToString();
     readed = reader.Read(write2);
     Assert.AreEqual(write1, write2, true);
     Assert.IsNotNull(readed.AllLinks.FirstOrDefault(l => l.Title == "test123" && l.Description == "<br>"), "Description must be preserved between reads and writes");
 }
コード例 #8
0
 public void EmbededIconTest()
 {
     var bookmarks = Helpers.GetSimpleStructure();
     var randomBytes = Encoding.UTF8.GetBytes(Helpers.RandomUnicodeString(4096));
     bookmarks.Add(new BookmarkLink("http://example.com", "<\">") {IconContentType = "image/png", IconData = randomBytes});
     var writter = new NetscapeBookmarksWritter(bookmarks);
     using (var stream = new MemoryStream())
     {
         writter.Write(stream);
         var content = writter.OutputEncoding.GetString(stream.ToArray());
         Assert.IsTrue(content.Contains("data:image/png;base64,"));
         Assert.IsTrue(content.Contains(Convert.ToBase64String(randomBytes)));
     }
 }
コード例 #9
0
 public void CustomAttributes()
 {
     var container = new BookmarkFolder
     {
         new BookmarkLink("a", "b") {Attributes = new Dictionary<string, string> {{"custom", "1"}}},
         new BookmarkFolder("folder") {Attributes = new Dictionary<string, string> {{"custom", "2"}, {"add_date", "ę"}}}
     };
     var writter = new NetscapeBookmarksWritter(container);
     var reader = new NetscapeBookmarksReader();
     var write1 = writter.ToString();
     var readed = reader.Read(write1);
     Assert.AreEqual("1", readed.AllLinks.First().Attributes["custom"]);
     Assert.AreEqual("2", readed.GetAllItems<BookmarkFolder>().First().Attributes["custom"]);
     Assert.IsFalse(readed.GetAllItems<BookmarkFolder>().First().Attributes.ContainsKey("add_date"), "add_date is ignored attribute, it must not be written");
 }
コード例 #10
0
        public void SimpleStructureBasic()
        {
            var bookmarks       = Helpers.GetSimpleStructure();
            var writter         = new NetscapeBookmarksWritter(bookmarks);
            var result          = writter.ToString();
            var folderTagCnt    = _folderTagsRegex.Matches(result).Count;
            var itemTagsCnt     = _linkRegex.Matches(result).Count;
            var h3Cnt           = _h3Regex.Matches(result).Count;
            var folderHeaderCnt = _folderHeaderRegex.Matches(result).Count;

            Assert.AreEqual(10, folderTagCnt);
            Assert.AreEqual(4, itemTagsCnt);
            Assert.AreEqual(4, h3Cnt);
            Assert.AreEqual(4, folderHeaderCnt);
        }
コード例 #11
0
        public void EmbededIconTest()
        {
            var bookmarks   = Helpers.GetSimpleStructure();
            var randomBytes = Encoding.UTF8.GetBytes(Helpers.RandomUnicodeString(4096));

            bookmarks.Add(new BookmarkLink("http://example.com", "<\">")
            {
                IconContentType = "image/png", IconData = randomBytes
            });
            var writter = new NetscapeBookmarksWritter(bookmarks);

            using (var stream = new MemoryStream())
            {
                writter.Write(stream);
                var content = writter.OutputEncoding.GetString(stream.ToArray());
                Assert.IsTrue(content.Contains("data:image/png;base64,"));
                Assert.IsTrue(content.Contains(Convert.ToBase64String(randomBytes)));
            }
        }
コード例 #12
0
        public void OutputEncoding1()
        {
            var encoding   = Encoding.BigEndianUnicode;
            var bookmarks  = Helpers.GetSimpleStructure();
            var unicodeStr = Helpers.RandomUnicodeString(10240);

            bookmarks.Add(new BookmarkLink("http://example.com", "Unicode title test: <" + unicodeStr));
            var writter = new NetscapeBookmarksWritter(bookmarks)
            {
                OutputEncoding = encoding
            };

            using (var stream = new MemoryStream())
            {
                writter.Write(stream);
                var content = encoding.GetString(stream.ToArray());
                Assert.IsTrue(content.Contains("&lt;" + unicodeStr));
            }
        }
コード例 #13
0
        public void StreamUnicode()
        {
            var container = Helpers.GetSimpleStructure();

            container.Add(new BookmarkLink("test", "ƒ"));
            var ms      = new MemoryStream();
            var writter = new NetscapeBookmarksWritter(container)
            {
                OutputEncoding = Encoding.Unicode
            };

            writter.Write(ms);
            ms = new MemoryStream(ms.GetBuffer());
            var reader = new NetscapeBookmarksReader {
                AutoDetectEncoding = true
            };
            var readed = reader.Read(ms);

            Assert.AreEqual(container.AllItems.Last().Title, readed.AllItems.Last().Title);
        }
コード例 #14
0
        public void SimpleStructure()
        {
            var container = Helpers.GetSimpleStructure();

            container.Add(new BookmarkLink("test", "test123")
            {
                Description = "<br>"
            });
            var writter = new NetscapeBookmarksWritter(container);
            var reader  = new NetscapeBookmarksReader();
            var write1  = writter.ToString();
            var readed  = reader.Read(write1);

            writter = new NetscapeBookmarksWritter(readed);
            var write2 = writter.ToString();

            readed = reader.Read(write2);
            Assert.AreEqual(write1, write2, true);
            Assert.IsNotNull(readed.AllLinks.FirstOrDefault(l => l.Title == "test123" && l.Description == "<br>"), "Description must be preserved between reads and writes");
        }
コード例 #15
0
        public void OutputEncoding2()
        {
            var encoding  = Encoding.GetEncoding(1257);
            var bookmarks = Helpers.GetSimpleStructure();

            bookmarks.Add(new BookmarkLink("http://example.com", "ASCII title test: ƒ ąčęėįšųūĄŪ"));
            var writter = new NetscapeBookmarksWritter(bookmarks)
            {
                OutputEncoding = encoding
            };

            using (var stream = new MemoryStream())
            {
                writter.Write(stream);
                var content = encoding.GetString(stream.ToArray());
                Assert.IsTrue(content.Contains("? ąčęėįšųūĄŪ"));
                content = Encoding.UTF8.GetString(stream.ToArray());
                Assert.IsFalse(content.Contains("ƒ"));
            }
        }
コード例 #16
0
        public NetscapeWritterTests()
        {
            var emptyContainer = new BookmarkFolder();

            _writter = new NetscapeBookmarksWritter(emptyContainer);
        }
コード例 #17
0
 public void OutputEncoding2()
 {
     var encoding = Encoding.GetEncoding(1257);
     var bookmarks = Helpers.GetSimpleStructure();
     bookmarks.Add(new BookmarkLink("http://example.com", "ASCII title test: ƒ ąčęėįšųūĄŪ"));
     var writter = new NetscapeBookmarksWritter(bookmarks) {OutputEncoding = encoding};
     using (var stream = new MemoryStream())
     {
         writter.Write(stream);
         var content = encoding.GetString(stream.ToArray());
         Assert.IsTrue(content.Contains("? ąčęėįšųūĄŪ"));
         content = Encoding.UTF8.GetString(stream.ToArray());
         Assert.IsFalse(content.Contains("ƒ"));
     }
 }
コード例 #18
0
 public NetscapeWritterTests()
 {
     var emptyContainer = new BookmarkFolder();
     _writter = new NetscapeBookmarksWritter(emptyContainer);
 }
コード例 #19
0
 public void SimpleStructureBasic()
 {
     var bookmarks = Helpers.GetSimpleStructure();
     var writter = new NetscapeBookmarksWritter(bookmarks);
     var result = writter.ToString();
     var folderTagCnt = _folderTagsRegex.Matches(result).Count;
     var itemTagsCnt = _linkRegex.Matches(result).Count;
     var h3Cnt = _h3Regex.Matches(result).Count;
     var folderHeaderCnt = _folderHeaderRegex.Matches(result).Count;
     Assert.AreEqual(10, folderTagCnt);
     Assert.AreEqual(4, itemTagsCnt);
     Assert.AreEqual(4, h3Cnt);
     Assert.AreEqual(4, folderHeaderCnt);
 }