示例#1
0
        public async Task CreateIssue_WhenModelValid_CreatesIssueInDbAndReturnSuccessResponse()
        {
            var claims = new Claim("roles", "ProjectManager");
            var token  = GetJwtToken(new[] { claims });

            AddAuth(token);
            var issuesCount = IssuesDbSet.Get().Count();
            var request     = new IssueDto()
            {
                ProjectId        = ProjectsDbSet.Get().First().Id,
                MilestoneId      = null,
                Description      = "description",
                Status           = Status.Closed,
                AssignedToUserId = UsersDbSet.Get().First().Id,
                ReportedByUserId = UsersDbSet.Get().First().Id,
                Title            = "title"
            };

            var httpResponse = await PostAsync(IssueControllerRoutes.CreateIssue, request);

            httpResponse.EnsureSuccessStatusCode();
            var response = await httpResponse.BodyAs <ApiResponse <IssueDto> >();

            response.VerifySuccessResponse();
            await CheckIssueIsAddedToDatabase(response.Data, issuesCount + 1);

            response.VerifySuccessResponse();
            await ReSeedDatabase();
        }
        public async Task <ActionResult <IssueDto> > PostIssue([FromBody] IssueDto issueDto)
        {
            _logger.LogInformation($"Post issue {issueDto}", issueDto);
            var insertedIssue = await _issueService.Add(issueDto);

            return(CreatedAtAction("GetIssue", new { id = insertedIssue.Id }, insertedIssue));
        }
 public override WidgetResult Caption(IssueDto issue = null)
 {
     return(new WidgetResult()
     {
         Success = true, Markup = new WidgetMarkup(AppName)
     });
 }
示例#4
0
        private CodeCommentBlock ParseCommentBlock(string comment, IssueDto args, string revisionid)
        {
            CodeCommentBlock block = new CodeCommentBlock();

            Regex ex = new Regex("GEM:(?<issueid>[0-9]+)", RegexOptions.IgnoreCase);

            MatchCollection matches = ex.Matches(comment);

            if (matches.Count > 0)
            {
                foreach (var item in matches)
                {
                    int issueId = item.ToString().ReplaceIgnoreCase("gem:", string.Empty).ToInt();

                    if (issueId != args.Id && !block.Items.ContainsKey(issueId))
                    {
                        block.Items.Add(issueId, string.Format("<a href='{0}project/all/0/item/{1}' target='_blank'>{1}</a>", UserContext.Url, issueId));
                    }
                }
            }

            block.Comment = comment;

            return(block);
        }
        private void MockData()
        {
            _issues = new List <Issue>
            {
                new Issue()
                {
                    Id   = 1,
                    Name = "General"
                },
                new Issue()
                {
                    Id   = 2,
                    Name = "Support"
                }
            };

            _issuesDto = _issues.Select(issue => new IssueDto
            {
                Id   = issue.Id,
                Name = issue.Name
            }).ToList();

            _issuesQueryableMock = _issues.AsQueryable().BuildMock();
            _issue    = _issues.FirstOrDefault();
            _issueDto = _issuesDto.FirstOrDefault();
        }
示例#6
0
        private IssueDto GetDtoWithLinks(Issue issue)
        {
            var dto = IssueDto.From(issue);

            dto.AddLinks(_linkGenerator.GetLinks(issue));
            return(dto);
        }
        public async Task <IActionResult> Get(string project, string name, string locale, [FromQuery] bool onlyactive = true)
        {
            if (!ModelState.IsValid || string.IsNullOrWhiteSpace(project) || string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(locale))
            {
                return(BadRequest("Invalid or missing parameters"));
            }

            GenericRepository <Build> buildRepo = _unitOfWork.BuildRepository;

            Build build = await BuildHelper.GetLatestBuild(buildRepo, project);

            Guid buildId = (build == null ? new Guid() : build.Id);


            GenericRepository <Issue> issueRepo = _unitOfWork.IssueRepository;

            List <IssueDto> issues = new List <IssueDto>();

            foreach (Issue issue in await issueRepo.GetAsync(i =>
                                                             i.ProjectName.Equals(project) &&
                                                             i.LocaleCode.Equals(locale) &&
                                                             i.ScreenName.Equals(name) &&
                                                             i.ModifiedInBuildId == buildId &&
                                                             (!onlyactive || i.IssueStatus == IssueStatus.Active),
                                                             includeProperties: "Build"))
            {
                IssueDto issueDto = new IssueDto();
                _mapper.Map <Issue, IssueDto>(issue, issueDto);

                issues.Add(issueDto);
            }

            return(Ok(issues));
        }
