Example #1
0
        public async Task GetByIdAsync_ReturnsClubAnnualReportDTO_Admin()
        {
            // Arrange
            ClubAnnualReport report = new ClubAnnualReport();

            _repositoryWrapper
            .Setup(x => x.ClubAnnualReports.GetFirstOrDefaultAsync(It.IsAny <Expression <Func <ClubAnnualReport, bool> > >(),
                                                                   It.IsAny <Func <IQueryable <ClubAnnualReport>,
                                                                                   IIncludableQueryable <ClubAnnualReport, object> > >())).ReturnsAsync(report);
            _clubAccessService
            .Setup(x => x.HasAccessAsync(It.IsAny <User>(), It.IsAny <int>())).ReturnsAsync(false);
            _mapper
            .Setup(x => x.Map <ClubAnnualReport, ClubAnnualReportDTO>(report)).Returns(new ClubAnnualReportDTO());
            _userManager.Setup(x => x.GetRolesAsync(It.IsAny <User>())).ReturnsAsync(new List <string>()
            {
                Roles.Admin
            });

            // Act
            var result = await _service.GetByIdAsync(It.IsAny <User>(), It.IsAny <int>());

            // Assert
            Assert.NotNull(result);
            Assert.IsInstanceOf <ClubAnnualReportDTO>(result);
        }
Example #2
0
        public void GetByIdAsync_UnauthorizedAccessException()
        {
            // Arrange
            ClubAnnualReport report = new ClubAnnualReport();

            _repositoryWrapper
            .Setup(x => x.ClubAnnualReports.GetFirstOrDefaultAsync(It.IsAny <Expression <Func <ClubAnnualReport, bool> > >(),
                                                                   It.IsAny <Func <IQueryable <ClubAnnualReport>,
                                                                                   IIncludableQueryable <ClubAnnualReport, object> > >())).ReturnsAsync(report);
            _clubAccessService
            .Setup(x => x.HasAccessAsync(It.IsAny <User>(), It.IsAny <int>())).ReturnsAsync(false);
            _mapper
            .Setup(x => x.Map <ClubAnnualReport, ClubAnnualReportDTO>(report)).Returns(new ClubAnnualReportDTO());
            _userManager.Setup(x => x.GetRolesAsync(It.IsAny <User>())).ReturnsAsync(new List <string>());

            // Act & Assert
            Assert.ThrowsAsync <UnauthorizedAccessException>(() =>
                                                             _service.GetByIdAsync(It.IsAny <User>(), It.IsAny <int>()));
        }