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"); }
public NetscapeWritterTests() { var emptyContainer = new BookmarkFolder(); _writter = new NetscapeBookmarksWritter(emptyContainer); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); }
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); }
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); }
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("<" + unicodeStr)); } }
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"); }
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))); } }
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"); }
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); }
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))); } }
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("<" + unicodeStr)); } }
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"); }
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("ƒ")); } }
public NetscapeWritterTests() { var emptyContainer = new BookmarkFolder(); _writter = new NetscapeBookmarksWritter(emptyContainer); }
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("ƒ")); } }