public WhenPostingViewApprenticeshipUpdatesFixture()
            {
                _apiClient = new Mock <ICommitmentsApiClient>();
                _apiClient.Setup(x => x.UndoApprenticeshipUpdates(It.IsAny <long>(), It.IsAny <UndoApprenticeshipUpdatesRequest>(),
                                                                  It.IsAny <CancellationToken>())).Returns(Task.CompletedTask);

                _modelMapper = new Mock <IModelMapper>();

                _viewModel = new ViewApprenticeshipUpdatesViewModel
                {
                    ApprenticeshipId       = 123,
                    ApprenticeshipHashedId = "DF34WG2",
                    ProviderId             = 2342
                };

                var tempData    = new TempDataDictionary(new DefaultHttpContext(), Mock.Of <ITempDataProvider>());
                var autoFixture = new Fixture();

                UserInfo = autoFixture.Create <UserInfo>();
                AuthenticationService = new Mock <IAuthenticationService>();
                AuthenticationService.Setup(x => x.UserInfo).Returns(UserInfo);

                _sut = new ApprenticeController(_modelMapper.Object, Mock.Of <ICookieStorageService <IndexRequest> >(), _apiClient.Object);

                _sut.TempData = tempData;
            }
Example #2
0
        public void WhenUndoChangesIsTrue_ThenValidatorReturnsValid(ViewApprenticeshipUpdatesViewModel viewModel)
        {
            viewModel.UndoChanges = true;

            var result = _validator.Validate(viewModel);

            Assert.True(result.IsValid);
        }
Example #3
0
        public void WhenUndoChangesIsNull_ThenValidatorReturnsInvalid(ViewApprenticeshipUpdatesViewModel viewModel)
        {
            viewModel.UndoChanges = null;

            var result = _validator.Validate(viewModel);

            Assert.False(result.IsValid);
        }
        public WhenPostingViewApprenticeshipUpdatesTestsFixture() : base()
        {
            ViewModel = new ViewApprenticeshipUpdatesViewModel {
                ApprenticeshipId = 1, AccountId = 1
            };
            _controller.TempData = new TempDataDictionary(Mock.Of <HttpContext>(), Mock.Of <ITempDataProvider>());

            var autoFixture = new Fixture();

            UserInfo = autoFixture.Create <UserInfo>();
            AuthenticationService = new Mock <IAuthenticationService>();
            AuthenticationService.Setup(x => x.UserInfo).Returns(UserInfo);
        }
        public async Task <IActionResult> ViewApprenticeshipUpdates([FromServices] IAuthenticationService authenticationService, ViewApprenticeshipUpdatesViewModel viewModel)
        {
            if (viewModel.UndoChanges.Value)
            {
                var request = new UndoApprenticeshipUpdatesRequest
                {
                    ApprenticeshipId = viewModel.ApprenticeshipId,
                    ProviderId       = viewModel.ProviderId,
                    UserInfo         = authenticationService.UserInfo
                };

                await _commitmentsApiClient.UndoApprenticeshipUpdates(viewModel.ApprenticeshipId, request);

                TempData.AddFlashMessage(ChangesUndoneFlashMessage, ITempDataDictionaryExtensions.FlashMessageLevel.Success);
            }

            return(RedirectToRoute(RouteNames.ApprenticeDetail, new { viewModel.ProviderId, viewModel.ApprenticeshipHashedId }));
        }