public async Task AddReviewAsyncAllReviewersAddedTheirReviewsWhileRatingIsLowSetAcceptedStatusAndSendEmail()
        {
            var       reviewerId       = 1u;
            var       reviewMsg        = _faker.Rant.Review();
            var       rating           = _faker.Random.Byte(1, 3);
            IFormFile reviewFile       = null;
            var       scientificWorkId = 2u;

            var version = new ScientificWorkFile()
            {
                Id      = 3,
                Reviews = new List <Review>()
            };

            var reviewer = new User()
            {
                Id = reviewerId
            };

            var reviewerCount = 3;
            var reviewsCount  = 3;

            var authorEmail = _faker.Internet.Email();

            var ratingSum = 9;

            var scientificWork = new ScientificWork()
            {
                Status = StatusEnum.UnderReview
            };

            _scientificWorkRepositoryMock.Setup(x => x.GetEmailOfAuthorByWorkIdAsync(scientificWorkId)).ReturnsAsync(authorEmail);
            _scientificWorkRepositoryMock.Setup(x => x.GetWorkByIdAsync(scientificWorkId)).ReturnsAsync(scientificWork);
            _scientificWorkRepositoryMock.Setup(x => x.ChangeStatusAsync(It.Is <ScientificWork>(y => y.Status == StatusEnum.Accepted)));

            _scientificWorkFileRepositoryMock.Setup(x => x.GetNewestVersionWithReviewsAsync(scientificWorkId)).ReturnsAsync(version);
            _scientificWorkFileRepositoryMock.Setup(x => x.GetReviewsCountInNewestVersion(scientificWorkId)).Returns(reviewsCount);
            _scientificWorkFileRepositoryMock.Setup(x => x.GetRatingSumFromVersion(version.Id)).ReturnsAsync(ratingSum);
            _scientificWorkFileRepositoryMock.Setup(x => x.AddRatingAsync(It.Is <ScientificWorkFile>(y => y.Rating == 3)));

            _userStoreMock.Setup(x => x.FindByIdAsync(reviewerId.ToString(), CancellationToken.None)).ReturnsAsync(reviewer);

            _reviewRepositoryMock.Setup(x => x.AddReviewAsync(It.Is <Review>(y => y.Reviewer == reviewer &&
                                                                             y.Rating == rating &&
                                                                             y.VersionOfScientificWork == version)));

            _reviewersWorkRepositoryMock.Setup(x => x.GetReviewersCount(scientificWorkId)).Returns(reviewerCount);
            _reviewersWorkRepositoryMock.Setup(x => x.IsReviewerOfScientificWorkAsync(reviewerId, scientificWorkId)).ReturnsAsync(true);

            _emailSenderMock.Setup(x => x.SendToAuthorWorkGotAcceptedAsync(authorEmail, scientificWorkId));

            var err = await Record.ExceptionAsync(async
                                                      () => await _service.AddReviewAsync(reviewerId, reviewMsg, reviewFile, rating, scientificWorkId));

            err.Should().BeNull();

            _emailSenderMock.Verify(x => x.SendToAuthorWorkGotAcceptedAsync(authorEmail, scientificWorkId), Times.Once);
            _scientificWorkFileRepositoryMock.Verify(x => x.AddRatingAsync(It.Is <ScientificWorkFile>(y => y.Rating == 3)), Times.Once);
            _scientificWorkRepositoryMock.Verify(x => x.ChangeStatusAsync(It.Is <ScientificWork>(y => y.Status == StatusEnum.Accepted)), Times.Once);
        }
示例#2
0
        public async Task <uint> AddBasicInfoAsync(uint authorId, string title, string description, string authors,
                                                   string specialization)
        {
            var user = await _userManager.FindByIdAsync(authorId.ToString());

            if (user.NormalizedUserName.Split(":")[0] != "PARTICIPANT")
            {
                throw new AuthenticationException();
            }

            var scientificWork = await _scientificWorkRepository.GetByAuthorIdAsync(authorId);

            if (!(scientificWork is null))
            {
                throw new InvalidOperationException();
            }

            scientificWork = new ScientificWork()
            {
                Name           = title,
                Description    = description,
                MainAuthor     = user,
                OtherAuthors   = authors,
                CreationDate   = DateTime.Now,
                Status         = StatusEnum.WaitingForDrawOfReviewers,
                Specialization = specialization
            };

            await _scientificWorkRepository.AddAsync(scientificWork);

            return(await _scientificWorkRepository.GetIdOfWorkByAuthorIdAsync(authorId));
        }
