public async Task AssignReviewersToScientificWorkAsyncWhenThereIsNotEnoughReviewersInCategorySendEmailAndSetStatusToRejected(int reviewersCount)
        {
            var scientificWorksCount = 7;
            var category             = "Biology";

            var userId           = 1u;
            var scientificWorkId = 1u;

            var fakeUser = new Faker <User>().Rules((f, o) =>
            {
                o.Id              = userId++;
                o.Email           = f.Internet.Email();
                o.NormalizedEmail = o.Email.ToUpper();
            });

            var scientificWorks = new Faker <ScientificWork>().Rules((f, o) =>
            {
                o.Id         = scientificWorkId++;
                o.MainAuthor = fakeUser.Generate();
            }).Generate(scientificWorksCount);

            var reviewers = fakeUser.Generate(reviewersCount);

            _scientificWorkRepositoryMock.Setup(x => x.GetAllBySpecializationAsync(category)).ReturnsAsync(scientificWorks);
            _scientificWorkRepositoryMock.Setup(x => x.ChangeStatusAsync(It.Is <ScientificWork>(x => x.Status == StatusEnum.Rejected)));

            _userRepositoryMock.Setup(x => x.GetAllBySpecializationAsync(category)).ReturnsAsync(reviewers);
            _userRepositoryMock.Setup(x => x.GetEmailById(It.IsIn(reviewers.Select(x => x.Id)))).Returns((uint x) => reviewers.Single(y => y.Id == x).Email);
            _userRepositoryMock.Setup(x => x.GetEmailById(It.IsIn(scientificWorks.Select(x => x.Id)))).Returns((uint x) => scientificWorks.Single(y => y.MainAuthor.Id == x).MainAuthor.Email);

            _emailSenderMock.Setup(x => x.SendDoNotGetAssignToAnyWork(It.IsAny <string>()));
            _emailSenderMock.Setup(x => x.SendWorkDidNotGetReviewers(It.IsAny <string>()));

            var err = await Record.ExceptionAsync(async
                                                      () => await _managementService.AssignReviewersToScientificWorkAsync());

            err.Should().BeNull();

            _emailSenderMock.Verify(x => x.SendDoNotGetAssignToAnyWork(It.IsIn(reviewers.Select(x => x.Email))), Times.Exactly(reviewersCount));
            _emailSenderMock.Verify(x => x.SendWorkDidNotGetReviewers(It.IsIn(scientificWorks.Select(x => x.MainAuthor.Email))), Times.Exactly(scientificWorksCount));
            _emailSenderMock.VerifyNoOtherCalls();

            _scientificWorkRepositoryMock.Verify(x => x.ChangeStatusAsync(It.Is <ScientificWork>(x => x.Status == StatusEnum.Rejected)), Times.Exactly(scientificWorksCount));
        }
Пример #2
0
        public async Task Execute(IJobExecutionContext context)
        {
            // TODO: Block reviewer registration

            await _fooService.AssignReviewersToScientificWorkAsync();
        }