コード例 #1
0
        public async Task ForgotPassword_Should_save_new_token_and_send_email()
        {
            // arrange
            var user = UserBuilder.Create().WithRole(UserRole.Customer).WithEmail(HealthyJuicesConstants.DEFAULT_USER_LOGIN).WithPassword(HealthyJuicesConstants.DEFAULT_USER_PASSWORD).Build(ArrangeRepositoryContext);

            var controller = new AuthorizationController(Mediator);
            var dto        = new ForgotPassword.Command(HealthyJuicesConstants.DEFAULT_USER_LOGIN);

            // act
            await controller.ForgotPasswordAsync(dto);

            // assert
            var subject = AssertRepositoryContext.Users.FirstOrDefault();

            subject.Should().NotBeNull();
            subject.PermissionsToken.Token.Should().NotBeNullOrEmpty();
            subject.PermissionsToken.Expiration.Should().BeAfter(DateTime.Now);
            subject.PermissionsToken.Expiration.Should().BeBefore(DateTime.Now.AddDays(2));

            MailerMock.Verify(mock => mock.SendAsync(It.Is <string>(x => x == HealthyJuicesConstants.DEFAULT_USER_LOGIN), It.IsAny <string>(), It.Is <string>(x => x.Contains(subject.PermissionsToken.Token)), false), Times.Once);
            MailerMock.VerifyNoOtherCalls();
        }