示例#3
0
        //public Guid UserId { get; set; }

        public void GetScientificWorkFromModel(ScientificWork scientificWork)
        {
            scientificWork.Name    = Name;
            scientificWork.Content = Content;
            scientificWork.LevelId = LevelId;
            scientificWork.Time    = Time;
            //scientificWork.UserId = UserId;
        }
示例#4
0
        public async Task GetWorkByIdAsyncParticipantSeeOnlyWorkInformationOnlyWhenWorkIsAccepted()
        {
            var authorId         = 1u;
            var userId           = 2u;
            var scientificWorkId = 1u;

            var scientificWork = new ScientificWork()
            {
                Id           = scientificWorkId,
                Name         = _faker.Commerce.ProductName(),
                Description  = _faker.Commerce.ProductDescription(),
                CreationDate = DateTime.UtcNow,
                OtherAuthors = string.Join(", ", Enumerable.Range(1, 3).Select(_ => _faker.Person.FullName)),
                Status       = StatusEnum.Accepted,
                MainAuthor   = new User()
                {
                    Id         = authorId,
                    Name       = _faker.Person.FirstName,
                    Surname    = _faker.Person.LastName,
                    Photo      = null,
                    Degree     = _faker.Name.JobTitle(),
                    University = _faker.Company.CompanyName()
                },
                Versions = Enumerable.Range(0, 2)
                           .Select(x => new ScientificWorkFile()
                {
                    Id      = (uint)x,
                    Version = (byte)x,
                    DateAdd = DateTime.UtcNow.AddDays(x)
                })
            };

            ScientificWorkWithReviewDto returnedDto = null;

            var expectedDto = new ScientificWorkWithReviewDto()
            {
                Status         = scientificWork.Status.ToString(),
                Versions       = null,
                Mode           = nameof(UserTypeEnum.Participant),
                MainAuthor     = _mapper.Map <UserDto>(scientificWork.MainAuthor),
                ScientificWork = _mapper.Map <ScientificWorkWithOtherAuthorsDto>(scientificWork)
            };

            _scientificWorkRepositoryMock.Setup(x => x.GetWorkByIdAsync(scientificWorkId)).ReturnsAsync(scientificWork);
            _reviewerScientificWorkRepositoryMock.Setup(x => x.IsReviewerAsync(scientificWorkId, userId)).ReturnsAsync(false);

            var err = await Record.ExceptionAsync(async
                                                      () => returnedDto = await _service.GetWorkByIdAsync(userId, scientificWorkId));

            err.Should().BeNull();

            returnedDto.Should().NotBeNull();
            returnedDto.Should().BeEquivalentTo(expectedDto);

            _scientificWorkFileRepositoryMock.Verify(x => x.GetVersionsWithReviews(It.IsAny <uint>()), Times.Never);
        }
示例#5
0
        //public UserViewModel User { get; set; }

        private List <LecturerViewModel> GetLecturer(ScientificWork scientificWork)
        {
            var lecturers = new List <LecturerViewModel>();

            foreach (var lecturerInScientificWork in scientificWork.LecturerInScientificWorks)
            {
                lecturers.Add(new LecturerViewModel(lecturerInScientificWork.Lecturer));
            }
            return(lecturers);
        }
