Ejemplo n.º 1
0
        public async Task <IActionResult> ChangeApproveStatus(int memberId)
        {
            var member = await _cityParticipantsService.ToggleApproveStatusAsync(memberId);

            _logger.LogInformation($"Status of member with ID {{{memberId}}} was changed.");

            return(Ok(member));
        }
Ejemplo n.º 2
0
        public async Task ToggleApproveStatusAsyncTest()
        {
            //Arrange
            _repoWrapper
            .Setup(s => s.CityMembers.GetFirstOrDefaultAsync(It.IsAny <Expression <Func <DataAccess.Entities.CityMembers, bool> > >(),
                                                             It.IsAny <Func <IQueryable <DataAccess.Entities.CityMembers>, IIncludableQueryable <DataAccess.Entities.CityMembers, object> > >()))
            .ReturnsAsync(new CityMembers()
            {
                UserId = "someId", IsApproved = false
            });

            //Act
            await _cityParticipantsService.ToggleApproveStatusAsync(It.IsAny <int>());

            //Assert
            _repoWrapper.Verify(i => i.CityMembers.Update(It.IsAny <CityMembers>()), Times.Once());
        }
        public async Task ToggleApproveStatusAsync_Valid_Test(bool isInRole)
        {
            // Arrange
            _repoWrapper
            .Setup(x => x.CityMembers
                   .GetFirstOrDefaultAsync(It.IsAny <Expression <Func <CityMembers, bool> > >(),
                                           It.IsAny <Func <IQueryable <CityMembers>, IIncludableQueryable <CityMembers, object> > >()))
            .ReturnsAsync(new CityMembers()
            {
                UserId = fakeId.ToString(),
                User   = new User()
                {
                    Email = "email"
                },
                City = new DataAccess.Entities.City()
                {
                    Name = "CityName"
                },
                IsApproved = false
            });
            _repoWrapper
            .Setup(x => x.CityMembers.Update(It.IsAny <CityMembers>()));
            _repoWrapper
            .Setup(x => x.SaveAsync());
            _userManager
            .Setup(x => x.FindByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new User());
            _userManager
            .Setup(x => x.IsInRoleAsync(It.IsAny <User>(), It.IsAny <string>()))
            .ReturnsAsync(isInRole);
            _repoWrapper
            .Setup(m => m.UserMembershipDates
                   .GetFirstOrDefaultAsync(It.IsAny <Expression <Func <UserMembershipDates, bool> > >(),
                                           It.IsAny <Func <IQueryable <UserMembershipDates>, IIncludableQueryable <UserMembershipDates, object> > >()))
            .ReturnsAsync(new UserMembershipDates());
            _repoWrapper
            .Setup(x => x.UserMembershipDates.Update(It.IsAny <UserMembershipDates>()));
            _mapper
            .Setup(x => x.Map <CityMembers, CityMembersDTO>(It.IsAny <CityMembers>()))
            .Returns(new CityMembersDTO());
            _repoWrapper
            .Setup(x => x.GetCitiesUrl)
            .Returns("citiesUrl");
            _emailSendingService
            .Setup(x => x.SendEmailAsync(It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>()))
            .ReturnsAsync(true);
            _emailContentService
            .Setup(x => x.GetCityApproveEmailAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new EmailModel());
            _emailContentService
            .Setup(x => x.GetCityToSupporterRoleOnApproveEmail()).Returns(new EmailModel());

            // Act
            var result = await _cityParticipantsService.ToggleApproveStatusAsync(fakeId);

            // Assert
            Assert.NotNull(result);
            Assert.IsInstanceOf <CityMembersDTO>(result);
        }