コード例 #1
0
        public void UpdateMergeBlacklistTest()
        {
            var entryA = new MergeBlacklistEntry
            {
                Id        = "A",
                ProjectId = ProjId,
                UserId    = UserId,
                WordIds   = new List <string> {
                    "1", "2", "3"
                }
            };
            var entryB = new MergeBlacklistEntry
            {
                Id        = "B",
                ProjectId = ProjId,
                UserId    = UserId,
                WordIds   = new List <string> {
                    "1", "4"
                }
            };

            _ = _mergeBlacklistRepo.Create(entryA);
            _ = _mergeBlacklistRepo.Create(entryB);

            var oldBlacklist = _mergeBlacklistRepo.GetAll(ProjId).Result;

            Assert.That(oldBlacklist, Has.Count.EqualTo(2));

            // Make sure all wordIds are in the frontier EXCEPT 1.
            var frontier = new List <Word>
            {
                new Word {
                    Id = "2", ProjectId = ProjId
                },
                new Word {
                    Id = "3", ProjectId = ProjId
                },
                new Word {
                    Id = "4", ProjectId = ProjId
                }
            };

            _ = _wordRepo.AddFrontier(frontier).Result;

            // All entries affected.
            var updatedEntriesCount = _mergeService.UpdateMergeBlacklist(ProjId).Result;

            Assert.That(updatedEntriesCount, Is.EqualTo(2));

            // The only blacklistEntry with at least two ids in the frontier is A.
            var newBlacklist = _mergeBlacklistRepo.GetAll(ProjId).Result;

            Assert.That(newBlacklist, Has.Count.EqualTo(1));
            Assert.AreEqual(newBlacklist.First().WordIds, new List <string> {
                "2", "3"
            });
        }
コード例 #2
0
        public async Task <IActionResult> PostFrontier(string projectId, [FromBody] Word word)
        {
#if DEBUG
            if (!_permissionService.HasProjectPermission(Permission.WordEntry, HttpContext))
            {
                return(new ForbidResult());
            }

            // Ensure project exists
            var project = _projectService.GetProject(projectId);
            if (project == null)
            {
                return(new NotFoundObjectResult(projectId));
            }

            word.ProjectId = projectId;
            await _repo.AddFrontier(word);

            return(new OkObjectResult(word.Id));
#else
            return(new NotFoundResult());
#endif
        }