示例#6
0
        public async Task AddVersionAsyncAddNextVersionsSuccess()
        {
            uint userId = 1;
            var  file   = new FormFile(null, _faker.Random.Long(), _faker.Random.Long(), _faker.Internet.UserName(), _faker.System.FileName("pdf"));

            var randomNameOfFile = _faker.System.FileName("pdf");

            byte versionNumber = 1;

            var scientificWork = new ScientificWork()
            {
                Id          = 1,
                Name        = _faker.Commerce.ProductName(),
                Description = _faker.Commerce.ProductDescription(),
                Status      = StatusEnum.UnderReview
            };

            var newVersion = new ScientificWorkFile()
            {
                Version        = (byte)(versionNumber + 1),
                FileName       = randomNameOfFile,
                ScientificWork = scientificWork
            };

            var reviewerEmails = Enumerable.Range(1, 3).Select(_ => _faker.Internet.Email());

            _scientificWorkRepositoryMock.Setup(x => x.GetNumberOfVersionsByAuthorIdAsync(userId)).ReturnsAsync(versionNumber);
            _scientificWorkRepositoryMock.Setup(x => x.GetByAuthorIdAsync(userId)).ReturnsAsync(scientificWork);
            _scientificWorkRepositoryMock.Setup(x => x.ChangeStatusAsync(It.Is <ScientificWork>(y => y.Id == scientificWork.Id && y.Status == StatusEnum.UnderReview)));

            _reviewerScientificWorkRepositoryMock.Setup(x => x.GetEmailsOfReviewersByWorkIdAsync(scientificWork.Id)).ReturnsAsync(reviewerEmails);

            _scientificWorkFileRepositoryMock.Setup(x => x.AddAsync(It.Is <ScientificWorkFile>(y => y.Version == newVersion.Version &&
                                                                                               y.FileName == newVersion.FileName &&
                                                                                               y.ScientificWork == newVersion.ScientificWork)));

            _fileManagerMock.Setup(x => x.SaveFileAsync(file)).ReturnsAsync(randomNameOfFile);
            _emailSenderMock.Setup(x => x.SendAddedNewVersionEmailAsync(It.IsIn(reviewerEmails), scientificWork.Id));

            var err = await Record.ExceptionAsync(async
                                                      () => await _service.AddVersionAsync(userId, file));

            err.Should().BeNull();

            _scientificWorkRepositoryMock.Verify(x => x.ChangeStatusAsync(It.Is <ScientificWork>(x => x.Status == StatusEnum.UnderReview)), Times.Once);
            _scientificWorkRepositoryMock.Verify(x => x.GetNumberOfVersionsByAuthorIdAsync(userId), Times.Once);
            _scientificWorkFileRepositoryMock.Verify(x => x.AddAsync(It.Is <ScientificWorkFile>(y => y.Version == newVersion.Version &&
                                                                                                y.FileName == newVersion.FileName &&
                                                                                                y.ScientificWork == newVersion.ScientificWork)), Times.Once);

            _emailSenderMock.Verify(x => x.SendAddedNewVersionEmailAsync(It.IsAny <string>(), scientificWork.Id), Times.Exactly(reviewerEmails.Count()));
        }
示例#7
0
 public ScientificWorkViewModel(ScientificWork scientificWork) : this()
 {
     if (scientificWork != null)
     {
         Id        = scientificWork.Id;
         Name      = scientificWork.Name;
         Content   = scientificWork.Content;
         Time      = scientificWork.Time;
         Level     = new LevelViewModel(scientificWork.Level);
         Lecturers = GetLecturer(scientificWork);
         //User = new UserViewModel(scientificWork.User);
         //Lecturer = new LecturerViewModel;
     }
 }
示例#8
0
        public async Task GetWorkByIdAsyncAddPhotoOfMainAuthorWhenItsAvalaible()
        {
            var authorId         = 1u;
            var userId           = 2u;
            var scientificWorkId = 1u;

            var randomBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(_faker.Random.String(7)));

            var author = new User()
            {
                Id         = authorId,
                Name       = _faker.Person.FirstName,
                Surname    = _faker.Person.LastName,
                Photo      = _faker.System.FileName("png"),
                Degree     = _faker.Name.JobTitle(),
                University = _faker.Company.CompanyName()
            };

            var scientificWork = new ScientificWork()
            {
                Id           = scientificWorkId,
                Name         = _faker.Commerce.ProductName(),
                Description  = _faker.Commerce.ProductDescription(),
                CreationDate = DateTime.UtcNow,
                Status       = StatusEnum.Accepted,
                MainAuthor   = author,
                Versions     = Enumerable.Range(0, 2)
                               .Select(x => new ScientificWorkFile()
                {
                    Id      = (uint)x,
                    Version = (byte)x,
                    DateAdd = DateTime.UtcNow.AddDays(x)
                })
            };

            _scientificWorkRepositoryMock.Setup(x => x.GetWorkByIdAsync(scientificWorkId)).ReturnsAsync(scientificWork);
            _reviewerScientificWorkRepositoryMock.Setup(x => x.IsReviewerAsync(scientificWorkId, userId)).ReturnsAsync(false);

            _fileManagerMock.Setup(x => x.GetBase64FileAsync(author.Photo)).ReturnsAsync(randomBase64);

            var err = await Record.ExceptionAsync(async
                                                      () => await _service.GetWorkByIdAsync(userId, scientificWorkId));

            err.Should().BeNull();

            _fileManagerMock.Verify(x => x.GetBase64FileAsync(author.Photo), Times.Once);
        }
