public void Setup() { _bugZillaClient = MockRepository.GenerateMock <IBugzillaClient>(); _bugZillaClient.Stub(client => client.Login()).Return("123"); _bugZillaClient.Stub(client => client.AcceptBug(Arg <int> .Is.Anything, Arg <string> .Is.Anything)).Return(true); var bugZillaClientFactory = MockRepository.GenerateMock <IBugzillaClientFactory>(); bugZillaClientFactory.Stub(factory => factory.CreateNew()).Return(_bugZillaClient); var logger = MockRepository.GenerateMock <ILogger>(); var config = new BugzillaServiceConfiguration(); var bugZillaBugStatusToSet = "IN_PROGRESS"; config.OnCreateResolveValue = bugZillaBugStatusToSet; _bugzillaReaderUpdater = new BugzillaReaderUpdater(config, bugZillaClientFactory, logger); var versionOneDefect = new Defect(string.Empty, String.Empty, String.Empty, string.Empty); var bugId = "1"; versionOneDefect.ExternalId = bugId; var versionOneWorkitemCreationResult = new WorkitemCreationResult(versionOneDefect); _bugzillaReaderUpdater.OnDefectCreated(versionOneWorkitemCreationResult); }
public void OnDefectCreated(WorkitemCreationResult createdResult) { var bugId = int.Parse(createdResult.Source.ExternalId); var bugzillaClient = bugzillaClientFactory.CreateNew(); bugzillaClient.Login(); if (!bugzillaClient.AcceptBug(bugId, configuration.OnCreateResolveValue)) { logger.Log(LogMessage.SeverityType.Error, string.Format("Failed to accept bug {0}.", bugId)); } if (!string.IsNullOrEmpty(configuration.OnCreateFieldName) && !bugzillaClient.UpdateBug(bugId, configuration.OnCreateFieldName, configuration.OnCreateFieldValue)) { logger.Log(LogMessage.SeverityType.Error, string.Format("Failed to set {0} to {1}.", configuration.OnCreateFieldName, configuration.OnCreateFieldValue)); } if (!string.IsNullOrEmpty(configuration.DefectLinkFieldName)) { if (!bugzillaClient.UpdateBug(bugId, configuration.DefectLinkFieldName, createdResult.Permalink)) { logger.Log(LogMessage.SeverityType.Error, string.Format("Failed to set {0} to {1}.", configuration.DefectLinkFieldName, createdResult.Permalink)); } } if (!string.IsNullOrEmpty(configuration.OnCreateReassignValue)) { if (!bugzillaClient.ReassignBug(bugId, configuration.OnCreateReassignValue)) { logger.Log(LogMessage.SeverityType.Error, string.Format("Failed to reassign bug to {0}.", configuration.OnCreateReassignValue)); } } bugzillaClient.Logout(); }
private void OnDefectCreated(BugzillaServiceConfiguration config) { BugzillaMocks mocks = new BugzillaMocks(); Defect defect = GetStockBug(); int expectedExternalId = 1234; string expectedDefectLinkValue = "http://localhost/VersionOne.Web/assetdetail.v1?Oid=Defect:1000"; defect.ExternalId = expectedExternalId.ToString(); WorkitemCreationResult workitemCreationResult = new WorkitemCreationResult(defect); workitemCreationResult.Messages.Add("Message1"); workitemCreationResult.Permalink = expectedDefectLinkValue; SetupResult.For(mocks.ClientFactory.CreateNew()).Return(mocks.Client); Expect.Call(mocks.Client.Login()).Return(expectedUserId); Expect.Call(mocks.Client.Logout); Expect.Call(mocks.Client.AcceptBug(Arg <int> .Is.Anything, Arg <string> .Is.Anything)).Return(true); if (!string.IsNullOrEmpty(config.OnCreateFieldName)) { Expect.Call(mocks.Client.UpdateBug(expectedExternalId, config.OnCreateFieldName, config.OnCreateFieldValue)).Return(true); } if (!string.IsNullOrEmpty(config.DefectLinkFieldName)) { Expect.Call(mocks.Client.UpdateBug(expectedExternalId, config.DefectLinkFieldName, expectedDefectLinkValue)).Return(true); } if (!string.IsNullOrEmpty(config.OnCreateReassignValue)) { Expect.Call(mocks.Client.ReassignBug(expectedExternalId, config.OnCreateReassignValue)).Return(true); } mocks.Repository.ReplayAll(); BugzillaReaderUpdater updater = new BugzillaReaderUpdater(config, mocks.ClientFactory, mocks.Logger); updater.OnDefectCreated(workitemCreationResult); mocks.Repository.VerifyAll(); }
public void OnWorkitemCreated() { var workitem = new Story("Title", "description", "project", "owners"); var workitemResult = new WorkitemCreationResult(workitem) { Source = { ExternalId = ExternalId, }, Permalink = "link", }; workitemResult.Messages.Add("external id"); FullUpdateJiraIssue(ExternalId, config.OnCreateFieldName, config.OnCreateFieldValue, workitemResult.Messages, config.ProgressWorkflow, null); UpdateWorkitemLinkInJira(workitemResult); Repository.ReplayAll(); reader.OnWorkitemCreated(workitemResult); Repository.VerifyAll(); }
///<summary> /// A Workitem has been created in VersionOne in response to an Issue in JIRA. /// We must update the Issue in JIRA to reflect the Workitem creation in VersionOne. /// That reflection may be manifest by... /// 1) Updating a field (probably a custom field) to some value. /// 2) Progressing the workflow to another status. /// One of these updates should keep the Issue from appearing in the new Issues filter again. ///</summary> ///<param name = "createdResult">Everything we need to know about the Workitem created in VersionOne.</param> public void OnWorkitemCreated(WorkitemCreationResult createdResult) { var issueId = createdResult.Source.ExternalId; var fieldName = configuration.OnCreateFieldName; var fieldValue = configuration.OnCreateFieldValue; var workflowId = configuration.ProgressWorkflow; var messages = createdResult.Messages; UpdateJiraIssue(issueId, fieldName, fieldValue, messages, workflowId, null); if (!string.IsNullOrEmpty(configuration.WorkitemLinkField)) { connector.Login(); logger.Log(LogMessage.SeverityType.Info, string.Format("Updating field {0} in JIRA issue {1}", configuration.WorkitemLinkField, issueId)); connector.UpdateIssue(issueId, configuration.WorkitemLinkField, createdResult.Permalink); connector.Logout(); } }
public void OnWorkitemCreatedInsufficientPermissions() { var workitem = new Story("Title", "description", "project", "owners"); var workitemResult = new WorkitemCreationResult(workitem) { Source = { ExternalId = ExternalId, }, Permalink = "link", }; workitemResult.Messages.Add("external id"); Expect.Call(ConnectorMock.Login); Expect.Call(ConnectorMock.UpdateIssue(ExternalId, config.OnCreateFieldName, config.OnCreateFieldValue)).Throw(new JiraException("Can't update issue", new Exception())); Expect.Call(ConnectorMock.Logout); UpdateWorkitemLinkInJira(workitemResult); Repository.ReplayAll(); reader.OnWorkitemCreated(workitemResult); Repository.VerifyAll(); }
private void UpdateWorkitemLinkInJira(WorkitemCreationResult workitemResult) { Expect.Call(ConnectorMock.Login); Expect.Call(ConnectorMock.UpdateIssue(workitemResult.Source.ExternalId, config.WorkitemLinkField, workitemResult.Permalink)).Return(null); Expect.Call(ConnectorMock.Logout); }