public void GetHomeViewModelShouldGetVacancies()
        {
            var searchViewModel = new DashboardVacancySummariesSearchViewModel();
            var vacancies       = new List <DashboardVacancySummaryViewModel>
            {
                new DashboardVacancySummaryViewModel
                {
                    Title = "Vacancy 1"
                }
            };
            var vacancyProvider = new Mock <IVacancyQAProvider>();

            vacancyProvider.Setup(vp => vp.GetPendingQAVacanciesOverview(searchViewModel)).Returns(new DashboardVacancySummariesViewModel {
                Vacancies = vacancies
            });
            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(c => c.Get <ManageWebConfiguration>())
            .Returns(new ManageWebConfiguration {
                AuthorisationGroupClaim = ValidAuthorisationGroupClaim
            });
            var mediator  = new AgencyUserMediatorBuilder().With(vacancyProvider).With(configurationService).Build();
            var principal = new ClaimsPrincipalBuilder().WithName("User001").WithGroup(ValidAuthorisationGroupClaim).Build();

            var response = mediator.GetHomeViewModel(principal, searchViewModel);

            response.AssertCodeAndMessage(AgencyUserMediatorCodes.GetHomeViewModel.OK);
            vacancyProvider.Verify(vp => vp.GetPendingQAVacanciesOverview(searchViewModel), Times.Once);
            response.ViewModel.VacancySummaries.Vacancies.ShouldBeEquivalentTo(vacancies);
        }
        [Test] //TODO: remove roleListPart
        public void GetHomeViewModelShouldGetUserViewModel()
        {
            const string userName  = "******";
            const string roleList  = "Agency";
            var          principal = new ClaimsPrincipalBuilder().WithName(userName).WithRole(Roles.Raa).WithRoleList(roleList).Build();

            var userProvider = new Mock <IAgencyUserProvider>();

            userProvider.Setup(up => up.GetAgencyUser(userName)).Returns(new AgencyUserViewModel
            {
                RoleId = roleList
            });

            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(c => c.Get <ManageWebConfiguration>())
            .Returns(new ManageWebConfiguration {
                AuthorisationGroupClaim = ValidAuthorisationGroupClaim
            });
            var mediator = new AgencyUserMediatorBuilder().With(userProvider).With(configurationService).Build();

            var response = mediator.GetHomeViewModel(principal, new DashboardVacancySummariesSearchViewModel());

            response.AssertCodeAndMessage(AgencyUserMediatorCodes.GetHomeViewModel.OK);
            response.ViewModel.AgencyUser.RoleId.Should().Be(roleList);
            userProvider.Verify(up => up.GetAgencyUser(userName), Times.Once);
        }
        public void Authenticated_MissingServicePermission()
        {
            var principal = new ClaimsPrincipalBuilder().WithName("User001").WithGroup(InValidAuthorisationGroupClaim).Build();

            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(c => c.Get <ManageWebConfiguration>())
            .Returns(new ManageWebConfiguration {
                AuthorisationGroupClaim = ValidAuthorisationGroupClaim
            });

            var mediator = new AgencyUserMediatorBuilder().With(configurationService).Build();

            var response = mediator.Authorize(principal);

            response.AssertMessage(AgencyUserMediatorCodes.Authorize.MissingServicePermission, AuthorizeMessages.MissingServicePermission, UserMessageLevel.Error);
        }
        public void Authorize_EmptyUsername()
        {
            var principal = new ClaimsPrincipalBuilder().Build();

            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(c => c.Get <ManageWebConfiguration>())
            .Returns(new ManageWebConfiguration {
                AuthorisationGroupClaim = ValidAuthorisationGroupClaim
            });

            var mediator = new AgencyUserMediatorBuilder().With(configurationService).Build();

            var response = mediator.Authorize(principal);

            response.AssertMessage(AgencyUserMediatorCodes.Authorize.EmptyUsername, AuthorizeMessages.EmptyUsername, UserMessageLevel.Error);
        }
        public void Authenticated_SessionReturnUrlNotAllowed()
        {
            const string returnUrl        = "http://notallowedurl.com/";
            var          userDataProvider = new Mock <IUserDataProvider>();

            userDataProvider.Setup(p => p.Pop(UserDataItemNames.ReturnUrl)).Returns(returnUrl);

            var configurationService = new Mock <IConfigurationService>();

            configurationService.Setup(c => c.Get <ManageWebConfiguration>())
            .Returns(new ManageWebConfiguration {
                AuthorisationGroupClaim = ValidAuthorisationGroupClaim
            });

            var mediator = new AgencyUserMediatorBuilder().With(userDataProvider).With(configurationService).Build();

            var principal = new ClaimsPrincipalBuilder().WithName("User001").WithGroup(ValidAuthorisationGroupClaim).Build();

            var response = mediator.Authorize(principal);

            response.AssertCodeAndMessage(AgencyUserMediatorCodes.Authorize.Ok);
        }