示例#9
0
        public async Task AddVersionAsyncAddFirstSuccess()
        {
            var userId = 1u;
            var file   = new FormFile(null, _faker.Random.Long(), _faker.Random.Long(), _faker.Internet.UserName(), _faker.System.FileName("pdf"));

            var randomNameOfFile = _faker.System.FileName("pdf");

            var scientificWork = new ScientificWork()
            {
                Id          = 1,
                Name        = _faker.Commerce.ProductName(),
                Description = _faker.Commerce.ProductDescription(),
                Status      = StatusEnum.WaitingForDrawOfReviewers
            };

            var newVersion = new ScientificWorkFile()
            {
                Version        = 1,
                FileName       = randomNameOfFile,
                ScientificWork = scientificWork
            };

            _scientificWorkRepositoryMock.Setup(x => x.GetByAuthorIdAsync(userId)).ReturnsAsync(scientificWork);
            _fileManagerMock.Setup(x => x.SaveFileAsync(file)).ReturnsAsync(randomNameOfFile);
            _scientificWorkFileRepositoryMock.Setup(x => x.AddAsync(It.Is <ScientificWorkFile>(y => y.Version == newVersion.Version &&
                                                                                               y.FileName == newVersion.FileName &&
                                                                                               y.ScientificWork == newVersion.ScientificWork)));

            var err = await Record.ExceptionAsync(async
                                                      () => await _service.AddVersionAsync(userId, file, true));

            err.Should().BeNull();

            _scientificWorkRepositoryMock.Verify(x => x.ChangeStatusAsync(It.IsAny <ScientificWork>()), Times.Never);
            _scientificWorkRepositoryMock.Verify(x => x.GetNumberOfVersionsByAuthorIdAsync(It.IsAny <uint>()), Times.Never);
            _emailSenderMock.Verify(x => x.SendAddedNewVersionEmailAsync(It.IsAny <string>(), It.IsAny <uint>()), Times.Never);
            _scientificWorkFileRepositoryMock.Verify(x => x.AddAsync(It.Is <ScientificWorkFile>(y => y.Version == newVersion.Version &&
                                                                                                y.FileName == newVersion.FileName &&
                                                                                                y.ScientificWork == newVersion.ScientificWork)), Times.Once);
        }
示例#10
0
        public async Task GetInformationFroMyProfileAsyncSuccessReturnDtoWithScientificWork()
        {
            var userId = 1u;

            var user = new User()
            {
                Id             = userId,
                Name           = _faker.Person.FirstName,
                Surname        = _faker.Person.LastName,
                Email          = _faker.Person.Email,
                Degree         = _faker.Name.JobTitle(),
                University     = _faker.Company.CompanyName(),
                Specialization = _faker.Commerce.Categories(1)[0],
                UserName       = UserHelper.GetUserName(UserTypeEnum.Participant, _faker.Person.Email)
            };

            var scientificWork = new ScientificWork()
            {
                Id = 1u
            };

            var expectedDto = _mapper.Map <MyProfileUserDto>(user);

            expectedDto.WorkId = scientificWork.Id;

            MyProfileUserDto returnedDto = null;

            _userManagerMock.Setup(x => x.FindByIdAsync(userId.ToString())).ReturnsAsync(user);
            _scientificWorkRepositoryMock.Setup(x => x.GetByAuthorIdAsync(userId)).ReturnsAsync(scientificWork);

            var err = await Record.ExceptionAsync(async() => returnedDto = await _userService.GetInformationForMyProfileAsync(userId.ToString()));

            err.Should().BeNull();

            returnedDto.Should().NotBeNull();
            returnedDto.Should().BeEquivalentTo(expectedDto);

            _userManagerMock.Verify(x => x.FindByIdAsync(userId.ToString()), Times.Once);
            _scientificWorkRepositoryMock.Verify(x => x.GetByAuthorIdAsync(userId), Times.Once);
        }
