public void Update_CreationResultFailure_OnPilotIssue()
 {
     var creationResult = new WorkitemCreationFailureResult(new Defect())
     {
         //Source = { ExternalId = "PILOT-416" },
         Source = { ExternalId = "VOID-37" },
     };
     //creationResult.Messages.Add("Integration Test Comment - Creation Failure");
     jiraIssueReaderUpdater.OnWorkitemCreationFailure(creationResult);
 }
        public WorkitemUpdateResult CreateWorkitem(Workitem item)
        {
            if(item == null) {
                throw new ArgumentNullException("item");
            }

            var type = item.Type;

            logger.Log(LogMessage.SeverityType.Info,
                string.Format("Creating VersionOne {0} for item from {1} system with identifier {2}", type, item.ExternalSystemName, item.ExternalId));

            var url = string.Empty;
            var urlTitle = string.Empty;

            if(item.ExternalUrl != null) {
                url = item.ExternalUrl.Url;
                urlTitle = item.ExternalUrl.Title;
            }

            ServerConnector.Entities.Workitem newWorkitem = null;
            string failureMessage = null;

            try {
                newWorkitem = v1Processor.CreateWorkitem(type, item.Title, item.Description, item.ProjectId, item.Project, externalFieldName, item.ExternalId,
                    item.ExternalSystemName, item.Priority, item.Owners, urlTitle, url, item.Environment, item.FoundBy, item.VersionAffected, item.BuildNumber, item.SeverityLevel);
                logger.Log(LogMessage.SeverityType.Info, string.Format("VersionOne asset {0} succesfully created.", newWorkitem.Id));
            } catch (Exception ex) {
                logger.Log(LogMessage.SeverityType.Error, string.Format("Error during saving workitems: {0}", ex.Message));
                failureMessage = string.Format("Faild to create item in versionOne, reason: \"{0}\"", ex.Message);
            }

            if(newWorkitem != null) {
                var result = new WorkitemCreationResult(item) {
                    Source = {
                        Number = newWorkitem.Number,
                        ExternalId = item.ExternalId,
                        Description = newWorkitem.Description,
                        ExternalSystemName = item.ExternalSystemName,
                        ProjectId = newWorkitem.Project.Key,
                        Project = newWorkitem.Project.Value,
                        Title = newWorkitem.Name,
                        Priority = newWorkitem.PriorityToken,
                        Environment = newWorkitem.Environment,
                    },
                    WorkitemId = newWorkitem.Id,
                    Permalink = v1Processor.GetWorkitemLink(newWorkitem),
                };

                result.Messages.Add(string.Format("Created item \"{0}\" ({1}) in Project \"{2}\" URL: {3}",
                    item.Title,
                    result.Source.Number,
                    item.Project,
                    result.Permalink));

                return result;
            }

            var failureResult = new WorkitemCreationFailureResult(item);
            failureResult.Messages.Add(failureMessage);
            failureResult.Warnings.Add(string.Format("[{0}] {1}", item.ExternalId, failureMessage));
            return failureResult;
        }