Exemplo n.º 1
0
        public async Task Clear_OneOfTwoBaskets()
        {
            var prodRepo        = new MockRepository <Product>();
            var basketRepo      = new MockRepository <ProductInBasket>();
            var productsService = new ProductsService(prodRepo);
            var basketService   = new BasketService(basketRepo, productsService);

            var userId      = "UserA";
            var otherUserId = "UserB";

            basketService.Add(new ProductInBasket {
                Id = 1, ProductId = 2, UserId = userId, Count = 50
            });
            basketService.Add(new ProductInBasket {
                Id = 1, ProductId = 4, UserId = userId, Count = 2
            });
            basketService.Add(new ProductInBasket {
                Id = 2, ProductId = 2, UserId = otherUserId, Count = 50
            });

            basketService.Clear(userId);

            Assert.True(basketService.ItemsCount(userId) == 0);
            Assert.True(basketService.ItemsCount(otherUserId) == 50);
        }
Exemplo n.º 2
0
        async void Init()
        {
            bool res = await orderService.ApplyOrder();

            Message = res ? "Заказ успешно оформлен! Наш менеджер свяжется с Вами в ближайшее время." : orderService.ErrorMessage;
            basketService.Clear();
            servicesService.Clear();
        }
Exemplo n.º 3
0
        public async void Clearing_a_basket_should_delete_all_contents()
        {
            var sessionId  = Guid.NewGuid();
            var basketRepo = new Mock <IBasketStore>();

            basketRepo.Setup(x => x.Delete(It.IsAny <Guid>())).Returns(Task.CompletedTask);

            var sut    = new BasketService(basketRepo.Object, new PollyProvider());
            var result = await sut.Clear(sessionId);

            basketRepo.Verify(x => x.Delete(sessionId));
            Assert.True(result.WasSuccess);
        }
Exemplo n.º 4
0
        public async void Clearing_a_basket_should_error_on_final_retry()
        {
            var sessionId  = Guid.NewGuid();
            var basketRepo = new Mock <IBasketStore>();

            basketRepo.SetupSequence(x => x.Delete(It.IsAny <Guid>()))
            .Throws(new Exception())
            .Throws(new Exception())
            .Throws(new Exception())
            .Throws(new Exception("Test message"));

            var sut    = new BasketService(basketRepo.Object, new PollyProvider());
            var result = await sut.Clear(sessionId);

            Assert.False(result.WasSuccess);
            Assert.Equal("Test message", result.Errors.First().Message);
        }
Exemplo n.º 5
0
        public async Task Clear_ThreeItems()
        {
            var prodRepo        = new MockRepository <Product>();
            var basketRepo      = new MockRepository <ProductInBasket>();
            var productsService = new ProductsService(prodRepo);
            var basketService   = new BasketService(basketRepo, productsService);

            var userId = "UserA";

            basketService.Add(new ProductInBasket {
                Id = 1, ProductId = 2, UserId = userId, Count = 2
            });
            basketService.Add(new ProductInBasket {
                Id = 2, ProductId = 2, UserId = userId, Count = 1
            });

            basketService.Clear(userId);

            Assert.True(basketService.ItemsCount(userId) == 0);
        }
Exemplo n.º 6
0
        public void Clear_ShouldRemoveItemsFromBasket_AndCallUpdate()
        {
            // Given
            var basketId     = Guid.NewGuid();
            var basketEntity = new BasketEntity {
                BasketId = basketId, Items = new List <ItemEntity> {
                    new ItemEntity(), new ItemEntity()
                }
            };

            _basketStore.Setup(x => x.Get(basketId)).Returns(basketEntity);
            var basketViewModel = new BasketViewModel {
                BasketId = basketId
            };

            _basketMapper.Setup(x => x.MapFrom(basketEntity)).Returns(basketViewModel);

            // When
            var result = _basketService.Clear(basketId);

            // Then
            result.ShouldBe(basketViewModel);
            _basketStore.Verify(x => x.Update(It.Is <BasketEntity>(p => p.Items.Count == 0)));
        }