示例#11
0
        public async Task GetWorkByIdAsyncThrowAuthenticationExceptionWhenUserIsParticipantAndWorkIsNotAccepted()
        {
            var authorId         = 1u;
            var userId           = 2u;
            var scientificWorkId = 1u;

            var author = new User()
            {
                Id         = authorId,
                Name       = _faker.Person.FirstName,
                Surname    = _faker.Person.LastName,
                Photo      = null,
                Degree     = _faker.Name.JobTitle(),
                University = _faker.Company.CompanyName()
            };

            var scientificWork = new ScientificWork()
            {
                Id           = scientificWorkId,
                Name         = _faker.Commerce.ProductName(),
                Description  = _faker.Commerce.ProductDescription(),
                CreationDate = DateTime.UtcNow,
                OtherAuthors = string.Join(", ", Enumerable.Range(1, 3).Select(_ => _faker.Person.FullName)),
                Status       = StatusEnum.UnderReview,
                MainAuthor   = author,
            };

            ScientificWorkWithReviewDto returnedDto = null;

            _scientificWorkRepositoryMock.Setup(x => x.GetWorkByIdAsync(scientificWorkId)).ReturnsAsync(scientificWork);
            _reviewerScientificWorkRepositoryMock.Setup(x => x.IsReviewerAsync(scientificWorkId, userId)).ReturnsAsync(false);

            var err = await Record.ExceptionAsync(async
                                                      () => returnedDto = await _service.GetWorkByIdAsync(userId, scientificWorkId));

            err.Should().BeOfType <AuthenticationException>();
            returnedDto.Should().BeNull();
        }
示例#12
0
        public async Task GetUserInfoForHeaderAsyncReturnDtoWithScientificWorkId()
        {
            var userId = 1u;

            var user = new User()
            {
                Id       = userId,
                Name     = _faker.Person.FirstName,
                Surname  = _faker.Person.LastName,
                UserName = UserHelper.GetUserName(UserTypeEnum.Participant, _faker.Person.Email)
            };

            var scientificWork = new ScientificWork()
            {
                Id = 1
            };

            var expectedDto = _mapper.Map <HeaderUserInfoDto>(user);

            expectedDto.ScientificWorkId = scientificWork.Id;

            HeaderUserInfoDto returnedDto = null;

            _userManagerMock.Setup(x => x.FindByIdAsync(userId.ToString())).ReturnsAsync(user);
            _scientificWorkRepositoryMock.Setup(x => x.GetByAuthorIdAsync(userId)).ReturnsAsync(scientificWork);

            var err = await Record.ExceptionAsync(async() => returnedDto = await _userService.GetUserInfoForHeaderAsync(userId.ToString()));

            err.Should().BeNull();

            returnedDto.Should().NotBeNull();
            returnedDto.Should().BeEquivalentTo(expectedDto);

            _userManagerMock.Verify(x => x.FindByIdAsync(userId.ToString()), Times.Once);
            _scientificWorkRepositoryMock.Verify(x => x.GetByAuthorIdAsync(userId), Times.Once);
        }
示例#13
0
        public async void AddWork(ScientificWork scientificWork)
        {
            await _dbContext.AddAsync(scientificWork);

            await _dbContext.SaveChangesAsync();
        }
