Inheritance: Workitem
        public void ProcessWorkitemSuccess()
        {
            var defect = new Defect();
            var result = new WorkitemCreationResult(defect);

            Expect.Call(workitemWriterMock.CheckForDuplicate(defect)).Return(false);
            Expect.Call(workitemWriterMock.CreateWorkitem(defect)).Return(result);
            Expect.Call(() => eventManagerMock.Publish(result));

            Repository.ReplayAll();
            eventManager.Publish(defect);
            Repository.VerifyAll();
        }
        public void UpdateWorkitemTest()
        {
            //given
            WorkitemWriter writer = new WorkitemWriter("Source");
            var defect = new VersionOne.ServiceHost.WorkitemServices.Defect();
            defect.Number = "D-78694";
            defect.ExternalId = "JRA-1000";
            defect.ExternalSystemName = "JIRA";
            UrlToExternalSystem url = new UrlToExternalSystem("http://jira.sabre.com/", "JIRA LINK");
            defect.ExternalUrl = url;

            //when
            writer.UpdateExternalWorkitem(defect);

            //then
            //TODO check if it was executed
        }
        public List<Defect> GetBugs() 
        {
            var bugzillaClient = bugzillaClientFactory.CreateNew(configuration.Url);

            var ids = bugzillaClient.LoginSearch(configuration.UserName, configuration.Password, true, configuration.OpenIssueFilterId, configuration.IgnoreCert);
            var defects = new List<Defect>(ids.Count);

            foreach (var id in ids) 
            {
                var bug = bugzillaClient.GetBug(id);
            	var product = bugzillaClient.GetProduct(bug.ProductID);
            	var user = bugzillaClient.GetUser(bug.AssignedToID);

                var projectMapping = ResolveVersionOneProjectMapping(product.Name);
                var priorityMapping = ResolveVersionOnePriorityMapping(bug.Priority);

                var defect = new Defect(bug.Name, bug.Description, projectMapping.Name, user.Login) 
                    { ExternalId = bug.ID.ToString(CultureInfo.InvariantCulture),
                      ProjectId = projectMapping.Id };

                // If the BugzillaBugUrlTemplate tag of the config file is set, then build a URL to the issue in Bugzilla.
				if (!string.IsNullOrEmpty(configuration.UrlTemplateToIssue) && !string.IsNullOrEmpty(configuration.UrlTitleToIssue)) 
                {
					defect.ExternalLink = new UrlToExternalSystem(configuration.UrlTemplateToIssue.Replace("#key#", bug.ID.ToString()), configuration.UrlTitleToIssue);
				}

                if (priorityMapping != null) 
                {
                    defect.Priority = priorityMapping.Id;
                } 
                
                logger.Log(string.Format("Product: ({0}) Bug: ({1}) Defect: ({2}) AssignedTo: ({3})", product, bug, defect, user));
				defects.Add(defect);
            }

            bugzillaClient.Logout();
			return defects;
		}
        private Defect CreateV1Defect(string title, string externalId, string description, string priority, string v1Project) {
            var defect = new Defect {
                                        Title = title,
                                        ExternalId = externalId,
                                        ExternalSystemName = versionOneSourceField,
                                        Project = v1Project,
                                        Description = description
                                    };

            var mappedVersionOnePriority = ResolvePriorityMapping(priority);

            if (mappedVersionOnePriority != null) {
                defect.Priority = mappedVersionOnePriority.Id;
            }

            return defect;
        }