public void BuildMessage_IssueCreatedThenUpdated_ExpectOneCreationMessage() { //Arrange var jiraMessageBuilder = new JiraMessageBuilder("http://jira"); var user = new User {displayName = "Laurent Kempé", name = "laurent"}; var sameIssue = new Issue {key = "LK-10", fields = new Fields {summary = "Issue Description", reporter = user, assignee = user}}; var jiraModel1 = new JiraModel { webhookEvent = "jira:issue_created", issue = sameIssue }; var jiraModel2 = new JiraModel { webhookEvent = "jira:issue_updated", issue = sameIssue }; var sameJiraIssueKeyEvents = new List<JiraModel> { jiraModel1, jiraModel2 }; //Act var buildMessage = jiraMessageBuilder.BuildMessage(sameJiraIssueKeyEvents); //Assert Assert.That(buildMessage, Is.EqualTo("<b><a href='http://jira/browse/LK-10'>LK-10 Issue Description</a></b> has been created by <a href='http://jira/secure/ViewProfile.jspa?name=laurent'>Laurent Kempé</a> and current assignee is <a href='http://jira/secure/ViewProfile.jspa?name=laurent'>Laurent Kempé</a>.")); }
// GET: Jira public ActionResult Authentication() { var model = new JiraModel { UserSkp = this.HttpContext.User.Identity.Name.Substring(9) }; return(View(model)); }
private void BuildIssueCreatedMessage(JiraModel model, StringBuilder stringBuilder) { stringBuilder .AppendFormat( "<b>{0}</b> has been created by {1} and current assignee is {2}.", GetFullIssueLink(model.issue), GetUserProfileLinkHtml(model.issue.fields.reporter), GetUserProfileLinkHtml(model.issue.fields.assignee)); }
public void SendNotification_1EventAfter0SecondThen1After3Minutes_Expect1NotificationSentAfter5Minutes() { //Arrange var eventEmitter = new MvvmLightMessenger(); var robot = Substitute.For <IRobot>(); robot.Messenger.Returns(eventEmitter); var scheduler = new TestScheduler(); var jiraAggregator = new JiraAggregatorSut(robot, scheduler); var user = new User { displayName = "Laurent Kempé", name = "laurent" }; var addCommentEvent1 = new JiraModel { issue = new Issue { key = "LK-10", fields = new Fields { reporter = user, assignee = user } }, webhookEvent = "jira:issue_created", comment = new CommentDetails(), user = user }; var addCommentEvent2 = new JiraModel { issue = new Issue { key = "LK-10", fields = new Fields { reporter = user, assignee = user } }, webhookEvent = "jira:issue_updated", comment = new CommentDetails(), user = user }; //Act scheduler.Schedule(TimeSpan.FromSeconds(0), () => eventEmitter.Publish("JiraEvent", addCommentEvent1)); scheduler.Schedule(TimeSpan.FromSeconds(120), () => eventEmitter.Publish("JiraEvent", addCommentEvent2)); scheduler.AdvanceTo(TimeSpan.FromSeconds(181).Ticks); robot.Received(0).SendNotification("", "", "Message", true); scheduler.AdvanceTo(TimeSpan.FromMinutes(5).Ticks); //Assert robot.Received(1).SendNotification(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), true); }
public ActionResult SetCookie(string user, string password) { var model = new JiraModel(); var restClient = new RestClient("https://godzilla.centrala.bzwbk:9999"); var request = new RestRequest("/rest/auth/1/session", Method.POST); request.AddJsonBody(new { username = user, password = password }); var response = restClient.Execute(request).Content; var jResponse = JObject.Parse(response); model.Cookie = jResponse["session"]["value"].ToString(); return(View("Authentication", model)); }
private string BuildMessage(JiraModel model) { var stringBuilder = new StringBuilder(); //SKYE-1650: Test webhook for the editor In Progress→Impeded→Impeded by Laurent Kempé. Current assignee is Laurent Kempé. switch (model.webhookEvent) { case "jira:issue_updated" : BuildChangeLogMessage(model, stringBuilder); break; case "jira:issue_created": BuildIssueCreatedMessage(model, stringBuilder); break; } return stringBuilder.ToString(); }
public void SendNotification_1EventAfter0SecondThen1After3Minutes_Expect1NotificationSentAfter5Minutes() { //Arrange var eventEmitter = new MvvmLightMessenger(); var robot = Substitute.For<IRobot>(); robot.EventEmitter.Returns(eventEmitter); var scheduler = new TestScheduler(); var jiraAggregator = new JiraAggregatorSut(robot, scheduler); var user = new User { displayName = "Laurent Kempé", name = "laurent" }; var addCommentEvent1 = new JiraModel { issue = new Issue { key = "LK-10", fields = new Fields { reporter = user, assignee = user } }, webhookEvent = "jira:issue_created", comment = new CommentDetails(), user = user }; var addCommentEvent2 = new JiraModel { issue = new Issue { key = "LK-10", fields = new Fields { reporter = user, assignee = user } }, webhookEvent = "jira:issue_updated", comment = new CommentDetails(), user = user }; //Act scheduler.Schedule(TimeSpan.FromSeconds(0), () => eventEmitter.Emit("JiraEvent", addCommentEvent1)); scheduler.Schedule(TimeSpan.FromSeconds(120), () => eventEmitter.Emit("JiraEvent", addCommentEvent2)); scheduler.AdvanceTo(TimeSpan.FromSeconds(181).Ticks); robot.Received(0).SendNotification("", "", "Message", true); scheduler.AdvanceTo(TimeSpan.FromMinutes(5).Ticks); //Assert robot.Received(1).SendNotification(Arg.Any<string>(), Arg.Any<string>(), Arg.Any<string>(), true); }
public void BuildMessage_IssueCreatedThenUpdated_ExpectOneCreationMessage() { //Arrange var jiraMessageBuilder = new JiraMessageBuilder("http://jira"); var user = new User { displayName = "Laurent Kempé", name = "laurent" }; var sameIssue = new Issue { key = "LK-10", fields = new Fields { summary = "Issue Description", reporter = user, assignee = user } }; var jiraModel1 = new JiraModel { webhookEvent = "jira:issue_created", issue = sameIssue }; var jiraModel2 = new JiraModel { webhookEvent = "jira:issue_updated", issue = sameIssue }; var sameJiraIssueKeyEvents = new List <JiraModel> { jiraModel1, jiraModel2 }; //Act var buildMessage = jiraMessageBuilder.BuildMessage(sameJiraIssueKeyEvents); //Assert Assert.That(buildMessage, Is.EqualTo("<b><a href='http://jira/browse/LK-10'>LK-10 Issue Description</a></b> has been created by <a href='http://jira/secure/ViewProfile.jspa?name=laurent'>Laurent Kempé</a> and current assignee is <a href='http://jira/secure/ViewProfile.jspa?name=laurent'>Laurent Kempé</a>.")); }
private void OnJiraEvent(JiraModel jiraModel) { _subject.OnNext(jiraModel); }
private void BuildChangeLogMessage(JiraModel model, StringBuilder stringBuilder) { if (CommentAdded(model)) { stringBuilder .AppendFormat( "{0} added a comment to <b>{1}</b>.", GetUserProfileLinkHtml(model.user), GetFullIssueLink(model.issue)); return; } if (model.changelog.items.Length == 2 && ((model.changelog.items.Any(i => i.field == "assignee") && model.changelog.items.Any(i => i.field == "status")))) { var status = model.changelog.items.First(i => i.field == "status"); if (status.toString == "Review") { stringBuilder.AppendFormat( "{0}, <b>{1}</b> has just been assigned to you for code review.", GetUserProfileLinkHtml(model.issue.fields.assignee), GetFullIssueLink(model.issue)); if (model.comment != null) { if (!string.IsNullOrEmpty(model.comment.body)) { stringBuilder .AppendFormat( "<br/>With followig comment '{0}'", model.comment.body); } } } } else { switch (model.changelog.items[0].field) { case "assignee": stringBuilder.AppendFormat( "{0}, <b>{1}</b> has just been assigned to you.", GetUserProfileLinkHtml(model.issue.fields.assignee), GetFullIssueLink(model.issue)); break; case "status": stringBuilder .AppendFormat( "<b><a href='{0}'>{1}</a></b> {2} -> {3} by {4}. Current assignee is {5}.", GetIssueLink(model.issue), GetIssueDescription(model.issue), model.changelog.items[0].fromString, model.changelog.items[0].toString, GetUserProfileLinkHtml(model.user), GetUserProfileLinkHtml(model.issue.fields.assignee)); break; } } }
private static bool CreatedIssueThenUpdated(List<JiraModel> sameJiraIssueKeyEvents, JiraModel firstEvent) { return firstEvent.webhookEvent.Equals("jira:issue_created") && sameJiraIssueKeyEvents.Skip(1).All(e => e.webhookEvent.Equals("jira:issue_updated")); }
private static bool CommentAdded(JiraModel model) { return model.comment != null && model.changelog == null; }
private static bool CreatedIssueThenUpdated(List <JiraModel> sameJiraIssueKeyEvents, JiraModel firstEvent) { return(firstEvent.webhookEvent.Equals("jira:issue_created") && sameJiraIssueKeyEvents.Skip(1).All(e => e.webhookEvent.Equals("jira:issue_updated"))); }
private static bool CommentAdded(JiraModel model) { return(model.comment != null && model.changelog == null); }