示例#14
0
        public async Task AddReviewAsyncAllReviewersAddedReviewSetAcceptedStatus()
        {
            var reviewerId       = 1u;
            var reviewMsg        = "This is my review!";
            var reviewFile       = new FormFile(null, 42534, 2345, "NameHaHa", "FileNameHueHue");
            var rating           = (byte)3;
            var scientificWorkId = 2u;

            var version = new ScientificWorkFile()
            {
                Id      = 3,
                Reviews = new List <Review>()
            };

            var reviewer = new User()
            {
                Id = reviewerId
            };

            var randomFileName = "afertgh35he.png";

            var reviewerCount = 3;
            var reviewsCount  = 3;

            var authorEmail = "*****@*****.**";

            var ratingSum = 9;

            var scientificWork = new ScientificWork()
            {
                Status = StatusEnum.UnderReview
            };

            _scientificWorkRepositoryMock.Reset();
            _scientificWorkRepositoryMock.Setup(x => x.IsReviewerOfScientificWorkAsync(reviewerId, scientificWorkId)).ReturnsAsync(true);
            _scientificWorkRepositoryMock.Setup(x => x.GetEmailOfAuthorByWorkIdAsync(scientificWorkId)).ReturnsAsync(authorEmail);
            _scientificWorkRepositoryMock.Setup(x => x.GetWorkByIdAsync(scientificWorkId)).ReturnsAsync(scientificWork);
            _scientificWorkRepositoryMock.Setup(x => x.ChangeStatusAsync(It.Is <ScientificWork>(y => y.Status == StatusEnum.Accepted)));

            _scientificWorkFileRepositoryMock.Reset();
            _scientificWorkFileRepositoryMock.Setup(x => x.GetNewestVersionWithReviewsAsync(scientificWorkId)).ReturnsAsync(version);
            _scientificWorkFileRepositoryMock.Setup(x => x.GetReviewsCountInNewestVersion(scientificWorkId)).Returns(reviewsCount);
            _scientificWorkFileRepositoryMock.Setup(x => x.GetRatingSumFromVersion(version.Id)).ReturnsAsync(ratingSum);
            _scientificWorkFileRepositoryMock.Setup(x => x.AddRatingAsync(It.Is <ScientificWorkFile>(y => y.Rating == 3)));

            _userStoreMock.Reset();
            _userStoreMock.Setup(x => x.FindByIdAsync(reviewerId.ToString(), CancellationToken.None)).ReturnsAsync(reviewer);

            _fileManagerMock.Reset();
            _fileManagerMock.Setup(x => x.SaveFileAsync(reviewFile)).ReturnsAsync(randomFileName);

            _reviewRepositoryMock.Reset();
            _reviewRepositoryMock.Setup(x => x.AddReviewAsync(It.Is <Review>(y => y.Reviewer == reviewer &&
                                                                             y.Rating == rating && y.File == randomFileName &&
                                                                             y.VersionOfScientificWork == version)));

            _reviewersWorkRepositoryMock.Reset();
            _reviewersWorkRepositoryMock.Setup(x => x.GetReviewersCount(scientificWorkId)).Returns(reviewerCount);

            _emailSenderMock.Reset();
            _emailSenderMock.Setup(x => x.SendToAuthorWorkGotAcceptedAsync(authorEmail, scientificWorkId));

            var err = await Record.ExceptionAsync(async
                                                      () => await _service.AddReviewAsync(reviewerId, reviewMsg, reviewFile, rating, scientificWorkId));

            err.Should().BeNull();

            _scientificWorkRepositoryMock.Verify(x => x.IsReviewerOfScientificWorkAsync(reviewerId, scientificWorkId), Times.Once);
            _scientificWorkRepositoryMock.Verify(x => x.GetEmailOfAuthorByWorkIdAsync(scientificWorkId), Times.Once);
            _scientificWorkRepositoryMock.Verify(x => x.GetWorkByIdAsync(scientificWorkId), Times.Once);
            _scientificWorkRepositoryMock.Verify(x => x.ChangeStatusAsync(It.Is <ScientificWork>(y => y.Status == StatusEnum.Accepted)), Times.Once);

            _scientificWorkFileRepositoryMock.Verify(x => x.GetNewestVersionWithReviewsAsync(scientificWorkId), Times.Once);
            _scientificWorkFileRepositoryMock.Verify(x => x.GetReviewsCountInNewestVersion(scientificWorkId), Times.Once);
            _scientificWorkFileRepositoryMock.Verify(x => x.GetRatingSumFromVersion(version.Id), Times.Once);
            _scientificWorkFileRepositoryMock.Verify(x => x.AddRatingAsync(It.Is <ScientificWorkFile>(y => y.Rating == 3)), Times.Once);

            _userStoreMock.Verify(x => x.FindByIdAsync(reviewerId.ToString(), CancellationToken.None), Times.Once);

            _fileManagerMock.Verify(x => x.SaveFileAsync(reviewFile), Times.Once);

            _reviewRepositoryMock.Verify(x => x.AddReviewAsync(It.Is <Review>(y => y.Reviewer == reviewer &&
                                                                              y.Rating == rating && y.File == randomFileName &&
                                                                              y.VersionOfScientificWork == version)), Times.Once);

            _reviewersWorkRepositoryMock.Verify(x => x.GetReviewersCount(scientificWorkId), Times.Once);

            _emailSenderMock.Verify(x => x.SendToAuthorWorkGotRejectedAsync(It.IsAny <string>(), It.IsAny <uint>()), Times.Never);
            _emailSenderMock.Verify(x => x.SendNewVersionEnabledEmailAsync(It.IsAny <string>(), It.IsAny <uint>()), Times.Never);
            _emailSenderMock.Verify(x => x.SendToAuthorWorkGotAcceptedAsync(authorEmail, scientificWorkId), Times.Once);
            _emailSenderMock.Verify(x => x.SendReceiveReviewEmailAsync(It.IsAny <string>(), It.IsAny <uint>()), Times.Never);
        }
