Example #1
0
        public async Task ValidateTwoFactorAuthenticationOTPAsync_GivenUnverifiedTokenandFindableUser_ReturnsFailed()
        {
            var userRepository       = Substitute.For <IUserRepository>();
            var twoFactorAuthService = new TwoFactorAuthService(userRepository, customUserManagerFake);

            userRepository.GetByIdAsync(twoFactorAuthOTP.UserId, Arg.Any <bool>()).Returns(mockedUserModel);
            customUserManagerFake.SetAuthenticatorTokenVerified(false);
            customUserManagerFake.SetAuthenticatorOtpValid(true);

            ValidationResultResponse validationResultResponse = await twoFactorAuthService.ValidateTwoFactorAuthenticationOTPAsync(twoFactorAuthOTP);

            Assert.False(validationResultResponse.Success, "Giving unverfied token and findable user must return success false.");
        }
Example #2
0
        public async Task ValidateTwoFactorAuthenticationOTPAsync_GivenUnfindableUser_ThrowsNotFoundException()
        {
            var userRepository       = Substitute.For <IUserRepository>();
            var twoFactorAuthService = new TwoFactorAuthService(userRepository, customUserManagerFake);

            customUserManagerFake.SetAuthenticatorTokenVerified(true);
            customUserManagerFake.SetAuthenticatorOtpValid(true);

            Exception catchingException = null;

            try
            {
                await twoFactorAuthService.ValidateTwoFactorAuthenticationOTPAsync(twoFactorAuthOTP);
            }
            catch (Exception ex)
            {
                catchingException = ex;
            }

            Assert.True(catchingException is ItemNotFoundException, "Giving unfindable user must throw ItemNotFoundException.");
        }