public void GetOfferForItem_NoOffer() { IOfferManager sut = new OfferManagerImpl(_mockLogger.Object); Item item = aValidCoconut; Assert.Null(sut.GetOfferForItem(item)); }
public void GetOfferForItem(string itemId, decimal expectedPrice, int expectedQuantity) { IOfferManager sut = new OfferManagerImpl(_mockLogger.Object); Item item = validItems.First(i => i.Id == itemId); Offer offer = sut.GetOfferForItem(item); Assert.True(offer.Price == expectedPrice); Assert.True(offer.Qtity == expectedQuantity); }
public void GetBasketTotal_Offers(int apples, int biscuits, int coconuts, decimal expectedBasketTotal) { IBasketManager sut = new BasketManagerImpl(_mockLogger.Object); IOfferManager offerManager = new OfferManagerImpl(_mockLogger.Object); Basket myBasket = new Basket() { Id = "My test basket", Items = new Dictionary <Item, int>() { { aValidApple, apples }, { aValidBiscuit, biscuits }, { aValidCoconut, coconuts } } }; Assert.True(sut.GetTotal(myBasket, offerManager) == expectedBasketTotal); }
public string GetTotal() { string total = ""; try { IBasketManager basketManager = new BasketManagerImpl(_log); IOfferManager offerManager = new OfferManagerImpl(_log); string totalWithoutOffers = basketManager.GetTotal(basket).ToString(); string totalWithOffers = basketManager.GetTotal(basket, offerManager).ToString(); StringBuilder sb = new StringBuilder(); sb.AppendLine($"Total without offers: {totalWithoutOffers}"); sb.AppendLine($"Total with offers: {totalWithOffers}"); total = sb.ToString(); } catch (Exception ex) { _log.LogCritical(ex, $"{nameof(BasketController)}.{nameof(GetTotal)} failed"); } return(total); }
public string Post([FromBody] Item item) { string message = ""; try { if (item == null) { throw new FormatException("Item is null"); } if (!validItems.Contains(item.Id)) { throw new FormatException($"Item of id {item.Id} is not supported"); } if (item.Price <= 0.00m) { throw new FormatException($"Price can't be null or negative"); } if (String.IsNullOrEmpty(item.Name)) { throw new FormatException($"Name can't be empty"); } IItemManager itemManager = new ItemManagerImpl(_log); bool success = itemManager.AddItemToBasket(item, ref basket); IBasketManager basketManager = new BasketManagerImpl(_log); IOfferManager offerManager = new OfferManagerImpl(_log); string total = basketManager.GetTotal(basket, offerManager).ToString(); StringBuilder sb = new StringBuilder(); if (success) { sb.AppendLine($"Successfully added item {item.Name} to basket {basket.Id}"); } else { sb.AppendLine($"Failed to add item {item.Name} to basket {basket.Id}"); } sb.AppendLine($"Current total with offers is: £{total}"); message = sb.ToString(); } catch (FormatException fex) { _log.LogInformation(fex, "Bad Item"); message = fex.Message; } catch (Exception ex) { _log.LogCritical(ex, "Failed to add an item"); message = ex.Message; } return(message); }
public void GetOfferForItem_NullItem() { IOfferManager sut = new OfferManagerImpl(_mockLogger.Object); Assert.Null(sut.GetOfferForItem(null)); }
public void Constructor() { IOfferManager sut = new OfferManagerImpl(_mockLogger.Object); Assert.NotNull(sut); }