public void Validate_CohortReference_ShouldBeValidated(string cohortReference, bool expectedValid)
        {
            var model = new DeleteCohortViewModel {
                CohortReference = cohortReference
            };

            AssertValidationResult(request => request.CohortReference, model, expectedValid);
        }
        public void Validate_Confirm_ShouldBeValidated(bool?confirm, bool expectedValid)
        {
            var model = new DeleteCohortViewModel {
                Confirm = confirm
            };

            AssertValidationResult(request => request.Confirm, model, expectedValid);
        }
        public void Validate_ProviderId_ShouldBeValidated(int providerId, bool expectedValid)
        {
            var model = new DeleteCohortViewModel {
                ProviderId = providerId
            };

            AssertValidationResult(request => request.ProviderId, model, expectedValid);
        }
Ejemplo n.º 4
0
        public WhenGettingDeleteCohortFixture()
        {
            var fixture = new Fixture();

            _request         = fixture.Create <DeleteCohortRequest>();
            _modelMapperMock = new Mock <IModelMapper>();
            _viewModel       = fixture.Create <DeleteCohortViewModel>();

            _modelMapperMock
            .Setup(x => x.Map <DeleteCohortViewModel>(_request))
            .ReturnsAsync(_viewModel);

            Sut = new CohortController(Mock.Of <IMediator>(), _modelMapperMock.Object, Mock.Of <ILinkGenerator>(), Mock.Of <ICommitmentsApiClient>(), Mock.Of <IFeatureTogglesService <ProviderFeatureToggle> >(), Mock.Of <IEncodingService>());
        }
        public PostDeleteCohortFixture()
        {
            var fixture = new Fixture();

            _viewModel           = fixture.Create <DeleteCohortViewModel>();
            _userInfo            = fixture.Create <UserInfo>();
            _commitmentApiClient = new Mock <ICommitmentsApiClient>();

            _mockModelMapper       = new Mock <IModelMapper>();
            _authenticationService = new Mock <IAuthenticationService>();

            _authenticationService.Setup(x => x.UserInfo).Returns(_userInfo);

            _commitmentApiClient
            .Setup(x => x.DeleteCohort(_viewModel.CohortId, _userInfo, It.IsAny <CancellationToken>())).Returns(Task.FromResult(0));

            RedirectUrl    = $"{_viewModel.ProviderId}/apprentices/{_viewModel.CohortReference}/Details";
            _linkGenerator = new Mock <ILinkGenerator>();
            _linkGenerator.Setup(x => x.ProviderApprenticeshipServiceLink(RedirectUrl)).Returns(RedirectUrl);

            Sut = new CohortController(Mock.Of <IMediator>(), _mockModelMapper.Object, _linkGenerator.Object, _commitmentApiClient.Object, Mock.Of <IFeatureTogglesService <ProviderFeatureToggle> >(), Mock.Of <IEncodingService>());
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Delete([FromServices] IAuthenticationService authenticationService, DeleteCohortViewModel viewModel)
        {
            if (viewModel.Confirm.Value)
            {
                CommitmentsV2.Types.UserInfo userInfo = authenticationService.UserInfo;
                await _commitmentApiClient.DeleteCohort(viewModel.CohortId, userInfo);

                return(RedirectToAction("Review", new { viewModel.ProviderId }));
            }

            return(RedirectToAction(nameof(Details), new { viewModel.ProviderId, viewModel.CohortReference }));
        }
        private void AssertValidationResult <T>(Expression <Func <DeleteCohortViewModel, T> > property, DeleteCohortViewModel instance, bool expectedValid)
        {
            var validator = new DeleteCohortViewModelValidator();

            if (expectedValid)
            {
                validator.ShouldNotHaveValidationErrorFor(property, instance);
            }
            else
            {
                validator.ShouldHaveValidationErrorFor(property, instance);
            }
        }