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); }
private void GetBugs(BugzillaServiceConfiguration config) { BugzillaMocks mocks = new BugzillaMocks(); List <Bug> expectedBugs = CreateSomeBogusRemoteBugs(5); List <int> expectedIds = new List <int>(); // Product expectedProduct = Product.Create(new GetProductResult(productId, productName, "Expected Descr")); // User expectedOwner = User.Create(new GetUserResult(ownerId, "Fred", "FredsLogin")); foreach (Bug bug in expectedBugs) { expectedIds.Add(int.Parse(bug.ID)); } // SetupResult.For(mocks.ClientFactory.CreateNew(config.Url, mocks.Logger)).Return(mocks.Client); Expect.Call(mocks.Client.Login()).Return(expectedUserId); for (int i = 0; i < expectedBugs.Count; i++) { Bug bug = expectedBugs[i]; Expect.Call(mocks.Client.GetBug(int.Parse(bug.ID))).Return(bug); Expect.Call(mocks.Client.Search(expectedFilterId)).Return(new List <int> { 1, 2, 3, 4, 5 }); //Expect.Call(mocks.Client.GetProduct(bug.ProductID)).Return(expectedProduct); //Expect.Call(mocks.Client.GetUser(bug.AssignedToID)).Return(expectedOwner); } mocks.Repository.ReplayAll(); BugzillaReaderUpdater reader = new BugzillaReaderUpdater(config, mocks.ClientFactory, mocks.Logger); List <Defect> returnedBugs = reader.GetBugs(); Assert.AreEqual(expectedBugs.Count, returnedBugs.Count, "Did not get back the right number of defects."); foreach (Defect defect in returnedBugs) { Assert.AreEqual(defect.ProjectId, v1ProjectId); Assert.AreEqual(defect.Owners, assignTo); Assert.AreEqual(defect.Priority, v1PriorityId); if (!string.IsNullOrEmpty(config.UrlTemplateToIssue) && !string.IsNullOrEmpty(config.UrlTitleToIssue)) { Assert.AreEqual(config.UrlTemplateToIssue.Replace("#key#", defect.ExternalId), defect.ExternalLink.Url); Assert.AreEqual(config.UrlTitleToIssue, defect.ExternalLink.Title); } } mocks.Repository.VerifyAll(); }
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(); }