示例#8
0
        /// <summary>
        /// Adds a watcher if it has the same domain as the email address. Only if user is not watcher as on this task.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="domain"></param>
        /// <param name="issueParam"></param>
        /// <param name="userId"></param>
        /// <param name="username"></param>
        /// <param name="createAudit"></param>
        private void AddWatcherFromDomain(GeminiContext context, string domain, IssueDto issueParam, int userId, string username, bool createAudit)
        {
            try
            {
                IssueDto       issue       = issueParam;
                Helper         helper      = new Helper();
                UserManager    usermanager = new UserManager(GeminiApp.Cache(), GeminiApp.UserContext(), context);
                List <UserDto> users       = usermanager.GetActiveUsers();

                foreach (UserDto user in users)
                {
                    // Only if not already watcher on this task
                    if (!issue.Entity.Watchers.Contains(user.Entity.Id.ToString()))
                    {
                        string activeUserDomain = helper.FindDomain(user.Entity.Email);
                        if (domain == activeUserDomain)
                        {
                            issue.Entity.AddWatcher(user.Entity.Id);

                            if (createAudit)
                            {
                                string watcher = user.Entity.Fullname;
                                helper.CreateAuditlog(context, issue.Id, issue.Project.Id, null, "", watcher, userId, username);
                            }
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                GeminiApp.LogException(exception, false, exception.Message);
            }
        }
示例#9
0
        public override WidgetResult Show(IssueDto issue = null)
        {
            WidgetResult result = new WidgetResult();

            List <int>    selectedProjects = new List <int>();
            ReportOptions options          = new ReportOptions();

            SummaryModel     model = new SummaryModel();
            IssuesGridFilter tmp   = new IssuesGridFilter();

            try
            {
                if (CurrentCard.IsNew || !CurrentCard.Options.ContainsKey(AppGuid))
                {
                    tmp = new IssuesGridFilter(HttpSessionManager.GetFilter(CurrentCard.Id, CurrentCard.Filter));

                    if (tmp == null)
                    {
                        tmp = CurrentCard.Options[AppGuid].FromJson <IssuesGridFilter>();
                    }

                    if (tmp.Projects == Constants.AllProjectsId.ToString())
                    {
                        selectedProjects.Add(Constants.AllProjectsId);
                    }
                    else
                    {
                        selectedProjects = tmp.GetProjects();
                    }
                }
                else
                {
                    options = CurrentCard.Options[AppGuid].FromJson <ReportOptions>();

                    if (options.AllProjectsSelected)
                    {
                        selectedProjects.Add(Constants.AllProjectsId);
                    }
                    else if (options.ProjectIds.Count > 0)
                    {
                        selectedProjects.AddRange(options.ProjectIds);
                    }
                }
            }
            catch (Exception ex)
            {
                tmp = new IssuesGridFilter(HttpSessionManager.GetFilter(CurrentCard.Id, IssuesFilter.CreateProjectFilter(UserContext.User.Entity.Id, UserContext.Project.Entity.Id)));

                selectedProjects = tmp.GetProjects();
            }

            model.ProjectList = GetProjectFilter(selectedProjects);
            model.Options     = options;

            result.Markup = new WidgetMarkup("views\\Summary.cshtml", model);

            result.Success = true;

            return(result);
        }
示例#10
0
        public IssueDto EditRuntimeIssue(int id)
        {
            IssueDto issue = null;

            if (id == 0)
            {
                issue = new IssueDto {
                    Id = _newRuntimeTaskId
                };
            }
            else
            {
                var runtimeIssues = (List <IssueDto>)HttpContext.Current.Session["runtimeIssues"];

                foreach (var runtimeIssue in runtimeIssues)
                {
                    if (runtimeIssue.Id != id)
                    {
                        continue;
                    }
                    issue = runtimeIssue;
                    break;
                }
            }

            if (issue == null)
            {
                throw new EntityNotFoundException(IssueResource.IssueNotFoundById + id);
            }

            return(issue);
        }
示例#11
0
        private IssueDto MapToIssueDto(IssueViewModel viewModel)
        {
            var orderNo = RandomTools.GetUniqueKey(10);
            var dto     = new IssueDto
            {
                Type   = viewModel.Type,
                Mode   = viewModel.Mode,
                Client = viewModel.Client,

                OrderNo      = orderNo,
                Language     = viewModel.Language,
                PayableCoins = viewModel.PayableCoins,

                CallbackUrl = GetSecureCallbackUrl(orderNo),
                WebhookUrl  = GetSecureWebhookUrl(orderNo),

                AllowReject   = viewModel.AllowReject,
                AllowTestNets = viewModel.AllowTestNets
            };

            if (viewModel.Type == Constants.PaymentType.Restricted)
            {
                dto.BaseAmount     = viewModel.BaseAmount;
                dto.BaseCurrencyId = viewModel.BaseCurrencyId;
            }

            if (dto.Language?.ToLower() == "auto")
            {
                dto.Language = null;
            }

            return(dto);
        }
示例#12
0
        public async Task <PaymentDto> IssueAsync(IssueDto input)
        {
            var httpRequest = BuildRequest(IssueUrl, input, Method.POST);
            var response    = await ExecuteRequestAsync <Response <PaymentDto> >(httpRequest);

            return(response.Result);
        }
示例#13
0
 public override WidgetResult Caption(IssueDto issue)
 {
     return(new WidgetResult()
     {
         Success = true, Markup = new WidgetMarkup("DocStore")
     });
 }
            public async Task CreateIssueAsync_Should_Return_CreatedAtActionResult_With_The_created_Issue_Test()
            {
                // Arrange

                var expectedCreatedAtActionName = nameof(IssueController.IssueByIdAsync);
                var issueToCreate = new IssueForCreationDto {
                    IssueDescription = "Test  1"
                };
                var expectedResult = new IssueDto {
                    Id = 1, IssueDescription = "Test  1"
                };

                IssueServiceMock
                .Setup(x => x.CreateIssueAsync(issueToCreate))
                .ReturnsAsync(expectedResult);

                // Act

                var result = await ControllerUnderTest.CreateIssueAsync(issueToCreate);

                // Assert

                var createdResult = Assert.IsType <CreatedAtRouteResult>(result);

                Assert.Same(expectedResult, createdResult.Value);
                Assert.Equal(expectedCreatedAtActionName, createdResult.RouteName);
                Assert.Equal(expectedResult.Id, createdResult.RouteValues.GetValueOrDefault("id")
                             );
            }
示例#15
0
        /// <summary>
        /// Add user with the same domain (superuser) as watcher.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="issueParam"></param>
        /// <param name="user"></param>
        /// <param name="createAudit"></param>
        private void AddSuperuser(GeminiContext context, IssueDto issueParam, User user, bool createAudit)
        {
            try
            {
                IssueDto issue  = issueParam;
                Helper   helper = new Helper();
                if ((issue.CustomFields.Count > 0) && (!issue.CustomFields.Find(field => field.Name.Equals(helper.GetAppConfigValue("customFieldNameDomain"))).ToString().Equals(null)))
                {
                    // Alternatively .Entity.Data could be chosen.
                    string domain = helper.GetFormattedDataErstellerOE(issue);

                    // If there is something to consider
                    if (helper.GetAppConfigValue("blacklist") != null)
                    {
                        // It has to be considered that we already are the superusers of erz.be.ch (and potentially other domains)
                        string   forbiddenDomains = helper.GetAppConfigValue("blacklist");
                        string[] domains          = forbiddenDomains.Split(',');

                        if (!Array.Exists(domains, element => element == domain))
                        {
                            AddWatcherFromDomain(context, domain, issue, user.Id, user.Fullname, createAudit);
                        }
                    }
                    else
                    {
                        AddWatcherFromDomain(context, domain, issue, user.Id, user.Fullname, createAudit);
                    }
                }
            }
            catch (Exception exception)
            {
                GeminiApp.LogException(exception, false, exception.Message);
            }
        }
示例#16
0
        public void GetWorklogsTotalTimeSpent_Issue_ReturnsTotalTimeInSeconds()
        {
            // Arrange.
            IssueDto issue = new IssueDto();

            issue.Worklogs.Add(new WorklogDto {
                TimeSpentSeconds = 301
            });
            issue.Worklogs.Add(new WorklogDto {
                TimeSpentSeconds = 4505
            });
            issue.Worklogs.Add(new WorklogDto {
                TimeSpentSeconds = 1999
            });

            int excepted = 0;

            foreach (var worklog in issue.Worklogs)
            {
                excepted += worklog.TimeSpentSeconds;
            }

            // Act.
            int result = WorklogsTimeSpentCounter.GetTotalTime(issue);

            // Assert.
            Assert.Equal(excepted, result);
        }
示例#17
0
        public void AddOrUpdateRuntimeIssue(IssueDto issue)
        {
            if (issue.EmployeeId != null)
            {
                issue.EmployeeDto =
                    _mapper.Map <EmployeeDto>(_unitOfWork.EmployeeRepository.GetById((int)issue.EmployeeId));
            }

            var runtimeIssues = (List <IssueDto>)HttpContext.Current.Session["runtimeIssues"] ?? new List <IssueDto>();

            for (var i = 0; i < runtimeIssues.Count; i++)
            {
                if (runtimeIssues[i].Id != issue.Id)
                {
                    continue;
                }
                runtimeIssues.RemoveAt(i);
                runtimeIssues.Insert(i, issue);
                break;
            }

            if (issue.Id == _newRuntimeTaskId)
            {
                runtimeIssues.Add(issue);
                _newRuntimeTaskId--;
            }

            HttpContext.Current.Session["runtimeIssues"] = runtimeIssues;
        }
示例#18
0
        public void AddOrUpdateIssue(IssueDto issue)
        {
            if (issue.Id == 0)
            {
                issue.ProjectDto  = null;
                issue.EmployeeDto = null;
                _unitOfWork.IssueRepository.Add(_mapper.Map <Issue>(issue));
            }
            else
            {
                issue.ProjectDto  = null;
                issue.EmployeeDto = null;

                if (issue.Id != null)
                {
                    var issueFromDb = _unitOfWork.IssueRepository.GetById((int)issue.Id);

                    if (issueFromDb == null || issueFromDb.IsDeleted == 1)
                    {
                        throw new EntityNotFoundException(IssueResource.IssueNotFoundById + issue.Id);
                    }
                }

                _unitOfWork.IssueRepository.Update(_mapper.Map <Issue>(issue));
                _unitOfWork.Save();
            }
        }
示例#19
0
        public override WidgetResult Caption(IssueDto issue)
        {
            WidgetResult result = new WidgetResult();

            result.Success     = true;
            result.Markup.Html = "Slack Integration";
            return(result);
        }
示例#20
0
 public Issue(IssueDto model)
 {
     this.Validate(model);
     this.IssueType  = model.IssueTypeId;
     this.CitizenId  = model.CitizenId;
     this.LocationId = model.LocationId;
     this.Details    = model.Details;
 }
        public IssueDto UpdateIssue(IssueDto issueDto)
        {
            // TODO: Get the logged in user instead of hard coding
            var currentUserId = 1;

            issueDto.CreatedByUserId = currentUserId;
            return(_issueRepository.UpdateIssue(issueDto));
        }
示例#22
0
        public override WidgetResult Show(IssueDto args)
        {
            var result = new WidgetResult();

            result.Success     = true;
            result.Markup.Html = "Slack Integration";
            return(result);
        }
示例#23
0
        public IssueDto Update(IssueDto issueDTO)
        {
            var issue = _mapper.Map <Issue>(issueDTO);

            _issueRepository.Update(issue);
            _issueRepository.SaveChanges();
            return(_mapper.Map <IssueDto>(_issueRepository.GetAllDetails(issue.Id)));
        }
        public void CanDetectExistingIssues()
        {
            GenericRepository <Issue> issueRepo = _unitOfWork.IssueRepository;
            GenericRepository <Build> buildRepo = _unitOfWork.BuildRepository;

            int initialIssueNo    = _context.Issues.Count();
            int initialIssueRevNo = _context.IssueRevision.Count();

            string _projectName = "Velocity";
            string _screenName  = "Install";
            string _locale      = "pl-PL";
            string _build       = "1.0";

            Build build = buildRepo.Get(b => b.BuildName.Equals(_build)).FirstOrDefault();

            //new Issue { ProjectName = project1Name, ScreenName = screen1Name, LocaleCode = "en-US", IssueType = IssueType.Hardcode, Identifier = "1", Value = "Hardcode", ModifiedInBuildId = buildId, IssueStatus = IssueStatus.Active },
            //new Issue { ProjectName = project1Name, ScreenName = screen1Name, LocaleCode = "pl-PL", IssueType = IssueType.Hardcode, Identifier = "1", Value = "Hardcode", ModifiedInBuildId = buildId, IssueStatus = IssueStatus.Active },
            //new Issue { ProjectName = project1Name, ScreenName = screen1Name, LocaleCode = "pl-PL", IssueType = IssueType.Linguistic, Identifier = "2", Value = "Test1", ModifiedInBuildId = buildId, IssueStatus = IssueStatus.FalsePositive },
            //new Issue { ProjectName = project1Name, ScreenName = screen1Name, LocaleCode = "pl-PL", IssueType = IssueType.Overlapping, Identifier = "3", Value = "", ModifiedInBuildId = buildId, IssueStatus = IssueStatus.Active, X = 0, Y = 0, Width = 10, Height = 10 }


            IssueDto sameIssue1 = new IssueDto()
            {
                Identifier = "1", Type = IssueType.Hardcode, Text = "New hardcode"
            };                                                                                                              // same Id different text
            IssueDto sameIssue2 = new IssueDto()
            {
                Identifier = "0", Type = IssueType.Hardcode, Text = "Hardcode"
            };                                                                                                          // differetn Id same text
            IssueDto sameIssue3 = new IssueDto()
            {
                Identifier = "0", Type = IssueType.Overlapping, Text = "", X = 0, Y = 0, Width = 10, Height = 10
            };                                                                                                                                         // different Id, empty text, same coordinates
            IssueDto sameIssue4 = new IssueDto()
            {
                Identifier = "1", Type = IssueType.Hardcode, Text = "Hardcode"
            };                                                                                                        // same 1
            IssueDto sameIssue5 = new IssueDto()
            {
                Identifier = "2", Type = IssueType.Linguistic, Text = "Test1"
            };                                                                                                       // same 2
            IssueDto differentTypeIssue = new IssueDto()
            {
                Identifier = "1", Type = IssueType.Linguistic, Text = "Hardcode"
            };                                                                                                                  // same, with different type



            Assert.IsNotNull(IssueHelper.GetExistingIssue(issueRepo, _projectName, _screenName, _locale, sameIssue1));
            Assert.IsNotNull(IssueHelper.GetExistingIssue(issueRepo, _projectName, _screenName, _locale, sameIssue2));
            Assert.IsNotNull(IssueHelper.GetExistingIssue(issueRepo, _projectName, _screenName, _locale, sameIssue3));
            Assert.IsNotNull(IssueHelper.GetExistingIssue(issueRepo, _projectName, _screenName, _locale, sameIssue4));
            Assert.IsNull(IssueHelper.GetExistingIssue(issueRepo, _projectName + "1", _screenName, _locale, sameIssue4));
            Assert.IsNull(IssueHelper.GetExistingIssue(issueRepo, _projectName, _screenName + "1", _locale, sameIssue4));
            Assert.IsNotNull(IssueHelper.GetExistingIssue(issueRepo, _projectName, _screenName, "en-US", sameIssue4));
            Assert.IsNull(IssueHelper.GetExistingIssue(issueRepo, _projectName, _screenName, "en-US", sameIssue5));
            Assert.IsNull(IssueHelper.GetExistingIssue(issueRepo, _projectName, _screenName, _locale, differentTypeIssue));
        }
示例#25
0
        public async Task <bool> Update(IssueDto issueDto)
        {
            var issue = _mapper.Map <Issue>(issueDto);

            _issueRepository.Update(issue);
            var affectedRows = await _issueRepository.SaveChangesAsync();

            return(affectedRows > 0);
        }
        public async Task AddIssue_IssueIsValid_Returns_IssueDto()
        {
            var issueDto = new IssueDto();

            var issueResult = await _issueService.Add(issueDto);

            _issueRepositoryMock.Verify(x => x.Add(It.IsAny <Issue>()), Times.Once);
            _issueRepositoryMock.Verify(x => x.SaveChangesAsync(), Times.Once);
        }
示例#27
0
        public async Task <IssueDto> Add(IssueDto issueDto)
        {
            var issue = _mapper.Map <Issue>(issueDto);

            _issueRepository.Add(issue);
            await _issueRepository.SaveChangesAsync();

            return(_mapper.Map <IssueDto>(issue));
        }
示例#28
0
        private async Task CheckIssueIsAddedToDatabase(IssueDto issue, int expectedCount)
        {
            var context         = GetService <TimeTrackingDbContext>();
            var issueInDatabase = await context.Issues.OrderBy(e => e.CreatedAt).LastAsync();

            context.Issues.Should().HaveCount(expectedCount);
            issue.Should().BeEquivalentTo(issueInDatabase, opt =>
                                          opt.ExcludingMissingMembers().Excluding(e => e.Status));
            issue.Status.Should().Be(issue.Status);
        }
        public void Remove(IssueDto dto)
        {
            var needle   = _dataStore.FirstOrDefault(x => x.Id == dto.Id);
            var wasFound = needle != null;

            if (wasFound)
            {
                _dataStore.Remove(needle);
            }
        }
示例#30
0
        public override WidgetResult Caption(IssueDto issue = null)
        {
            WidgetResult result = new WidgetResult();

            result.Success = true;

            result.Markup.Html = AppName;

            return(result);
        }
示例#31
0
        public override WidgetResult Show(IssueDto issue = null)
        {
            WidgetResult result = new WidgetResult();

            IssueWidgetData<string> data = GeminiContext.IssueWidgetStore.Get<string>(issue.Id, AppGuid, AppControlGuid);

            if (data == null || data.Value == null)
            {
                data = new IssueWidgetData<string>();
                data.Value = "Default!";
                data.IssueId = issue.Id;

                GeminiContext.IssueWidgetStore.Save(issue.Id, AppGuid, AppControlGuid, data.Value);
            }

            result.Markup = new WidgetMarkup("views\\my-view.cshtml", data);
            result.Success = true;

            return result;
        }
示例#32
0
 public override WidgetResult Caption(IssueDto issue = null)
 {
     return new WidgetResult() { Success = true, Markup = new WidgetMarkup(AppName) };
 }