public void Activate_WhenCalledAndTokenDoesNotExist_EntityNotFoundExceptionExpected() { // ARRANGE _tokenProvider.IsTokenExpired(default(string), default(int)).ReturnsForAnyArgs(false); _accountActivationTokenRepository .SingleOrDefaultAsync(default(Expression <Func <AccountActivationToken, bool> >)) .ReturnsForAnyArgs((AccountActivationToken)null); Func <Task> action = async() => await _sut.Activate("the token"); // ACT & ASSERT action.Should().Throw <EntityNotFoundException>() .WithMessage("Given token the token does not exist in data store"); }
public async Task <ActionResult> Activate(string email, string otp) { var res = await _authService.Activate(email, otp); if (res == true) { TempData["SuccessMsg"] = "Your Account activated Successfully"; return(RedirectToAction("Login")); } return(Content("ERROR!")); }
public async Task <IActionResult> Activate(UserForRegisterActivateDto userForRegisterActivate) { try { await _authService.Activate(userForRegisterActivate.Token); } catch (Exception ex) when(ex is SecurityTokenExpiredException || ex is EntityNotFoundException) { return(BadRequest("User can not be activated: token expired or does not exist")); } return(NoContent()); }