Example #1
0
        public void Setup()
        {
            _addFromApprenticeshipDetailsModel = GetApprenticeshipDetailsRequestModel();
            _addFromApprenticeshipResultsModel = GetApprenticeshipResultsRequestModel();
            _addFromProviderDetailsModel       = GetProviderDetailsRequestModel();
            _addFromProviderSearchModel        = GetProviderResultsRequestModel();
            _deleteFromBasketViewModel         = GetDeleteFromBasketViewModel();

            // Set cookie in http request
            _mockMediator           = new Mock <IMediator>();
            _mockCookieManager      = new Mock <ICookieManager>();
            _mockBasketOrchestrator = new Mock <IBasketOrchestrator>();

            _mockBasketOrchestrator
            .Setup(orchestrator =>
                   orchestrator.UpdateBasket(It.IsAny <string>(), null, null))
            .ReturnsAsync(new AddOrRemoveFavouriteInBasketResponse());

            _mockMediator.Setup(s => s.Send(It.IsAny <GetBasketQuery>(), default(CancellationToken))).ReturnsAsync(GetApprenticeshipFavouritesBasketRead());

            _basketController = new BasketController(_mockMediator.Object, _mockCookieManager.Object, _mockBasketOrchestrator.Object);

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

            _basketController.TempData = tempData;
        }
        public void Setup()
        {
            _basketViewModel = new BasketViewModel <ApprenticeshipBasketItemViewModel>()
            {
                BasketId = Guid.Parse(_basketId)
            };

            _apprenticeshipFavouritesBasketRead = new ApprenticeshipFavouritesBasketRead(_apprenticeshipFavouritesBasket);

            _mediatorMock = new Mock <IMediator>();

            _mediatorMock
            .Setup(m => m.Send(It.IsAny <AddOrRemoveFavouriteInBasketCommand>(), CancellationToken.None))
            .ReturnsAsync(new AddOrRemoveFavouriteInBasketResponse());

            _basketViewModelMapperMock = new Mock <IBasketViewModelMapper>();
            _cookieManagerMock         = new Mock <ICookieManager>();
            _cacheStorageServiceMock   = new Mock <ICacheStorageService>();
            _cacheSettingsMock         = new Mock <ICacheSettings>();
            _configMock = new Mock <IFatConfigurationSettings>();

            _addFromApprenticeshipDetailsModel = GetApprenticeshipDetailsRequestModel();
            _addFromApprenticeshipResultsModel = GetApprenticeshipResultsRequestModel();
            _addFromProviderDetailsModel       = GetProviderDetailsRequestModel();
            _addFromProviderSearchModel        = GetProviderResultsRequestModel();
            _deleteFromBasketViewModel         = GetDeleteFromBasketViewModel();

            _basketViewModelMapperMock.Setup(s => s.Map(new ApprenticeshipFavouritesBasketRead(), It.IsAny <Guid>())).Returns(new BasketViewModel <ApprenticeshipBasketItemViewModel>());
            _basketViewModelMapperMock.Setup(s => s.Map(_apprenticeshipFavouritesBasketRead, It.IsAny <Guid>())).Returns(_basketViewModel);

            _basketOrchestrator = new BasketOrchestrator(_mediatorMock.Object, _cookieManagerMock.Object, _basketViewModelMapperMock.Object, _cacheStorageServiceMock.Object, _cacheSettingsMock.Object, _configMock.Object);
        }
        public async Task <IActionResult> RemoveFromBasket(DeleteFromBasketViewModel model)
        {
            // Check here if item being removed had TPs and is not a TP itself. If it has redirect to confirmation page.
            // else continue here as before.
            if (model.Ukprn == null)
            {
                if (await HasLinkedTrainingProviders(model.ApprenticeshipId))
                {
                    var returnPath = new Uri(Request.Headers["Referer"].ToString()).PathAndQuery;
                    return(RedirectToAction("RemoveConfirmation", "Basket",
                                            new
                    {
                        apprenticeshipId = model.ApprenticeshipId, returnPath
                    }));
                }
            }

            if (await IsInBasket(model.ApprenticeshipId, model.Ukprn))
            {
                await _basketOrchestrator.UpdateBasket(model.ApprenticeshipId, model.Ukprn);
            }

            return(RedirectToAction("View", "Basket"));
        }