public void ShouldReturnErrorForInvalidValidateOTPRequest()
        {
            var validateOTPResponse = _otpService.ValidateOtp(new ValidateOTPRequest());

            Assert.That(validateOTPResponse, Is.Not.Null);
            Assert.That(validateOTPResponse.UserId, Is.Null);
            Assert.That(validateOTPResponse.Success, Is.False);
            Assert.That(validateOTPResponse.Error, Is.EqualTo(_invalidRequestError));
        }
        public void ShouldNotValidateOutsideExpiryLimit()
        {
            var otpConfiguration = new OTPConfiguration
            {
                OTPExpiryInSeconds  = 2,
                NumberOfDigitsInOTP = 6,
                PrivateKey          = "as9121jd623ms23h232k3"
            };

            _otpService = new OTPService(new HmacBasedOTPAlgorithm(),
                                         new ExpiryBasedMovingFactorAlgorithm(otpConfiguration), new ErrorFactory(),
                                         otpConfiguration);

            string userId = "2j32jk432m23482394jkddsd";
            var    generateOTPResponse = _otpService.GenerateOtp(new GenerateOTPRequest
            {
                UserId = userId
            });

            Assert.That(generateOTPResponse, Is.Not.Null);
            Assert.That(generateOTPResponse.UserId, Is.EqualTo(userId));
            Assert.That(generateOTPResponse.OTP, Is.Not.Empty);

            Thread.Sleep(5000);

            var validateOTPResponse = _otpService.ValidateOtp(new ValidateOTPRequest
            {
                OTP    = generateOTPResponse.OTP,
                UserId = userId
            });

            Assert.That(validateOTPResponse, Is.Not.Null);
            Assert.That(validateOTPResponse.UserId, Is.EqualTo(userId));
            Assert.That(validateOTPResponse.Success, Is.False);
        }
        public ValidateModule(IOTPService otpService)
        {
            Get["/Validate"] = parameters => {
                return(View["Validate"]);
            };

            Post["/Validate"] = parameters =>
            {
                var validateOTPRequest  = this.Bind <ValidateOTPRequest>();
                var validateOTPResponse = otpService.ValidateOtp(validateOTPRequest);
                return(View["Validate", validateOTPResponse]);
            };
        }
        public ValidateModule(IOTPService otpService)
        {
            Get["/Validate"] = parameters => {
                                                 return View["Validate"];
            };

            Post["/Validate"] = parameters =>
            {
                var validateOTPRequest = this.Bind<ValidateOTPRequest>();
                var validateOTPResponse = otpService.ValidateOtp(validateOTPRequest);
                return View["Validate", validateOTPResponse];
            };
        }
        public void GenerateAndValidateOTP(string userId)
        {
            var generateOTPResponse = _otpService.GenerateOtp(new GenerateOTPRequest
            {
                UserId = userId
            });

            Assert.That(generateOTPResponse, Is.Not.Null);
            Assert.That(generateOTPResponse.UserId, Is.EqualTo(userId));
            Assert.That(generateOTPResponse.OTP, Is.Not.Empty);
            Assert.That(IsValidNumberFormat(generateOTPResponse.OTP), Is.True);

            var validateOTPResponse = _otpService.ValidateOtp(new ValidateOTPRequest
            {
                OTP    = generateOTPResponse.OTP,
                UserId = userId
            });

            Assert.That(validateOTPResponse, Is.Not.Null);
            Assert.That(validateOTPResponse.UserId, Is.EqualTo(userId));
            Assert.That(validateOTPResponse.Success, Is.True);
        }