示例#1
0
        public async Task Should_GenerateDisablementOrEnablement()
        {
            var request = FakeRequest();
            var user    = new UserFake().Builder
                          .RuleFor(x => x.Id, f => request.ToDisableId)
                          .Generate();
            var disablementType = new DisablementTypeFake().Builder
                                  .RuleFor(x => x.Id, f => request.DisablementTypeId)
                                  .Generate();

            var uowGeneralMock = new Mock <IUowGeneral>();

            uowGeneralMock.Setup(x => x.UserRepository.Find(user.Id)).ReturnsAsync(user);
            uowGeneralMock.Setup(x => x.DisablementTypeRepository.Find(disablementType.Id)).ReturnsAsync(disablementType);
            uowGeneralMock.Setup(x => x.UserDisablementRepository.Create(It.IsAny <UserDisablement>())).ReturnsAsync(It.IsAny <UserDisablement>());
            var mailServiceMock = new Mock <IMailService>();

            var handler = new DisableUserCommandHandler(uowGeneralMock.Object, mailServiceMock.Object);

            var response = await handler.Handle(request, default);

            Assert.NotNull(user.DisabledAccountAt);
            Assert.Equal(user.Id, response.UserId);
            uowGeneralMock.Verify(x => x.UserRepository.Update(user), Times.Once);
            uowGeneralMock.Verify(x =>
                                  x.UserDisablementRepository.Create(It.IsAny <UserDisablement>()), Times.Once);
            uowGeneralMock.Verify(x => x.SaveChanges(), Times.Once);
            mailServiceMock.Verify(x =>
                                   x.Enqueue(It.IsAny <MailTemplateData>(), typeof(IDisablementMail), It.IsAny <DisablementMailData>()),
                                   Times.Once);
        }
        public async Task Execute_CorrectCommand_EnablesUserAccount()
        {
            //Arrange
            var usersStub = new List <AppUser>
            {
                new AppUser {
                    Id = "6bd969d6-cec7-4383-8aa0-d59b89f77602", Email = "*****@*****.**", FullName = "Mr Test", IsDisabled = false
                }
            };
            var idStub = "6bd969d6-cec7-4383-8aa0-d59b89f77602";

            var userManager = MockUserManager.Build(usersStub, idStub).Object;
            var command     = new DisableUserCommand {
                Id = idStub
            };
            var handler = new DisableUserCommandHandler(_config.Object, _logger.Object, _context, userManager);

            //Act
            await handler.Handle(command);

            //Assert
            var user = await userManager.FindByIdAsync(idStub);

            Assert.AreEqual(user.IsDisabled.Value, true);
        }
示例#3
0
        public async Task ShouldThrow_AlreadyDisabledAccountException()
        {
            var request = FakeRequest();
            var user    = new UserFake().Builder
                          .RuleFor(x => x.Id, f => request.ToDisableId)
                          .RuleFor(x => x.DisabledAccountAt, f => f.Date.Recent())
                          .Generate();

            var uowGeneralMock = new Mock <IUowGeneral>();

            uowGeneralMock.Setup(x => x.UserRepository.Find(user.Id)).ReturnsAsync(user);
            var mailServiceMock = new Mock <IMailService>();

            var handler = new DisableUserCommandHandler(uowGeneralMock.Object, mailServiceMock.Object);

            await Assert.ThrowsAsync <AlreadyDisabledAccountException>(() =>
                                                                       handler.Handle(request, default));
        }