public override async Task <Unit> Handle(ChangePinAction aChangePinAction, CancellationToken aCancellationToken) { ChangePinDto changePinDto = MapSendActionToChangePinDto(aChangePinAction); Console.WriteLine("Check if the Data Exists, NewPIn: {0}, EnablePin Login: {1}", changePinDto.NewPin, changePinDto.EnableLogin); //not sure about this line string changePinResults = await JSRuntime.InvokeAsync <string>(EdgeInteropMethodNames.EdgeAccountInterop_ChangePin, changePinDto); Console.WriteLine($"whatever Comes Back from ChangePin:", changePinResults); return(Unit.Value); }
public async Task ChangePinAsync_should_return_401_when_authentication_fails() { // Arrange var controller = new EmployeesController(this.Fixture.EmployeeRepository, this.Fixture.JwtRepository, this.Logger) { EmployeeCardId = this.Fixture.InvalidId }; var contextMock = new Mock <HttpContext>(); contextMock.Setup(x => x.User).Returns(new ClaimsPrincipal()); controller.ControllerContext.HttpContext = contextMock.Object; var model = new ChangePinDto(); // Act var response = await controller.ChangePinAsync(model); // Assert Assert.IsType <UnauthorizedResult>(response); }
public async Task <DataHolder <CreditCard> > ChangePinAsync(ChangePinDto pinDto, Guid userId) { var creditCard = await GetCreditCardById(pinDto.Id, userId); if (creditCard == null) { return(DataHolder <CreditCard> .CreateFailure("Card don't exits")); } creditCard.Pin = pinDto.NewPin; var updateRes = await _creditCardRepository.UpdateAsync(creditCard); if (updateRes < 0) { return(DataHolder <CreditCard> .CreateFailure("Can't update credit card")); } return(DataHolder <CreditCard> .CreateSuccess(creditCard)); }
public async Task ChangePinAsync_should_return_500_when_error() { // Arrange var controller = new EmployeesController(null, null, this.Logger) { EmployeeCardId = this.Fixture.ValidId }; var contextMock = new Mock <HttpContext>(); contextMock.Setup(x => x.User).Returns(new ClaimsPrincipal()); controller.ControllerContext.HttpContext = contextMock.Object; var model = new ChangePinDto(); // Act var response = await controller.ChangePinAsync(model); // Assert var result = Assert.IsType <StatusCodeResult>(response); Assert.Equal(500, result.StatusCode); }
public async Task ChangePinAsync_should_return_200_with_true_when_changed() { // Arrange var controller = new EmployeesController(this.Fixture.EmployeeRepository, this.Fixture.JwtRepository, this.Logger) { EmployeeCardId = this.Fixture.ValidId }; var contextMock = new Mock <HttpContext>(); contextMock.Setup(x => x.User).Returns(new ClaimsPrincipal()); controller.ControllerContext.HttpContext = contextMock.Object; var model = new ChangePinDto(); // Act var response = await controller.ChangePinAsync(model); // Assert var result = Assert.IsType <OkObjectResult>(response); var resultValue = Boolean.Parse(result.Value.ToString()); Assert.True(resultValue); }
public async Task <IActionResult> ChangePin([FromBody] ChangePinDto pinDto) { if (pinDto.NewPin < 1000 || pinDto.NewPin > 9999) { return(BadRequest("Invalid pin")); } var userIdHolder = await _userService.GetUserId(User.Identity.Name); if (userIdHolder.Status == DataHolderStatus.Unauthorized) { return(Unauthorized()); } var cardHolder = await _creditCardService.ChangePinAsync(pinDto, new Guid(userIdHolder.Data)); if (cardHolder.Status == DataHolderStatus.Failure) { return(BadRequest(cardHolder.Message)); } return(Ok(_mapper.Map <CreditCard, CreditCardDto>(cardHolder.Data))); }
public async Task <IActionResult> ChangePinAsync([FromBody] ChangePinDto model) { try { // Confirm that the provided emplyoee pin is correct. var authenticationConfirmed = await this.EmployeeRepository.VerifyPinAsync(this.EmployeeCardId, model.Pin); if (!authenticationConfirmed) { return(this.Unauthorized()); } // Update the pin using the new pin. var updated = await this.EmployeeRepository.ChangePinAsync(this.EmployeeCardId, model.NewPin); // Return the result of the update. return(this.Ok(updated)); } catch (Exception ex) { this.Logger.LogError(ex, "Error when ChangePinAsync for employeeCardId {0}", this.EmployeeCardId); return(this.StatusCode(500)); } }