public void BuildWallTest() { DataHandler handler = new DataHandler(); //.Instance; handler.InsertPerson("Neil"); handler.InsertPost("Neil", "This is my first post"); handler.InsertPost("Neil", "This is my first post"); handler.InsertPerson("Jai"); handler.Follow("Neil", "Jai"); handler.InsertPost("Jai", "This is my first post"); handler.InsertPost("Neil", "This is my first post"); handler.InsertPerson("Ramone"); handler.InsertPost("Ramone", "This is my first post"); handler.InsertPost("Neil", "This is my first post"); Assert.IsTrue(handler.Read("Jai").Count == 1); Assert.IsTrue(handler.Read("Ramone").Count == 1); Assert.IsTrue(handler.BuildWall("Neil").Count == 5); Assert.IsTrue(handler.BuildWall("Jai").Count == 1); }
/// <summary> /// Translates console text into Feed command /// </summary> /// <param name="trendCommand">console text</param> /// <param name="trendFeed">the current feed</param> public void HandleCommand(string trendCommand, DataHandler trendFeed) { if (trendCommand.ToLower().Trim() == "clear") { Console.Clear(); } else if (trendCommand.IndexOf(" ") == -1) { List<Post> posts = trendFeed.Read(trendCommand); if (posts != null) { foreach (Post p in posts) { Console.WriteLine(p.ToTimeLapseString()); } } } else if (trendCommand.Contains("->")) { string[] newTrend = Regex.Split(trendCommand, " -> "); try { trendFeed.InsertPerson(newTrend[0]); trendFeed.InsertPost(newTrend[0], newTrend[1]); } catch { trendFeed.InsertPost(newTrend[0], newTrend[1]); } } else if (trendCommand.Contains("wall")) { List<Post> posts = trendFeed.BuildWall(trendCommand.Substring(0, trendCommand.IndexOf(' '))); foreach (Post p in posts) { Console.WriteLine(p.ToTimeLapseString()); } } else if (trendCommand.Contains("follows")) { trendFeed.Follow(trendCommand.Substring(0, trendCommand.IndexOf(' ')), trendCommand.Substring(trendCommand.LastIndexOf(' ') + 1)); } }
public void CommandLineTest() { DataHandler datahandler = new DataHandler(); //.Instance; CommandHandler commandHandler = new CommandHandler(); commandHandler.HandleCommand("Neil -> Post 1", datahandler); commandHandler.HandleCommand("Neil -> Post 2", datahandler); commandHandler.HandleCommand("Jai -> Post 1", datahandler); commandHandler.HandleCommand("Neil -> Post 3", datahandler); commandHandler.HandleCommand("Ramone -> Post 1", datahandler); commandHandler.HandleCommand("Neil -> Post 4", datahandler); commandHandler.HandleCommand("Neil follows Jai", datahandler); commandHandler.HandleCommand("Jai -> Post 2", datahandler); commandHandler.HandleCommand("Neil -> Post 5", datahandler); commandHandler.HandleCommand("Neil -> Post 6", datahandler); Assert.IsTrue(datahandler.Read("Neil").Count == 6); Assert.IsTrue(datahandler.BuildWall("Neil").Count == 8); datahandler.Dispose(); }