public string DispatchAction(IEndpoint endpoint) { switch (endpoint.ActionName) { case "RegisterUser": string username = endpoint.Parameters["username"]; string password = endpoint.Parameters["password"]; string confirmPassword = endpoint.Parameters["confirmPassword"]; return(tracker.RegisterUser(username, password, confirmPassword)); case "LoginUser": username = endpoint.Parameters["username"]; password = endpoint.Parameters["password"]; return(tracker.LoginUser(username, password)); case "LogoutUser": return(tracker.LogoutUser()); case "CreateIssue": string title = endpoint.Parameters["title"]; string description = endpoint.Parameters["description"]; IssuePriority priority = (IssuePriority)System.Enum.Parse(typeof(IssuePriority), endpoint.Parameters["priority"]); string[] tags = endpoint.Parameters["tags"].Split('|'); return(tracker.CreateIssue(title, description, priority, tags)); case "RemoveIssue": int issueId = int.Parse(endpoint.Parameters["id"]); return(tracker.RemoveIssue(issueId)); case "AddComment": issueId = int.Parse(endpoint.Parameters["id"]); string commentText = endpoint.Parameters["text"]; return(tracker.AddComment(issueId, commentText)); case "MyIssues": return(tracker.GetMyIssues()); case "MyComments": return(tracker.GetMyComments()); case "Search": tags = endpoint.Parameters["tags"].Split('|'); return(tracker.SearchForIssues(tags)); default: throw new InvalidOperationException(string.Format("Invalid action: {0}", endpoint.ActionName)); } }
public void TestSearchForIssueWhenMathcingTagsGivenShouldReturnOrderedMatchingResult() { var username = "******"; var password = "******"; this.tracker.RegisterUser(username, password, password); this.tracker.LoginUser(username, password); this.tracker.CreateIssue("some", "issue", IssuePriority.Low, new string[] { "a", "b", "c" }); this.tracker.CreateIssue("other", "missue", IssuePriority.High, new string[] { "a", "b", "c" }); var message = tracker.SearchForIssues(new[] { "a" }); var expectedMessage = new Problem(2, "other", "missue", IssuePriority.High, new List <string>() { "a", "b", "c" }) + Environment.NewLine + new Problem(1, "some", "issue", IssuePriority.Low, new List <string>() { "a", "b", "c" }); Assert.AreEqual(expectedMessage, message); }