public void CreateIssueInMissingProject()
        {
            var newWorkitem = new NewVersionOneWorkitem("Scope:somescope")
            {
                Title = "Title",
                Description = "Description",
                Number = "D-1",
                ProjectId = "Query scope is used",
            };

            Assert.IsFalse(jiraIssueReaderUpdater.OnNewWorkitem(newWorkitem, "JIRA"));
        }
        public void CreateIssueInMappedProject()
        {
            var newWorkitem = new NewVersionOneWorkitem("Scope:123456")
            {
                Title = "Title",
                Description = "Description",
                Number = "D-1",
                ProjectId = "Query scope is used",
            };

            newWorkitem.Messages.Add("Integration Test Comment - Creating JIRA Issue");
            Assert.IsTrue(jiraIssueReaderUpdater.OnNewWorkitem(newWorkitem, "JIRA"));
        }
        public NewVersionOneWorkitemsCollection GetNewWorkitems(DateTime lastCreatedTimestamp, string lastCreatedWorkitemId, IEnumerable<string> scopes)
        {
            var results = new NewVersionOneWorkitemsCollection();

            var lastLocalCreatedTimestamp = lastCreatedTimestamp;
            var lastLocalCreatedWorkitemId = lastCreatedWorkitemId;

            try {
                foreach (string scope in scopes) {
                    var filter = FilterDefectsCreatedSince(lastCreatedTimestamp, scope);

                    var workitems = v1Processor.GetWorkitems(VersionOneProcessor.DefectType, filter);

                    foreach (VersionOne.ServerConnector.Entities.Defect item in workitems) {
                        var id = item.Number;
                        var createDateUtc = item.CreateDateUtc;

                        logger.Log(LogMessage.SeverityType.Debug, string.Format("Processing V1 Workitem {0} created at {1}", id, createDateUtc));

                        if (lastLocalCreatedWorkitemId.Equals(id) == true && lastCreatedTimestamp.CompareTo(createDateUtc) == 0) {
                            logger.Log(LogMessage.SeverityType.Debug, "\tSkipped because this ID was processed last time");
                            continue;
                        }

                        if (lastLocalCreatedTimestamp.CompareTo(createDateUtc) < 0) {
                            logger.Log(LogMessage.SeverityType.Debug, "\tCaused an update to lastCreatedTimestamp and lastCreatedWorkitemId");
                            lastLocalCreatedTimestamp = createDateUtc;
                            lastLocalCreatedWorkitemId = id;
                        }

                        //TODO extract to new method
                        var workitem = new NewVersionOneWorkitem(scope) {
                            Number = item.Number,
                            Title = item.Name,
                            Description = item.Description,
                            ProjectId = item.Project.Key,
                            Project = item.Project.Value,
                            Priority = item.Priority,
                            Environment = item.Environment,
                            Url = v1Processor.GetWorkitemLink(item),
                            BuildNumber = item.FoundInBuild,
                            SeverityLevel = item.SeverityLevel,
                            Created = item.CreateDateUtc,
                            Updated = item.ChangeDateUtc,
                        };

                        if (item.CreatedByUsername != null)
                            workitem.CreatedBy = ExtractUsername(item.CreatedByUsername);

                        if (item.OwnersUsernames != null)
                            workitem.Owners = ExtractUsernames(item.OwnersUsernames);

                        workitem.Messages.Add("VersionOne URL: " + workitem.Url);

                        results.Add(workitem);
                    }
                }
            } catch (WebException ex) {
                string responseMessage = null;

                if (ex.Response != null) {
                    using (var reader = new StreamReader(ex.Response.GetResponseStream())) {
                        responseMessage = reader.ReadToEnd();
                    }
                }

                logger.Log(LogMessage.SeverityType.Error, string.Format("Error querying VersionOne ({0}) for newly created defects:\r\n{1}\r\n\r\n{2}", ex.Response.ResponseUri, responseMessage, ex));
            } catch (Exception ex) {
                logger.Log(LogMessage.SeverityType.Error, string.Format("Error while creating new workitems list, reason: {0}", ex.Message));
            }

            results.QueryTimeStamp = lastLocalCreatedTimestamp;
            results.LastCheckedDefectId = lastLocalCreatedWorkitemId;

            return results;
        }