public void TestSerializeAndStoreBrowser() { // Arrange MiniBowser.MiniBowser mb = new MiniBowser.MiniBowser(); // History mb.History.AddNewSite("https://www.hw.ac.uk/"); mb.History.AddNewSite("https://www.vision.hw.ac.uk/"); mb.History.AddNewSite("https://www.outlook.com/"); // Bookmarks Bookmark bm1 = new Bookmark("Google", "http://www.google.com/"); Bookmark bm2 = new Bookmark("HWU", "http://www.hw.ac.uk/"); Bookmark bm3 = new Bookmark("Vision", "http://www.vision.hw.ac.uk/"); Bookmark bm4 = new Bookmark("Mail", "http://www.outlook.com/"); mb.AddBookmark(bm1); mb.AddBookmark(bm2); mb.AddBookmark(bm3); mb.AddBookmark(bm4); // homepage mb.Homepage = "https://www.google.com/"; // Act serializer.SerializeAndStoreBrowser(mb); string actualHistory = File.ReadAllText(Serializer.pathHistory); string actualBookmarks = File.ReadAllText(Serializer.pathBookmarks); // Assert Assert.AreEqual(expectedBookmarks, actualBookmarks); Assert.AreEqual(expectedHistory, actualHistory); Assert.AreEqual("\"https://www.google.com/\"", System.IO.File.ReadAllText(Serializer.pathHomepage)); }
/// <summary> /// Initializes the browser by loading the objects from the file as /// well as adding some elemtns to the different lists so no problem occurs /// when displaying the UI. /// </summary> public void InitializeBrowser() { mb = new MiniBowser.MiniBowser(); // if the urlList is empty, fills it with empty strings (for display purposes) if (mb.History.UrlList.Count <= 8) { List <string> emptyUrlList = new List <string> { "", "", "", "", "", "", "", "" }; mb.History.UrlList.AddRange(emptyUrlList); } // if the bookmark list is empty, fills it with empty bookmarks (for display purposes) if (mb.BookmarkList.Count <= 8) { List <MiniBowser.Bookmark> emptyBookmarkList = new List <MiniBowser.Bookmark> { new MiniBowser.Bookmark("", ""), new MiniBowser.Bookmark("", ""), new MiniBowser.Bookmark("", ""), new MiniBowser.Bookmark("", ""), new MiniBowser.Bookmark("", ""), new MiniBowser.Bookmark("", ""), new MiniBowser.Bookmark("", ""), new MiniBowser.Bookmark("", "") }; mb.BookmarkList.AddRange(emptyBookmarkList); } // store the initial state mb.Store(); // loads the homepage urlEntry.Text = mb.Homepage; mb.CurrentSite = mb.Homepage; // http load homepage // display html content(tostring) htmlTextView.Buffer.Text = mb.RequestResult(mb.Homepage); CheckButtonsStatus(); }
public void TestAddBookmark() { // Arrange Bookmark bm = new Bookmark("Google", "http://www.google.com"); MiniBowser.MiniBowser mb = new MiniBowser.MiniBowser(); // Act mb.AddBookmark(bm); // Assert Assert.IsTrue(mb.BookmarkList.Contains(bm)); }
/// <summary> /// Serializes the full browser by calling the serialization methods /// of history, bookmarks list and homepage. /// </summary> /// <param name="miniBowser">Browser to be serialized</param> public void SerializeAndStoreBrowser(MiniBowser miniBowser) { SerializeAndStoreHistory(miniBowser.History); SerializeAndStoreBookmarks(miniBowser.BookmarkList); SerializeAndStoreHomePage(miniBowser.Homepage); }