public async Task Then_Updates_Existing_Reservation_If_Supplied(ReservationsRouteModel routeModel, ConfirmLegalEntityViewModel viewModel, GetLegalEntitiesResponse getLegalEntitiesResponse, long decodedAccountId, [Frozen] Mock <IMediator> mockMediator, [Frozen] Mock <IEncodingService> mockEncodingService, EmployerReservationsController controller) { var firstLegalEntity = getLegalEntitiesResponse.AccountLegalEntities.First(); firstLegalEntity.AgreementSigned = true; viewModel.LegalEntity = firstLegalEntity.AccountLegalEntityPublicHashedId; mockMediator .Setup(mediator => mediator.Send( It.Is <GetLegalEntitiesQuery>(query => query.AccountId == decodedAccountId), It.IsAny <CancellationToken>())) .ReturnsAsync(getLegalEntitiesResponse); mockEncodingService .Setup(service => service.Decode(routeModel.EmployerAccountId, EncodingType.AccountId)) .Returns(decodedAccountId); await controller.PostSelectLegalEntity(routeModel, viewModel); mockMediator.Verify(mediator => mediator.Send( It.Is <CacheReservationEmployerCommand>(command => command.Id == routeModel.Id), It.IsAny <CancellationToken>()), Times.Once); }
public async Task Then_Caches_New_Reservation( ReservationsRouteModel routeModel, ConfirmLegalEntityViewModel viewModel, GetLegalEntitiesResponse getLegalEntitiesResponse, long decodedAccountId, [Frozen] Mock <IMediator> mockMediator, [Frozen] Mock <IEncodingService> mockEncodingService, EmployerReservationsController controller) { var firstLegalEntity = getLegalEntitiesResponse.AccountLegalEntities.First(); viewModel.LegalEntity = firstLegalEntity.AccountLegalEntityPublicHashedId; mockMediator .Setup(mediator => mediator.Send( It.Is <GetLegalEntitiesQuery>(query => query.AccountId == decodedAccountId), It.IsAny <CancellationToken>())) .ReturnsAsync(getLegalEntitiesResponse); mockEncodingService .Setup(service => service.Decode(routeModel.EmployerAccountId, EncodingType.AccountId)) .Returns(decodedAccountId); await controller.PostSelectLegalEntity(routeModel, viewModel); mockMediator.Verify(mediator => mediator.Send( It.Is <CacheReservationEmployerCommand>(command => command.Id != Guid.Empty && command.AccountId == firstLegalEntity.AccountId && command.AccountLegalEntityId == firstLegalEntity.AccountLegalEntityId && command.AccountLegalEntityName == firstLegalEntity.AccountLegalEntityName && command.AccountLegalEntityPublicHashedId == firstLegalEntity.AccountLegalEntityPublicHashedId && !command.EmployerHasSingleLegalEntity), It.IsAny <CancellationToken>()), Times.Once); }
public void Then_The_Model_Is_Populated_With_The_Correct_Values( string dashboardUrl, string findApprenticeshipTrainingUrl, string providerPermissionsUrl, ReservationsRouteModel routeModel, [Frozen] Mock <IExternalUrlHelper> externalUrlHelper, [Frozen] IOptions <ReservationsWebConfiguration> configuration, EmployerReservationsController controller) { //Arrange externalUrlHelper.Setup(x => x.GenerateDashboardUrl(routeModel.EmployerAccountId)).Returns(dashboardUrl); externalUrlHelper.Setup(x => x.GenerateUrl( It.Is <UrlParameters>(c => c.SubDomain.Equals("permissions") && c.Folder.Equals("accounts") && c.Id.Equals(routeModel.EmployerAccountId) && c.Controller.Equals("providers")))) .Returns(providerPermissionsUrl); configuration.Value.FindApprenticeshipTrainingUrl = findApprenticeshipTrainingUrl; //Act var actual = controller.CourseGuidance(routeModel); //Assert Assert.IsNotNull(actual); var actualViewResult = actual as ViewResult; Assert.IsNotNull(actualViewResult); var actualModel = actualViewResult.Model as CourseGuidanceViewModel; Assert.IsNotNull(actualModel); Assert.AreEqual(dashboardUrl, actualModel.DashboardUrl); Assert.AreEqual(RouteNames.EmployerSelectCourse, actualModel.BackRouteName); Assert.AreEqual(findApprenticeshipTrainingUrl, actualModel.FindApprenticeshipTrainingUrl); Assert.AreEqual(providerPermissionsUrl, actualModel.ProviderPermissionsUrl); }
public async Task Then_Sets_Owner_Users_On_ViewModel( ReservationsRouteModel routeModel, GetAccountUsersResponse usersResponse, long decodedAccountId, [Frozen] Mock <IMediator> mockMediator, [Frozen] Mock <IEncodingService> mockEncodingService, EmployerReservationsController controller) { usersResponse.AccountUsers.First().Role = "Owner"; mockEncodingService .Setup(service => service.Decode( routeModel.EmployerAccountId, EncodingType.AccountId)) .Returns(decodedAccountId); mockMediator .Setup(mediator => mediator.Send( It.IsAny <GetAccountUsersQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(usersResponse); var result = await controller.TransactorSignAgreement(routeModel) as ViewResult; var model = result.Model as SignAgreementViewModel; model.OwnersOfThisAccount.Should().BeEquivalentTo(usersResponse.AccountUsers .Where(user => user.Role.Equals(EmployerUserRole.Owner.ToString(), StringComparison.InvariantCultureIgnoreCase)) .OrderBy(user => user.Name) .Select(user => (EmployerAccountUserViewModel)user)); }
public async Task Then_The_BackLink_Is_Set_To_Return_To_SelectLegalEntityView( ICollection <Course> courses, [Frozen] Mock <IMediator> mockMediator, ReservationsRouteModel routeModel, EmployerReservationsController controller, PostSelectCourseViewModel postSelectCourseViewModel) { //Arrange _cachedReservationResult.CohortRef = ""; _cachedReservationResult.EmployerHasSingleLegalEntity = false; routeModel.CohortReference = ""; routeModel.FromReview = false; _mediator.Setup(mediator => mediator.Send(It.IsAny <CacheReservationCourseCommand>(), It.IsAny <CancellationToken>())) .ThrowsAsync(new ValidationException(new ValidationResult("Failed", new List <string> { "Course|The Course field is not valid." }), null, null)); postSelectCourseViewModel.SelectedCourseId = _course.Id; //Act var result = await _controller.PostSelectCourse(routeModel, postSelectCourseViewModel) as ViewResult; var viewModel = result?.Model as EmployerSelectCourseViewModel; Assert.IsNotNull(viewModel); Assert.AreEqual(RouteNames.EmployerSelectLegalEntity, viewModel.BackLink); Assert.AreEqual(routeModel.CohortReference, viewModel.CohortReference); }
public async Task ThenRedirectToStartIfNoActiveFromDateFoundOnNextGlobalFundingRule( string expectedUserId, [Frozen] Mock <IMediator> mockMediator, ReservationsRouteModel routeModel, EmployerReservationsController controller) { //arrange controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(EmployerClaims.IdamsUserIdClaimTypeIdentifier, expectedUserId) })); mockMediator.Setup(x => x.Send(It.IsAny <GetNextUnreadGlobalFundingRuleQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetNextUnreadGlobalFundingRuleResult { Rule = new GlobalRule { Id = 2 } }); //act var redirect = await controller.Index(routeModel) as RedirectToRouteResult; //assert Assert.IsNotNull(redirect); Assert.AreEqual(redirect.RouteName, RouteNames.EmployerStart); }
public async Task And_Single_Legal_Entity_Then_The_BackLink_Is_Set_To_Return_To_Start( ReservationsRouteModel routeModel, ICollection <Course> courses, GetCachedReservationResult cachedReservationResult, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { //Arrange routeModel.FromReview = false; cachedReservationResult.CohortRef = string.Empty; cachedReservationResult.IsEmptyCohortFromSelect = false; cachedReservationResult.EmployerHasSingleLegalEntity = true; mockMediator .Setup(m => m.Send(It.IsAny <GetCoursesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetCoursesResult { Courses = courses }); mockMediator .Setup(mediator => mediator.Send(It.IsAny <GetCachedReservationQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(cachedReservationResult); //Act var result = await controller.SelectCourse(routeModel) as ViewResult; //Assert var viewModel = result?.Model as EmployerSelectCourseViewModel; Assert.IsNotNull(viewModel); Assert.AreEqual(RouteNames.EmployerStart, viewModel.BackLink); }
public async Task And_Only_One_Legal_Entity_Then_Adds_Legal_Entity_To_Reservation_And_Redirects_To_Course_Selection( ReservationsRouteModel routeModel, AccountLegalEntity accountLegalEntity, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { routeModel.Id = null; var getLegalEntitiesResponse = new GetLegalEntitiesResponse { AccountLegalEntities = new List <AccountLegalEntity> { accountLegalEntity } }; mockMediator .Setup(mediator => mediator.Send(It.IsAny <GetLegalEntitiesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(getLegalEntitiesResponse); var result = await controller.SelectLegalEntity(routeModel) as RedirectToRouteResult; result.RouteName.Should().Be(RouteNames.EmployerSelectCourse); mockMediator.Verify(mediator => mediator.Send( It.Is <CacheReservationEmployerCommand>(command => command.Id != Guid.Empty && command.AccountId == accountLegalEntity.AccountId && command.AccountLegalEntityId == accountLegalEntity.AccountLegalEntityId && command.AccountLegalEntityName == accountLegalEntity.AccountLegalEntityName && command.AccountLegalEntityPublicHashedId == accountLegalEntity.AccountLegalEntityPublicHashedId && command.EmployerHasSingleLegalEntity), It.IsAny <CancellationToken>()), Times.Once); }
public void Arrange() { var fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true }); _course = new Course("1-4-5", "test", 1); _cachedReservationResult = fixture.Create <GetCachedReservationResult>(); _externalUrlHelper = fixture.Freeze <Mock <IExternalUrlHelper> >(); _mediator = fixture.Freeze <Mock <IMediator> >(); _controller = fixture.Create <EmployerReservationsController>(); _mediator.Setup(mediator => mediator.Send( It.IsAny <GetCachedReservationQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(() => _cachedReservationResult); _mediator.Setup(mediator => mediator.Send( It.IsAny <CacheReservationCourseCommand>(), It.IsAny <CancellationToken>())) .ReturnsAsync(Unit.Value); _mediator.Setup(m => m.Send(It.IsAny <GetCoursesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetCoursesResult { Courses = new List <Course> { _course } }); }
And_User_Has_Transactor_Role_And_Chosen_Legal_Entity_Has_Not_Signed_Agreement_Then_Redirect_To_Transactor_Sign_Route( ReservationsRouteModel routeModel, ConfirmLegalEntityViewModel viewModel, GetLegalEntitiesResponse getLegalEntitiesResponse, [Frozen] Mock <IMediator> mockMediator, [Frozen] Mock <IUserClaimsService> mockClaimsService, EmployerReservationsController controller) { var firstLegalEntity = getLegalEntitiesResponse.AccountLegalEntities.First(); firstLegalEntity.AgreementSigned = false; viewModel.LegalEntity = firstLegalEntity.AccountLegalEntityPublicHashedId; mockMediator .Setup(mediator => mediator.Send( It.IsAny <GetLegalEntitiesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(getLegalEntitiesResponse); mockClaimsService .Setup(service => service.UserIsInRole( routeModel.EmployerAccountId, EmployerUserRole.Owner, It.IsAny <IEnumerable <Claim> >())) .Returns(false); var result = await controller.PostSelectLegalEntity(routeModel, viewModel) as RedirectToRouteResult; result.RouteName.Should().Be(RouteNames.EmployerTransactorSignAgreement); result.RouteValues[nameof(ReservationsRouteModel.PreviousPage)].Should().Be(RouteNames.EmployerSelectLegalEntity); }
public async Task And_ValidationException_Then_Redirects_To_SelectLegalEntity( ReservationsRouteModel routeModel, ConfirmLegalEntityViewModel viewModel, GetLegalEntitiesResponse getLegalEntitiesResponse, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { var firstLegalEntity = getLegalEntitiesResponse.AccountLegalEntities.First(); firstLegalEntity.AgreementSigned = true; viewModel.LegalEntity = firstLegalEntity.AccountLegalEntityPublicHashedId; mockMediator .Setup(mediator => mediator.Send( It.IsAny <GetLegalEntitiesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(getLegalEntitiesResponse); mockMediator.Setup(x => x.Send(It.IsAny <CacheReservationEmployerCommand>(), It.IsAny <CancellationToken>())) .ThrowsAsync(new ValidationException( new ValidationResult("Failed", new List <string> { "AccountId| Account reservation limit has been reached." }), null, null)); var actual = await controller.PostSelectLegalEntity(routeModel, viewModel); actual.Should().NotBeNull(); var actualViewResult = actual as ViewResult; actualViewResult.Should().NotBeNull(); actualViewResult?.ViewName.Should().Be("SelectLegalEntity"); controller.ModelState.IsValid.Should().BeFalse(); controller.ModelState.Should().Contain(pair => pair.Key == "AccountId"); }
And_User_Has_Owner_Role_And_Chosen_Legal_Entity_Has_Not_Signed_Agreement_Then_Redirect_To_Owner_Sign_Route( ReservationsRouteModel routeModel, AccountLegalEntity accountLegalEntity, GetLegalEntitiesResponse getLegalEntitiesResponse, [Frozen] Mock <IMediator> mockMediator, [Frozen] Mock <IUserClaimsService> mockClaimsService, EmployerReservationsController controller) { getLegalEntitiesResponse.AccountLegalEntities = new List <AccountLegalEntity> { accountLegalEntity }; accountLegalEntity.AgreementSigned = false; mockMediator .Setup(mediator => mediator.Send( It.IsAny <GetLegalEntitiesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(getLegalEntitiesResponse); mockClaimsService .Setup(service => service.UserIsInRole( routeModel.EmployerAccountId, EmployerUserRole.Owner, It.IsAny <IEnumerable <Claim> >())) .Returns(true); var result = await controller.SelectLegalEntity(routeModel) as RedirectToRouteResult; result.RouteName.Should().Be(RouteNames.EmployerOwnerSignAgreement); result.RouteValues[nameof(ReservationsRouteModel.PreviousPage)].Should().Be(RouteNames.EmployerIndex); }
public async Task And_Reservation_Limit_Has_Been_Exceeded_Then_Shows_Reservation_Limit_Reached_Page( ReservationsRouteModel routeModel, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { mockMediator .Setup(mediator => mediator.Send(It.IsAny <GetLegalEntitiesQuery>(), It.IsAny <CancellationToken>())) .ThrowsAsync(new ReservationLimitReachedException(10)); var result = await controller.SelectLegalEntity(routeModel) as ViewResult; Assert.AreEqual("ReservationLimitReached", result?.ViewName); }
public async Task And_Global_Rule_Exists_Then_Shows_Funding_Paused_Page( ReservationsRouteModel routeModel, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { mockMediator .Setup(mediator => mediator.Send(It.IsAny <GetLegalEntitiesQuery>(), It.IsAny <CancellationToken>())) .ThrowsAsync(new GlobalReservationRuleException(10)); var result = await controller.SelectLegalEntity(routeModel) as ViewResult; Assert.AreEqual("EmployerFundingPaused", result?.ViewName); }
public void Then_Sets_IsUrl_If_From_SelectReservation_On_ViewModel( ReservationsRouteModel routeModel, EmployerReservationsController controller) { routeModel.IsFromSelect = true; var result = controller.OwnerSignAgreement(routeModel) as ViewResult; result.ViewName.Should().Be("OwnerSignAgreement"); var model = result.Model as SignAgreementViewModel; model.BackRouteName.Should().Be(routeModel.PreviousPage); model.IsUrl.Should().BeTrue(); }
public async Task Then_Gets_Cached_Reservation( ReservationsRouteModel routeModel, GetCoursesResult coursesResult, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { mockMediator .Setup(m => m.Send(It.IsAny <GetCoursesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(coursesResult); await controller.SelectCourse(routeModel); mockMediator.Verify(mediator => mediator.Send(It.Is <GetCachedReservationQuery>(query => query.Id == routeModel.Id.Value), CancellationToken.None), Times.Once); }
public async Task And_Exception_Then_Redirect_To_Error_500( ReservationsRouteModel routeModel, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { mockMediator .Setup(mediator => mediator.Send( It.IsAny <GetAccountUsersQuery>(), It.IsAny <CancellationToken>())) .Throws <Exception>(); var result = await controller.TransactorSignAgreement(routeModel) as RedirectToRouteResult; result.RouteName.Should().Be(RouteNames.Error500); }
public async Task WhenApprenticeshipTrainingNotKnown_ThenRedirectsToGuidancePage( ReservationsRouteModel routeModel, EmployerReservationsController controller, PostSelectCourseViewModel postSelectCourseViewModel) { //Arrange postSelectCourseViewModel.ApprenticeTrainingKnown = false; var expectedRouteName = RouteNames.EmployerCourseGuidance; //Act var result = await controller.PostSelectCourse(routeModel, postSelectCourseViewModel) as RedirectToRouteResult; //Assert Assert.NotNull(result); Assert.AreEqual(expectedRouteName, result.RouteName); }
public async Task ThenRedirectToFundingNotificationIfFundingRulesExist( string expectedUserId, [Frozen] Mock <IMediator> mockMediator, [Frozen] Mock <IUrlHelper> urlHelper, string expectedBackUrl, ReservationsRouteModel routeModel, EmployerReservationsController controller) { //Arrange urlHelper.Setup(h => h.RouteUrl(It.Is <UrlRouteContext>(c => c.RouteName.Equals(RouteNames.EmployerManage)))) .Returns(expectedBackUrl); var expectedRule = new GlobalRule { Id = 2, ActiveFrom = DateTime.Now.AddDays(2) }; controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(EmployerClaims.IdamsUserIdClaimTypeIdentifier, expectedUserId) })); var result = new GetNextUnreadGlobalFundingRuleResult { Rule = expectedRule }; mockMediator.Setup(x => x.Send(It.IsAny <GetNextUnreadGlobalFundingRuleQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(result); //act var view = await controller.Index(routeModel) as ViewResult; //assert Assert.IsNotNull(view); var viewModel = view?.Model as FundingRestrictionNotificationViewModel; Assert.IsNotNull(viewModel); Assert.AreEqual(view.ViewName, "FundingRestrictionNotification"); Assert.AreEqual(expectedRule.Id, viewModel.RuleId); Assert.AreEqual(RuleType.GlobalRule, viewModel.TypeOfRule); Assert.AreEqual(expectedRule.ActiveFrom, viewModel.RestrictionStartDate); Assert.AreEqual(expectedBackUrl, viewModel.BackLink); Assert.AreEqual(false, viewModel.IsProvider); Assert.AreEqual(RouteNames.EmployerStart, viewModel.RouteName); Assert.AreEqual(RouteNames.EmployerSaveRuleNotificationChoiceNoReservation, viewModel.PostRouteName); }
public async Task And_Model_Invalid_Then_Shows_View_Again( ReservationsRouteModel routeModel, ConfirmLegalEntityViewModel viewModel, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { controller.ModelState.AddModelError("test", "test"); var result = await controller.PostSelectLegalEntity(routeModel, viewModel) as ViewResult; result.Should().NotBeNull(); result.ViewName.Should().Be("SelectLegalEntity"); mockMediator.Verify(mediator => mediator.Send( It.IsAny <CacheReservationEmployerCommand>(), It.IsAny <CancellationToken>()), Times.Never); }
public async Task Then_If_There_Is_A_Reservation_Created_The_Entity_Is_Taken_From_The_Cache( ReservationsRouteModel routeModel, GetLegalEntitiesResponse getLegalEntitiesResponse, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { mockMediator .Setup(mediator => mediator.Send(It.IsAny <GetLegalEntitiesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(getLegalEntitiesResponse); var result = await controller.SelectLegalEntity(routeModel) as ViewResult; result.Should().NotBeNull(); mockMediator.Verify(x => x.Send(It.Is <GetCachedReservationQuery>(c => c.Id.Equals(routeModel.Id)), It.IsAny <CancellationToken>()), Times.Once); var viewModel = result?.Model.Should().BeOfType <SelectLegalEntityViewModel>().Subject; viewModel.Should().NotBeNull(); }
public void Arrange() { var fixture = new Fixture().Customize(new AutoMoqCustomization { ConfigureMembers = true }); _mockMediator = fixture.Freeze <Mock <IMediator> >(); _employerConfig = new ReservationsWebConfiguration { EmployerDashboardUrl = "test.com/test" }; var options = fixture.Freeze <Mock <IOptions <ReservationsWebConfiguration> > >(); options.Setup(o => o.Value).Returns(_employerConfig); _controller = fixture.Create <EmployerReservationsController>(); }
public async Task And_No_Cached_Reservation_Then_Redirects_Start_Again( ReservationsRouteModel routeModel, GetCoursesResult coursesResult, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { mockMediator .Setup(m => m.Send(It.IsAny <GetCoursesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(coursesResult); mockMediator .Setup(mediator => mediator.Send(It.IsAny <GetCachedReservationQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync((GetCachedReservationResult)null); var result = await controller.SelectCourse(routeModel) as ViewResult; result.Should().NotBeNull(); result?.ViewName.Should().Be("Index"); }
public async Task ThenRedirectToStartIfNoFundingRulesExist( string expectedUserId, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { //arrange controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(EmployerClaims.IdamsUserIdClaimTypeIdentifier, expectedUserId) })); mockMediator.Setup(x => x.Send(It.IsAny <GetNextUnreadGlobalFundingRuleQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync((GetNextUnreadGlobalFundingRuleResult)null); //act var redirect = await controller.Index() as RedirectToActionResult; //assert Assert.IsNotNull(redirect); Assert.AreEqual(redirect.ActionName, "Start"); }
public async Task Then_Returns_Populated_View_Model( ReservationsRouteModel routeModel, GetLegalEntitiesResponse getLegalEntitiesResponse, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { routeModel.Id = null; mockMediator .Setup(mediator => mediator.Send(It.IsAny <GetLegalEntitiesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(getLegalEntitiesResponse); var result = await controller.SelectLegalEntity(routeModel) as ViewResult; result.Should().NotBeNull(); var viewModel = result?.Model.Should().BeOfType <SelectLegalEntityViewModel>().Subject; viewModel.Should().NotBeNull(); viewModel?.RouteModel.Should().BeEquivalentTo(routeModel); viewModel?.LegalEntities.Should().BeEquivalentTo(getLegalEntitiesResponse.AccountLegalEntities, options => options.ExcludingMissingMembers()); }
public async Task Then_Sets_The_IsUrl_Property_If_Come_From_Select_Reservation( ReservationsRouteModel routeModel, GetAccountUsersResponse usersResponse, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { mockMediator .Setup(mediator => mediator.Send( It.IsAny <GetAccountUsersQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(usersResponse); routeModel.IsFromSelect = true; var result = await controller.TransactorSignAgreement(routeModel) as ViewResult; result.ViewName.Should().Be("TransactorSignAgreement"); var model = result.Model as SignAgreementViewModel; model.BackRouteName.Should().Be(routeModel.PreviousPage); model.IsUrl.Should().BeTrue(); }
public async Task ThenChecksIfRelatedUnreadRulesExists( string expectedUserId, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { //Arrange controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { new Claim(EmployerClaims.IdamsUserIdClaimTypeIdentifier, expectedUserId) })); mockMediator.Setup(x => x.Send(It.IsAny <GetNextUnreadGlobalFundingRuleQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetNextUnreadGlobalFundingRuleResult()); //act await controller.Index(); //assert mockMediator.Verify(m => m.Send(It.Is <GetNextUnreadGlobalFundingRuleQuery>( q => q.Id.Equals(expectedUserId, StringComparison.CurrentCultureIgnoreCase)), It.IsAny <CancellationToken>()), Times.Once); }
public async Task Then_The_BackLink_Is_Set_To_Return_To_CohortDetails_If_There_Is_A_Cohort_Ref( ICollection <Course> courses, [Frozen] Mock <IExternalUrlHelper> externalUrlHelper, [Frozen] Mock <IMediator> mockMediator, ReservationsRouteModel routeModel, GetCachedReservationResult cachedReservationResult, string cohortUrl, EmployerReservationsController controller ) { //Arrange cachedReservationResult.CohortRef = "ABC123"; cachedReservationResult.IsEmptyCohortFromSelect = false; cachedReservationResult.UkPrn = null; mockMediator.Setup(m => m.Send(It.IsAny <GetCoursesQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(new GetCoursesResult { Courses = courses }); mockMediator .Setup(mediator => mediator.Send(It.IsAny <GetCachedReservationQuery>(), It.IsAny <CancellationToken>())) .ReturnsAsync(cachedReservationResult); externalUrlHelper.Setup(x => x.GenerateCohortDetailsUrl( null, routeModel.EmployerAccountId, cachedReservationResult.CohortRef, false, It.IsAny <string>() )) .Returns(cohortUrl); //Act var result = await controller.SelectCourse(routeModel) as ViewResult; //Assert var viewModel = result?.Model as EmployerSelectCourseViewModel; Assert.IsNotNull(viewModel); Assert.AreEqual(cohortUrl, viewModel.BackLink); Assert.AreEqual(cachedReservationResult.CohortRef, viewModel.CohortReference); Assert.AreEqual(cachedReservationResult.IsEmptyCohortFromSelect, viewModel.IsEmptyCohortFromSelect); }
public async Task ThenSendsCorrectCommand( [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { //arrange var expectedRuleId = 12L; var expectedTypeOfRule = RuleType.GlobalRule; var expectedUserId = "123"; var claim = new Claim(EmployerClaims.IdamsUserIdClaimTypeIdentifier, expectedUserId); controller.HttpContext.User = new ClaimsPrincipal(new ClaimsIdentity(new[] { claim })); //act await controller.SaveRuleNotificationChoice(expectedRuleId, expectedTypeOfRule, true); //assert mockMediator.Verify(m => m.Send(It.Is <MarkRuleAsReadCommand>(c => c.Id.Equals(expectedUserId) && c.RuleId.Equals(expectedRuleId) && c.TypeOfRule.Equals(expectedTypeOfRule)), It.IsAny <CancellationToken>())); }
public async Task WhenApprenticeshipTrainingIsNull_ThenRedirectsToSelectCourse( ReservationsRouteModel routeModel, PostSelectCourseViewModel postSelectCourseViewModel, [Frozen] Mock <IMediator> mockMediator, EmployerReservationsController controller) { //Arrange postSelectCourseViewModel.ApprenticeTrainingKnown = null; var expectedViewName = "SelectCourse"; _mediator.Setup(mediator => mediator.Send(It.IsAny <CacheReservationCourseCommand>(), It.IsAny <CancellationToken>())) .ThrowsAsync(new ValidationException(new ValidationResult("Failed", new List <string> { "Course|The Course field is not valid." }), null, null)); //Act var result = await _controller.PostSelectCourse(routeModel, postSelectCourseViewModel) as ViewResult; //Assert Assert.NotNull(result); Assert.AreEqual(expectedViewName, result.ViewName); }