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(bug.ID);
			}

			SetupResult.For(mocks.ServiceFactory.CreateNew(config.Url)).Return(mocks.Client);

            Expect.Call(mocks.Client.Login(config.UserName, config.Password, true, false)).Return(expectedUserId);
			//Expect.Call(mocks.Client.GetBugs(config.OpenIssueFilterId)).Return(expectedIds);

			for (int i = 0; i < expectedBugs.Count; i++)
			{
				Bug bug = expectedBugs[i];
				Expect.Call(mocks.Client.GetBug(bug.ID)).Return(bug);
				Expect.Call(mocks.Client.GetProduct(bug.ProductID)).Return(expectedProduct);
				Expect.Call(mocks.Client.GetUser(bug.AssignedToID)).Return(expectedOwner);
			}

			mocks.Client.Logout();

			mocks.Repository.ReplayAll();

			BugzillaReaderUpdater reader = new BugzillaReaderUpdater(config, mocks.ServiceFactory, 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, expectedOwner.Login);
                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.ServiceFactory.CreateNew(config.Url)).Return(mocks.Client);

			Expect.Call(mocks.Client.Login(config.UserName, config.Password, true, false)).Return(expectedUserId);
			
			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);
			}

			if (!string.IsNullOrEmpty(config.OnCreateResolveValue))
			{
				Expect.Call(mocks.Client.ResolveBug(expectedExternalId, config.OnCreateResolveValue, string.Empty)).Return(true);
			}

			mocks.Client.Logout();

			mocks.Repository.ReplayAll();

			BugzillaReaderUpdater updater = new BugzillaReaderUpdater(config, mocks.ServiceFactory, mocks.Logger);

			updater.OnDefectCreated(workitemCreationResult);

			mocks.Repository.VerifyAll();

		}