示例#15
0
        public async Task GetWorkByIdAsyncAuthorSeeEverything()
        {
            var userId      = 1u;
            var reviewer1Id = 2u;
            var reviewer2Id = 3u;

            var scientificWorkId = 1u;
            var versionsId       = 0u;
            var reviewId         = 1u;
            var answerId         = 1u;

            var author = new User()
            {
                Id         = userId,
                Name       = _faker.Person.FirstName,
                Surname    = _faker.Person.LastName,
                Photo      = null,
                Degree     = _faker.Name.JobTitle(),
                University = _faker.Company.CompanyName()
            };

            var reviewer1 = new User()
            {
                Id = reviewer1Id
            };
            var reviewer2 = new User()
            {
                Id = reviewer2Id
            };

            var scientificWork = new ScientificWork()
            {
                Id           = scientificWorkId,
                Name         = _faker.Commerce.ProductName(),
                Description  = _faker.Commerce.ProductDescription(),
                CreationDate = DateTime.UtcNow,
                OtherAuthors = string.Join(", ", Enumerable.Range(1, 3).Select(_ => _faker.Person.FullName)),
                Status       = StatusEnum.Accepted,
                MainAuthor   = author,
                Versions     = new List <ScientificWorkFile>()
                {
                    new ScientificWorkFile()
                    {
                        Id      = ++versionsId,
                        Version = (byte)versionsId,
                        DateAdd = DateTime.UtcNow.AddDays(versionsId),
                        Reviews = new List <Review>()
                        {
                            new Review()
                            {
                                Id         = reviewId++,
                                DateReview = DateTime.UtcNow,
                                Comment    = _faker.Rant.Review(),
                                Rating     = _faker.Random.Byte(1, 3),
                                Reviewer   = reviewer1
                            },
                            new Review()
                            {
                                Id         = reviewId++,
                                DateReview = DateTime.UtcNow,
                                File       = _faker.System.FileName("pdf"),
                                Rating     = _faker.Random.Byte(1, 3),
                                Reviewer   = reviewer2,
                                Answer     = new Answer()
                                {
                                    Id         = answerId++,
                                    Comment    = _faker.Lorem.Sentence(5),
                                    AnswerDate = DateTime.UtcNow,
                                    User       = author
                                }
                            }
                        }
                    },
                    new ScientificWorkFile()
                    {
                        Id      = ++versionsId,
                        Version = (byte)versionsId,
                        DateAdd = DateTime.UtcNow.AddDays(versionsId),
                        Reviews = new List <Review>()
                        {
                            new Review()
                            {
                                Id         = reviewId++,
                                DateReview = DateTime.UtcNow,
                                File       = _faker.Rant.Review(),
                                Rating     = _faker.Random.Byte(1, 3),
                                Reviewer   = reviewer1,
                                Answer     = new Answer()
                                {
                                    Id         = answerId++,
                                    Comment    = _faker.Lorem.Sentence(5),
                                    AnswerDate = DateTime.UtcNow,
                                    User       = author
                                }
                            },
                            new Review()
                            {
                                Id         = reviewId++,
                                DateReview = DateTime.UtcNow,
                                Comment    = _faker.System.FileName("pdf"),
                                Rating     = _faker.Random.Byte(1, 3),
                                Reviewer   = reviewer2
                            }
                        }
                    },
                }
            };

            ScientificWorkWithReviewDto returnedDto = null;

            var expectedDto = new ScientificWorkWithReviewDto()
            {
                Status         = scientificWork.Status.ToString(),
                Mode           = "Author",
                MainAuthor     = _mapper.Map <UserDto>(author),
                ScientificWork = _mapper.Map <ScientificWorkWithOtherAuthorsDto>(scientificWork),
                Versions       = _mapper.Map <List <VersionDto> >(scientificWork.Versions)
            };

            _scientificWorkRepositoryMock.Setup(x => x.GetWorkByIdAsync(scientificWorkId)).ReturnsAsync(scientificWork);
            _scientificWorkFileRepositoryMock.Setup(x => x.GetVersionsWithReviews(scientificWorkId)).ReturnsAsync(scientificWork.Versions);

            var err = await Record.ExceptionAsync(async
                                                      () => returnedDto = await _service.GetWorkByIdAsync(userId, scientificWorkId));

            err.Should().BeNull();

            returnedDto.Should().NotBeNull();
            returnedDto.Should().BeEquivalentTo(expectedDto);

            _scientificWorkFileRepositoryMock.Verify(x => x.GetVersionsWithReviews(scientificWorkId), Times.Once);
        }
