public async Task <ActionResult> RemovePaye(string hashedAccountId, RemovePayeSchemeViewModel model) { model.UserId = OwinWrapper.GetClaimValue("sub"); if (model.RemoveScheme == 1) { return(RedirectToAction("Index", "EmployerAccountPaye", new { model.HashedAccountId })); } var result = await _employerAccountPayeOrchestrator.RemoveSchemeFromAccount(model); if (result.Status != HttpStatusCode.OK) { return(View("Remove", result)); } var flashMessage = new FlashMessageViewModel { Severity = FlashMessageSeverityLevel.Success, Headline = $"You've removed {model.PayeRef}", HiddenFlashMessageInformation = "page-paye-scheme-deleted" }; AddFlashMessageToCookie(flashMessage); return(RedirectToAction("Index", "EmployerAccountPaye", new { model.HashedAccountId })); }
public void WhenIRemoveAScheme() { var accountId = (long)ScenarioContext.Current["AccountId"]; var hashedId = ScenarioContext.Current["HashedAccountId"].ToString(); var userId = ScenarioContext.Current["ExternalUserId"].ToString(); var employerPayeOrchestrator = _container.GetInstance <EmployerAccountPayeOrchestrator>(); var legalEntities = employerPayeOrchestrator.Get(hashedId, userId).Result; var scheme = legalEntities.Data.PayeSchemes.First(); var removeScheme = new RemovePayeSchemeViewModel { HashedAccountId = hashedId, RemoveScheme = 2, UserId = userId, AccountName = "", PayeRef = scheme.PayeRef }; try { var result = employerPayeOrchestrator.RemoveSchemeFromAccount(removeScheme).Result; if (result.Status == HttpStatusCode.Unauthorized) { _unauthorizedCount++; } } catch (Exception ex) { _exceptionCount++; } }
public async Task ThenThePayeSchemeNameShouldBeReturnedWhenTheUserSelectsASchemeToRemove() { //Arrange var hashedId = "ABV465"; var userRef = "abv345"; var payeRef = "123/abc"; var model = new RemovePayeSchemeViewModel { HashedAccountId = hashedId, PayeRef = payeRef, UserId = userRef }; _mediator.Setup(x => x.SendAsync(It.IsAny <GetEmployerAccountHashedQuery>())) .ReturnsAsync(new GetEmployerAccountResponse { Account = new Account { Name = "test account" } }); //Act var actual = await _employerAccountPayeOrchestrator.GetRemovePayeSchemeModel(model); //Assert Assert.AreEqual(SchemeName, actual.Data.PayeSchemeName); }
public async Task <ActionResult> RemovePaye(string hashedAccountId, RemovePayeSchemeViewModel model) { model.UserId = OwinWrapper.GetClaimValue(ControllerConstants.UserRefClaimKeyName); if (model.RemoveScheme == 1) { return(RedirectToAction(ControllerConstants.IndexActionName, ControllerConstants.EmployerAccountPayeControllerName, new { model.HashedAccountId })); } var result = await _employerAccountPayeOrchestrator.RemoveSchemeFromAccount(model); if (result.Status != HttpStatusCode.OK) { return(View(ControllerConstants.RemoveViewName, result)); } model.PayeSchemeName = model.PayeSchemeName ?? string.Empty; var flashMessage = new FlashMessageViewModel { Severity = FlashMessageSeverityLevel.Success, Headline = $"You've removed {model.PayeRef}", SubMessage = model.PayeSchemeName, HiddenFlashMessageInformation = "page-paye-scheme-deleted" }; AddFlashMessageToCookie(flashMessage); return(RedirectToAction(ControllerConstants.IndexActionName, ControllerConstants.EmployerAccountPayeControllerName, new { model.HashedAccountId })); }
public async Task ThenThePayeSchemeNameShouldBeReturnedWhenTheSchemeIsRemoved() { //Arrange var hashedId = "ABV465"; var userRef = "abv345"; var payeRef = "123/abc"; var model = new RemovePayeSchemeViewModel { HashedAccountId = hashedId, PayeRef = payeRef, UserId = userRef }; //Act var actual = await _employerAccountPayeOrchestrator.RemoveSchemeFromAccount(model); //Assert Assert.AreEqual(SchemeName, actual.Data.PayeSchemeName); }
public async Task ThenTheCommandIsCalledForRemovingThePayeScheme() { //Arrange var hashedId = "ABV465"; var userRef = "abv345"; var payeRef = "123/abc"; var model = new RemovePayeSchemeViewModel { HashedAccountId = hashedId, PayeRef = payeRef, UserId = userRef }; //Act var actual = await _employerAccountPayeOrchestrator.RemoveSchemeFromAccount(model); //Assert _mediator.Verify(x => x.SendAsync(It.Is <RemovePayeFromAccountCommand>(c => c.HashedAccountId.Equals(hashedId) && c.PayeRef.Equals(payeRef) && c.UserId.Equals(userRef))), Times.Once); }
//TODO: The message gets mutated by the method. Message needs to be made immutable public virtual async Task <OrchestratorResponse <RemovePayeSchemeViewModel> > RemoveSchemeFromAccount(RemovePayeSchemeViewModel model) { var response = new OrchestratorResponse <RemovePayeSchemeViewModel> { Data = model }; try { var result = await Mediator.SendAsync(new GetPayeSchemeByRefQuery { HashedAccountId = model.HashedAccountId, Ref = model.PayeRef, }); model.PayeSchemeName = result.PayeScheme.Name; await Mediator.SendAsync(new RemovePayeFromAccountCommand(model.HashedAccountId, model.PayeRef, model.UserId, model.RemoveScheme == 2, model.PayeSchemeName)); response.Data = model; } catch (UnauthorizedAccessException) { response.Status = HttpStatusCode.Unauthorized; } catch (InvalidRequestException ex) { response.Status = HttpStatusCode.BadRequest; response.Data.ErrorDictionary = ex.ErrorMessages; } return(response); }
public virtual async Task <OrchestratorResponse <RemovePayeSchemeViewModel> > GetRemovePayeSchemeModel(RemovePayeSchemeViewModel model) { var accountResponse = await Mediator.SendAsync(new GetEmployerAccountHashedQuery { HashedAccountId = model.HashedAccountId, UserId = model.UserId }); var payeResponse = await Mediator.SendAsync(new GetPayeSchemeByRefQuery { HashedAccountId = model.HashedAccountId, Ref = model.PayeRef }); model.AccountName = accountResponse.Account.Name; model.PayeSchemeName = payeResponse.PayeScheme.Name; return(new OrchestratorResponse <RemovePayeSchemeViewModel> { Data = model }); }