public async Task Handle_ShouldRemoveApprenticeFromBasket_IfApprenticeshipAlreadyInBasket()
        {
            var basketId = Guid.NewGuid();
            var basket   = new ApprenticeshipFavouritesBasket {
                Id = basketId
            };

            basket.Add("123", 23456, "TestProvider");
            basket.Add("123", 12345, "TestProvider");

            _mockBasket.Setup(x => x.GetAsync(basketId)).ReturnsAsync(basket);

            var request = new AddOrRemoveFavouriteInBasketCommand
            {
                BasketId         = basketId,
                ApprenticeshipId = "123"
            };

            await _sut.Handle(request, default(CancellationToken));

            _mockBasket.Verify(x => x.UpdateAsync(It.IsAny <ApprenticeshipFavouritesBasket>()), Times.Once);

            basket.Should().NotBeNull();
            basket.Should().BeEmpty();
        }
        public async Task Handle_ShouldDeleteTrainingProviderLocationFromExistingBasket_WhenProviderLocationHasAlreadyBeenAddedForApprenticeship()
        {
            var basketId = Guid.NewGuid();
            var basket   = new ApprenticeshipFavouritesBasket {
                Id = basketId
            };

            basket.Add("123", 12345678, "TestProvider", 10000020);
            basket.Add("123", 23456789, "TestProvider", 10000030);

            _mockBasket.Setup(x => x.GetAsync(basketId)).ReturnsAsync(basket);

            ApprenticeshipFavouritesBasket savedBasket = null; // Setup callback so we can check contents of basket easier.

            _mockBasket.Setup(x => x.UpdateAsync(It.IsAny <ApprenticeshipFavouritesBasket>()))
            .Returns(Task.CompletedTask)
            .Callback <ApprenticeshipFavouritesBasket>((a) => savedBasket = a);

            var request = new AddOrRemoveFavouriteInBasketCommand
            {
                BasketId         = basketId,
                ApprenticeshipId = "123",
                Ukprn            = 12345678,
                LocationId       = 10000020
            };

            var response = await _sut.Handle(request, default(CancellationToken));

            _mockBasket.Verify(x => x.UpdateAsync(It.IsAny <ApprenticeshipFavouritesBasket>()), Times.Once);

            var favourite = savedBasket.SingleOrDefault(x => x.ApprenticeshipId == "123");

            favourite.Should().NotBeNull();
            favourite.Providers.Count.Should().Be(1);
        }
        public async Task SaveBasket_UpdatesFavourites_ForGivenEmployerAccount()
        {
            _basket.Add("40");

            var result = await Sut.SaveBasket(Guid.NewGuid());

            _mockFavouritesWriteRepository.Verify(x =>
                                                  x.SaveApprenticeshipFavourites(EMPLOYER_ACCOUNT_ID, It.IsAny <WriteModel.ApprenticeshipFavourites>()),
                                                  Times.Once);
        }
        public async Task Handle_AddsApprenticeshipToExistingBasket_ForNewApprenticeship()
        {
            var basketId = Guid.NewGuid();
            var basket   = new ApprenticeshipFavouritesBasket {
                Id = basketId
            };

            basket.Add("111");

            _mockBasket.Setup(x => x.GetAsync(basketId)).ReturnsAsync(basket);

            ApprenticeshipFavouritesBasket savedBasket = null; // Setup callback so we can check contents of basket easier.

            _mockBasket.Setup(x => x.UpdateAsync(It.IsAny <ApprenticeshipFavouritesBasket>()))
            .Returns(Task.CompletedTask)
            .Callback <ApprenticeshipFavouritesBasket>((a) => savedBasket = a);

            var request = new AddOrRemoveFavouriteInBasketCommand
            {
                BasketId         = basketId,
                ApprenticeshipId = "123"
            };

            var response = await _sut.Handle(request, default(CancellationToken));

            response.ApprenticeshipName.Should().Be("Standard 1");
            response.BasketId.Should().Be(basketId);
            response.BasketOperation.Should().Be(BasketOperation.Added);
            _mockBasket.Verify(x => x.UpdateAsync(It.Is <ApprenticeshipFavouritesBasket>(b => b.Count() == 2)));

            savedBasket.SingleOrDefault(x => x.ApprenticeshipId == "123").Should().NotBeNull();
        }