示例#16
0
 public async Task ChangeStatusAsync(ScientificWork scientificWork)
 {
     _context.ScientificWorks.Update(scientificWork);
     await _context.SaveChangesAsync();
 }
示例#17
0
        public async Task AddAsync(ScientificWork scienceWork)
        {
            await _context.ScientificWorks.AddAsync(scienceWork);

            await _context.SaveChangesAsync();
        }
        public ScientificWorkProfileTests()
        {
            var configuration = new MapperConfiguration(cfg
                                                        => cfg.AddProfile <ScientificWorkProfile>());

            _mapper = new Mapper(configuration);

            var versionsId  = 1u;
            var reviewersId = 1u;
            var reviewId    = 1u;
            var answerId    = 1u;
            var users       = new Faker <User>()
                              .RuleFor(o => o.Id, f => reviewersId++)
                              .RuleFor(o => o.Name, f => f.Person.FirstName)
                              .RuleFor(o => o.Surname, f => f.Person.LastName)
                              .Generate(3);

            var versions = new List <ScientificWorkFile>()
            {
                new ScientificWorkFile()
                {
                    Id      = ++versionsId,
                    Version = (byte)versionsId,
                    DateAdd = DateTime.UtcNow.AddDays(versionsId),
                    Reviews = new List <Review>()
                    {
                        new Review()
                        {
                            Id         = reviewId++,
                            DateReview = DateTime.UtcNow,
                            Comment    = _faker.Rant.Review(),
                            Rating     = _faker.Random.Byte(1, 3),
                            Reviewer   = users[1]
                        },
                        new Review()
                        {
                            Id         = reviewId++,
                            DateReview = DateTime.UtcNow,
                            File       = _faker.System.FileName("pdf"),
                            Rating     = _faker.Random.Byte(1, 3),
                            Reviewer   = users[2],
                            Answer     = new Answer()
                            {
                                Id         = answerId++,
                                Comment    = _faker.Lorem.Sentence(5),
                                AnswerDate = DateTime.UtcNow,
                                User       = users[0]
                            }
                        }
                    }
                },
                new ScientificWorkFile()
                {
                    Id      = ++versionsId,
                    Version = (byte)versionsId,
                    DateAdd = DateTime.UtcNow.AddDays(versionsId),
                    Reviews = new List <Review>()
                    {
                        new Review()
                        {
                            Id         = reviewId++,
                            DateReview = DateTime.UtcNow,
                            File       = _faker.System.FileName("pdf"),
                            Rating     = _faker.Random.Byte(1, 3),
                            Reviewer   = users[1],
                            Answer     = new Answer()
                            {
                                Id         = answerId++,
                                Comment    = _faker.Lorem.Sentence(5),
                                AnswerDate = DateTime.UtcNow,
                                User       = users[0]
                            }
                        },
                        new Review()
                        {
                            Id         = reviewId++,
                            DateReview = DateTime.UtcNow,
                            Comment    = _faker.Rant.Review(),
                            Rating     = _faker.Random.Byte(1, 3),
                            Reviewer   = users[2]
                        }
                    }
                },
            };

            _scientificWork = new ScientificWork()
            {
                Id           = 1u,
                CreationDate = _faker.Date.Recent(),
                Description  = _faker.Commerce.ProductDescription(),
                MainAuthor   = new User()
                {
                    Name = _faker.Person.FirstName, Surname = _faker.Person.LastName
                },
                Name           = _faker.Commerce.ProductName(),
                Specialization = _faker.Commerce.Department(1),
                Status         = _faker.Random.Enum <StatusEnum>(),
                OtherAuthors   = string.Join(", ", Enumerable.Range(0, 3).Select(_ => _faker.Person.FullName)),
                Versions       = versions
            };
        }