コード例 #1
0
        public async Task CreateTest()
        {
            // Arrange
            _userManager
            .Setup(x => x.GetUserIdAsync(It.IsAny <User>()))
            .ReturnsAsync("userId");
            _repoWrapper
            .Setup(x => x.ConfirmedUser.CreateAsync(It.IsAny <ConfirmedUser>()));
            _repoWrapper
            .Setup(x => x.SaveAsync());
            _emailSendingService
            .Setup(s => s.SendEmailAsync(It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>()))
            .ReturnsAsync(true);
            _emailContentService
            .Setup(x => x.GetConfirmedUserEmailAsync(It.IsAny <User>(), It.IsAny <User>()))
            .ReturnsAsync(new EmailModel());
            _userManager
            .Setup(x => x.FindByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new User()
            {
                Email = "email"
            });
            var service = new ConfirmedUsersService(_repoWrapper.Object, _userManager.Object, _emailSendingService.Object, _emailContentService.Object);

            // Act
            await service.CreateAsync(new User(), "vaucheeId");

            // Assert
            _repoWrapper.Verify(r => r.ConfirmedUser.CreateAsync(It.IsAny <ConfirmedUser>()), Times.Once());
            _repoWrapper.Verify(r => r.SaveAsync(), Times.Once());
        }
コード例 #2
0
        public async Task DeleteTest()
        {
            _repoWrapper.Setup(x => x.ConfirmedUser.GetFirstAsync(It.IsAny <Expression <Func <ConfirmedUser, bool> > >(), null)).ReturnsAsync(new ConfirmedUser());
            var service = new ConfirmedUsersService(_repoWrapper.Object, _userManager.Object);

            await service.DeleteAsync(It.IsAny <int>());

            _repoWrapper.Verify(r => r.ConfirmedUser.Delete(It.IsAny <ConfirmedUser>()), Times.Once());
            _repoWrapper.Verify(r => r.SaveAsync(), Times.Once());
        }
コード例 #3
0
        public async Task CreateTest()
        {
            _userManager.Setup(x => x.GetUserId(It.IsAny <ClaimsPrincipal>())).Returns("1");
            _repoWrapper.Setup(x => x.ConfirmedUser.GetAllAsync(null, null)).ReturnsAsync(new List <ConfirmedUser>().AsQueryable());
            var service = new ConfirmedUsersService(_repoWrapper.Object, _userManager.Object);

            await service.CreateAsync(It.IsAny <User>(), It.IsAny <string>());

            _repoWrapper.Verify(r => r.ConfirmedUser.CreateAsync(It.IsAny <ConfirmedUser>()), Times.Once());
            _repoWrapper.Verify(r => r.SaveAsync(), Times.Once());
        }
コード例 #4
0
        public async Task DeleteTest()
        {
            // Arrange
            _repoWrapper.Setup(x => x.ConfirmedUser
                               .GetFirstOrDefaultAsync(It.IsAny <Expression <Func <ConfirmedUser, bool> > >(),
                                                       null))
            .ReturnsAsync(new ConfirmedUser()
            {
                UserID = "userId"
            });
            _userManager
            .Setup(x => x.FindByIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new User()
            {
                Email = "email"
            });
            _repoWrapper
            .Setup(x => x.ConfirmedUser.Delete(It.IsAny <ConfirmedUser>()));
            _repoWrapper
            .Setup(x => x.SaveAsync());
            _emailSendingService
            .Setup(s => s.SendEmailAsync(It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>(),
                                         It.IsAny <string>()))
            .ReturnsAsync(true);
            _emailContentService
            .Setup(x => x.GetCanceledUserEmailAsync(It.IsAny <User>(), It.IsAny <User>()))
            .ReturnsAsync(new EmailModel());
            var service = new ConfirmedUsersService(_repoWrapper.Object,
                                                    _userManager.Object,
                                                    _emailSendingService.Object,
                                                    _emailContentService.Object);

            // Act
            await service.DeleteAsync(new User(), 1);

            // Assert
            _repoWrapper.Verify(r => r.ConfirmedUser.Delete(It.IsAny <ConfirmedUser>()), Times.Once());
            _repoWrapper.Verify(r => r.SaveAsync(), Times.Once());
        }