public void DefaultsToQuantityOfOne() { var basket = new Basket(); basket.AddItem(_testCatalogItemId, _testUnitPrice); var firstItem = basket.Items.Single(); Assert.Equal(1, firstItem.Quantity); }
public void ReturnsTotalQuantityWithOneItem() { var basket = new Basket(_buyerId); basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity); var result = basket.TotalItems; Assert.Equal(_testQuantity, result); }
public void RemoveItem_From_Basket_Test() { var basket = new Basket(_username); basket.AddItem(_itemId, _price); basket.RemoveItem(_itemId); Assert.Equal(0, basket.BasketItems.Count); }
// [InlineData(10)] public async Task SetQuantityToZero_Removes_Item_From_Basket( int numInitiallItemsBasket, int numItemsToRemove ) { if (numInitiallItemsBasket < numItemsToRemove) { throw new Exception(); } var random = new Random(); var basketId = 10; var basket = new Basket(); var itemPrice = 10; // CREATE INITIAL BASKET foreach (var itemId in Enumerable.Range(1, numInitiallItemsBasket)) { { var initialQty = random.Next(1, 10); basket.AddItem(itemId, itemPrice, initialQty); } } foreach (var item in basket.Items) { item.Id = item.CatalogItemId; } // END INTIAL BASKET var initialItemsCount = basket.Items.Count; // targetItem.Id = itemId; _mockBasketRepo.Setup( x => x.GetByIdAsync(basketId)).ReturnsAsync(basket); var basketService = new BasketService(_mockBasketRepo.Object, null); // BEGIN DECIDE ITEMS TO REMOVE // var itemIdToRemove = random.Next(1, numInitiallItemsBasket); // var itemToRemove = basket.Items.Where(item => item.Id == itemIdToRemove).First(); var quantities = new System.Collections.Generic.Dictionary <string, int>(); foreach (var itemToRemove in basket.Items.Take(numItemsToRemove)) { quantities.Add(itemToRemove.Id.ToString(), 0); } // var numItemsToRemove = quantities.Count; // END DECIDE ITEMS TO REMOVE await basketService.SetQuantities( basketId, quantities); var expectedCount = initialItemsCount - numItemsToRemove; Assert.True(basket.Items.Count == expectedCount); _mockBasketRepo.Verify(x => x.UpdateAsync(basket), Times.Once()); }
public void WhenAnItemIsAdded_ThenBasketItemCountIncreases() { //Arrange var basket = new Basket(); //Act basket.AddItem(Guid.NewGuid(), 1, 1); //Assert basket.Items.Count.Should().Be(1); }
public ActionResult AddToBasketWithoutSize(Basket basket, int clothesID) { Product wear = _repository.Products.GetAll().Where(item => item.Article == clothesID).FirstOrDefault(); if (wear != null) { basket.AddItem(wear, 1); } return(PartialView("_AddToBasketPartial", basket)); }
public void AddItem_WithNonExistentBasketItem_ShouldReturnNewlyCreatedItem() { // Arrange var basket = new Basket(); // Act var item = basket.AddItem(1, 1, Pounds.Of(1)); // Assert Assert.NotNull(item); }
public void AddItem_WithNonExistentBasketItem_ShouldAddItemToList() { // Arrange var basket = new Basket(); // Act basket.AddItem(1, 1, Pounds.Of(1)); // Assert Assert.Equal(1, basket.Items.Count); }
public void AfterFiveDiffrerentItemThereShoulBeFiveItemsInTheBasket() { var basket = new Basket(); for (int i = 1; i < 6; i++) { basket.AddItem(i.ToString(), i, i, null); } basket.Items.Count.ShouldBe(5); }
public RedirectToRouteResult AddOneToBasket(Basket basket, int Id, string returnUrl) { Product product = repository.Products .FirstOrDefault(p => p.Id == Id); if (product != null) { basket.AddItem(product, 1); } return(RedirectToAction("Index", new { returnUrl })); }
public void AppliesMilkDiscountFor8() { var basket = new Basket(); basket.Id = _testBasketId; basket.AddItem(_testProductMilk); basket.ChangeItemQuantity(_testProductMilk, 8); basket.ApplyDiscount(); Assert.AreEqual(6.90m, basket.Total()); }
public void should_be_able_to_create_a_basket_and_apply_offers() { BasketService basketService = BasketServiceSetup(); var basket = new Basket(); basket.AddItem(new Product() { Price = 0.80m, Name = "Butter" }, 2); basket.AddItem(new Product() { Price = 1m, Name = "Bread" }, 1); basketService.ApplyOffers(basket); Assert.Equal(2.10m, basket.Total); }
public void Setup() { product = fixture.Create <Product>(); offersMock = fixture.Freeze <IList <Mock <IOffer> > >(); productRepoMock.Setup(p => p.GetProductByName(It.IsAny <string>())) .Returns(() => product); resultTotals = fixture.CreateMany <double>(offersMock.Count).ToList(); for (int i = 0; i < resultTotals.Count; i++) { offersMock[i].Setup(o => o.ApplyDiscount(It.IsAny <Basket>(), It.IsAny <double>())) .Returns(resultTotals[i]); } basket = fixture.Create <Basket>(); basket.AddItem(fixture.Create <Product>(), fixture.Create <int>()); basket.AddItem(fixture.Create <Product>(), fixture.Create <int>()); basket.AddItem(fixture.Create <Product>(), fixture.Create <int>()); }
public RedirectToRouteResult AddToBasket(Basket basket, int bookId, string returnUrl) { Book book = repository.Books.FirstOrDefault(b => b.BookId == bookId); if (book != null) { basket.AddItem(book, 1); } return(RedirectToAction("Index", new { returnUrl })); }
public void AddItem_To_Basket_With_Quantity_Test() { var basket = new Basket(_username); basket.AddItem(_itemId, _price, _quantity); var item = basket.BasketItems.First(); Assert.Equal(_itemId, item.ItemId); Assert.Equal(_price, item.Price); Assert.Equal(_quantity, item.Quantity); }
public void Save_added_items() { basketRepository = new Mock <IBasketRepository>(); summaryPrinter = new Mock <ISummaryPrinter>(); var basket = new Basket(basketRepository.Object, summaryPrinter.Object); var product = new Product("Bread", 1.50); var item = new BasketItem(product, 1); basket.AddItem(item); basketRepository.Verify(x => x.AddItem(item)); }
public void PercentageOffPromotion_MultipleD_ReturnsTotalDiscountedPrice() { //Arrange var priceStrategies = new IItemPriceStrategy[] { new BasketItemSkuDItemPriceStrategy() }; var basket = new Basket(); basket.AddItem(new BasketItemSkuD()); basket.AddItem(new BasketItemSkuD()); var basketService = new BasketService(basket, priceStrategies); //Act var totalPrice = basketService.GetTotal(); //Assert Assert.Equal((decimal)82.50, totalPrice); }
public void AddsBasketItemIfNotPresent() { var basket = new Basket(_buyerId); basket.AddItem(_testCatalogItemId, _testUnitPrice, _testQuantity); var firstItem = basket.Items.Single(); Assert.Equal(_testCatalogItemId, firstItem.CatalogItemId); Assert.Equal(_testUnitPrice, firstItem.UnitPrice); Assert.Equal(_testQuantity, firstItem.Quantity); }
public void AddItem_SingleItemOnce_SingleLineWithQuantity1() { var basket = new Basket(); basket.AddItem(_mockStockItemA); Assert.That(basket.LineItems.Count(), Is.EqualTo(1)); var lineItem = basket.LineItems.Single(); Assert.That(lineItem.Quantity, Is.EqualTo(1)); Assert.That(lineItem.StockItem.SKU, Is.EqualTo(_mockStockItemA.SKU)); }
public void Given_IHaveSelectedToAddAnItemToTheBasket_ThenTheItemShouldBeAddedToTheBasket() { // Arrange var basket = new Basket(); var item = new Item(sku: 'A', unitPrice: 10); // Act basket.AddItem(item); // Assert Assert.AreEqual(expected: 1, actual: basket.ItemsCount); }
public void ItemAdded() { //Arrange var basket = new Basket(); var basketItem = new BasketItemSkuA(); //Act basket.AddItem(basketItem); //Assert Assert.NotEmpty(basket.Items); }
public void WhenAProductsAreAddedAgainThenTheBasketContainsTheCorrectItems() { var basket = new Basket(); basket.AddItem(new Product("Dove Soap", 39.99m), 5); basket.AddItem(new Product("Dove Soap", 39.99m), 3); basket.Items().Should().BeEquivalentTo( new[] { new { Product = new { Name = "Dove Soap", Price = 39.99m }, Quantity = 8 } }); }
public void CalculatesPricesWithoutDiscounts() { var basket = new Basket(); basket.Id = _testBasketId; basket.AddItem(_testProductButter); basket.ChangeItemQuantity(_testProductButter, 2); basket.AddItem(_testProductMilk); basket.ChangeItemQuantity(_testProductMilk, 8); basket.AddItem(_testProductBread); basket.ChangeItemQuantity(_testProductBread, 1); var basketItemButter = basket.Items.FirstOrDefault(i => i.Product.Name == "Butter"); var basketItemMilk = basket.Items.FirstOrDefault(i => i.Product.Name == "Milk"); var basketItemBread = basket.Items.FirstOrDefault(i => i.Product.Name == "Bread"); Assert.AreEqual(1.60m, basketItemButter.Total); Assert.AreEqual(9.20m, basketItemMilk.Total); Assert.AreEqual(1m, basketItemBread.Total); Assert.AreEqual(11.80m, basket.Total()); }
public void TestQuantityIfOnlyOneExists() { var basket = new Basket(); basket.AddItem(_testItemdId, _testQuantity, _testUnitPrice, _testName); var firstItem = basket.Items.Single(); firstItem.Quantity.ShouldBe(_testQuantity); firstItem.Name.ShouldBe(_testName); firstItem.UnitPrice.ShouldBe(_testUnitPrice); }
public void AddsBasketItemIfNotPresent() { Basket basket = new Basket(); basket.AddItem(_productItemId, _testUnitPrice, _testQuantity); BasketItem firstItem = basket.Items.Single(); firstItem.ProductItemId.Should().Be(_productItemId); firstItem.UnitPrice.Should().Be(_testUnitPrice); firstItem.Quantity.Should().Be(_testQuantity); }
public void Given_IHaveSelectedToAddAnItemToTheBasket_Then_TheItemShouldBeAddedToTheBasket() { //Arrange var item = new ItemA(); var basket = new Basket(); //Act basket.AddItem(item); //Assert Assert.AreEqual(1, basket.GetItems().Count); }
public void ItemPresentInBasketCanBeRemoved() { var sut = new Basket(); sut.AddItem(_catalogueItemId, _unitPrice, _quantity); sut.RemoveItem(_catalogueItemId); var item = sut.Items.FirstOrDefault(); Assert.IsNull(item); }
public ActionResult AddToBasketWithSize(Basket basket, int clothesID, string size) { Product wear = _repository.Products.GetAll().Where(item => item.Article == clothesID).FirstOrDefault(); Size sizeName = wear.Sizes.First(x => x.SizeName == size); if (wear != null && sizeName != null) { basket.AddItem(wear, 1, size); } return(PartialView("_AddToBasketPartial", basket)); }
public void AddItem_AddTwoItemD_CorrectPrice() { // Arrange double expected = 82.5; Basket checkout = new Basket(); Item A = new Item(0, 10, "none"); Item B = new Item(0, 15, "3 for 40"); Item C = new Item(0, 40, "none"); Item D = new Item(0, 55, "25% off for every 2 purchased together"); Item[] basket = { A, B, C, D }; // Act checkout.AddItem(D, basket); checkout.AddItem(D, basket); // Assert double actual = checkout.basketTotal; Assert.AreEqual(expected, actual); }
public void Quantity_in_Basket_cannot_be_negative() { var expectedItem = new BasketItem(new CatalogItem("Item 1", "1234item", 10.50), 5); var basket = new Basket(new List <BasketItem>()); basket.AddItem(expectedItem); Assert.IsTrue(basket.ReturnItemQuantity(expectedItem.CatalogItem.ItemId) == 5); expectedItem.SetQuantity(100); basket.RemoveItem(expectedItem); Assert.IsTrue(basket.ReturnItemQuantity(expectedItem.CatalogItem.ItemId) == 0); }