Пример #5
0
        private static ApprenticeshipFavouritesBasketRead GetApprenticeshipFavouritesBasketRead()
        {
            var basket = new ApprenticeshipFavouritesBasket();

            basket.Add(APPRENTICESHIP_ID, UKPRN, PROVIDER_NAME);

            return(new ApprenticeshipFavouritesBasketRead(basket));
        }
        public Task <ApprenticeshipFavouritesBasket> GetAsync(Guid basketId)
        {
            var basket = new ApprenticeshipFavouritesBasket();

            basket.Add("123456");

            return(Task.FromResult(basket));
        }
        private ApprenticeshipFavouritesBasket CreateNewBasket(AddOrRemoveFavouriteInBasketCommand request)
        {
            var basket = new ApprenticeshipFavouritesBasket();

            if (request.Ukprn.HasValue && request.LocationId.HasValue)
            {
                var providerName = _providerApiClient.Get(request.Ukprn.Value).ProviderName;
                basket.Add(request.ApprenticeshipId, request.Ukprn.Value, providerName, request.LocationId.Value);
            }
            else if (request.Ukprn.HasValue)
            {
                var providerName = _providerApiClient.Get(request.Ukprn.Value).ProviderName;
                basket.Add(request.ApprenticeshipId, request.Ukprn.Value, providerName);
            }
            else
            {
                basket.Add(request.ApprenticeshipId);
            }

            return basket;
        }
        public async Task Handle_AddsTrainingProviderLocationToExistingBasket_ForExistingApprenticeshipAndProviderWithExistingLocations()
        {
            var basketId = Guid.NewGuid();
            var basket   = new ApprenticeshipFavouritesBasket {
                Id = basketId
            };

            basket.Add("123", 12345678, "TestProvider", 10000030);

            _mockBasket.Setup(x => x.GetAsync(basketId)).ReturnsAsync(basket);

            ApprenticeshipFavouritesBasket savedBasket = null; // Setup callback so we can check contents of basket easier.

            _mockBasket.Setup(x => x.UpdateAsync(It.IsAny <ApprenticeshipFavouritesBasket>()))
            .Returns(Task.CompletedTask)
            .Callback <ApprenticeshipFavouritesBasket>((a) => savedBasket = a);

            var request = new AddOrRemoveFavouriteInBasketCommand
            {
                BasketId         = basketId,
                ApprenticeshipId = "123",
                Ukprn            = 12345678,
                LocationId       = 10000020
            };

            var response = await _sut.Handle(request, default(CancellationToken));

            response.ApprenticeshipName.Should().Be("Standard 1");
            response.BasketId.Should().Be(basketId);
            response.BasketOperation.Should().Be(BasketOperation.Added);
            _mockBasket.Verify(x => x.UpdateAsync(It.Is <ApprenticeshipFavouritesBasket>(b => b.Count() == 1)));

            var favourite = savedBasket.SingleOrDefault(x => x.ApprenticeshipId == "123");

            favourite.Should().NotBeNull();
            favourite.Providers.Should().NotBeNull();
            favourite.Providers.Count.Should().Be(1);
            favourite.Providers.First().Ukprn.Should().Be(12345678);
            favourite.Providers.First().Locations.Count().Should().Be(2);
            favourite.Providers.First().Locations.Contains(10000020);
            favourite.Providers.First().Name.Should().Be("TestProvider");
        }
        public void Setup()
        {
            _mockBasket    = new Mock <IApprenticeshipFavouritesBasketStore>();
            _mockFramework = new Mock <IGetFrameworks>();
            _mockStandard  = new Mock <IGetStandards>();
            _mockProviders = new Mock <IGetProviderDetails>();

            _mockStandard.Setup(s => s.GetStandardById(It.IsAny <string>())).Returns(new Standard()
            {
                Title = "Title", Level = 2, Duration = 18
            });

            _sut = new GetBasketHandler(new NullLogger <GetBasketHandler>(), _mockBasket.Object, _mockStandard.Object, _mockFramework.Object, _mockProviders.Object);

            var basket = new ApprenticeshipFavouritesBasket();

            basket.Add("23");

            _mockBasket.Setup(x => x.GetAsync(It.IsAny <Guid>())).ReturnsAsync(basket);
        }
        public new void Setup()
        {
            base.Setup();

            var cookieBasketId = Guid.NewGuid();

            _mockCookieManager = new Mock <ICookieManager>();
            _mockCookieManager.Setup(x => x.Get(CookieNames.BasketCookie)).Returns(cookieBasketId.ToString());

            var basket = new ApprenticeshipFavouritesBasket();

            basket.Add("420-2-1", UKPRN, PROVIDER_NAME);

            _mockMediator = new Mock <IMediator>();
            _mockMediator.Setup(x => x.Send(It.Is <GetBasketQuery>(a => a.BasketId == cookieBasketId), default(CancellationToken)))
            .ReturnsAsync(new ApprenticeshipFavouritesBasketRead(basket));

            _sut = new AddOrRemoveFromBasketViewComponent(_mockMediator.Object, _mockCookieManager.Object)
            {
                ViewComponentContext = _viewComponentContext
            };
        }
Пример #11
0
        public async Task Handle_RemoveBasket()
        {
            var basketId = Guid.NewGuid();

            var basket = new ApprenticeshipFavouritesBasket {
                Id = basketId
            };

            basket.Add("123", 12345678, "Test Provider");

            _mockBasket.Setup(x => x.GetAsync(basketId)).ReturnsAsync(basket);

            _mockBasket.Setup(x => x.RemoveAsync(basketId))
            .Returns(Task.CompletedTask);

            var request = new RemoveBasketCommand
            {
                BasketId = basketId
            };

            await _sut.Handle(request, default(CancellationToken));

            _mockBasket.Verify(x => x.RemoveAsync(basketId), Times.Once());
        }