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));
        }
        public async Task <IActionResult> Put(string project, string name, string locale, string build, [FromBody] CreateIssueDto issueData)
        {
            Guid buildId;

            if (!Guid.TryParse(build, out buildId))
            {
                GenericRepository <Build> buildRepo = _unitOfWork.BuildRepository;
                buildId = (await buildRepo.GetAsync(b => b.BuildName.Equals(build))).FirstOrDefault().Id;
            }

            string currentUser = User.Identity.Name;

            if (!ModelState.IsValid || buildId == null || string.IsNullOrWhiteSpace(project) || string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(locale) || issueData == null)
            {
                return(BadRequest("Invalid or missing parameters"));
            }

            GenericRepository <Issue> issueRepo = _unitOfWork.IssueRepository;

            Issue existingIssue = IssueHelper.GetExistingIssue(issueRepo, project, name, locale, issueData);

            IssueDto createdIssue = new IssueDto();

            if (existingIssue != null)
            {
                existingIssue.X             = issueData.X;
                existingIssue.Y             = issueData.Y;
                existingIssue.Width         = issueData.Width;
                existingIssue.Height        = issueData.Height;
                existingIssue.IssueStatus   = issueData.Status;
                existingIssue.IssueSeverity = issueData.Severity;
                existingIssue.Value         = issueData.Text;

                await _unitOfWork.SaveAsync(currentUser);

                _mapper.Map <Issue, IssueDto>(existingIssue, createdIssue);
            }
            else
            {
                Issue newIssue = new Issue()
                {
                    ProjectName       = project,
                    ScreenName        = name,
                    ModifiedInBuildId = buildId,
                    LocaleCode        = locale,
                    IssueType         = issueData.Type,
                    IssueSeverity     = issueData.Severity,
                    Identifier        = issueData.Identifier,
                    Value             = issueData.Text,
                    X      = issueData.X,
                    Y      = issueData.Y,
                    Height = issueData.Height,
                    Width  = issueData.Width
                };

                issueRepo.Insert(newIssue);

                await _unitOfWork.SaveAsync(currentUser);

                _mapper.Map <Issue, IssueDto>(newIssue, createdIssue);
            }



            return(CreatedAtRoute(routeName: "GetIssueRoute", routeValues: new { project = project, id = createdIssue.Id }, value: createdIssue));
        }