/// <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 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); }