public void Add(HarryPotterBook book) { if(Contains(book)) throw new ArgumentException(book + " has already been added to this set. Each book " + "in the series can only be added once."); _booksInSeries.Add(book); }
public BookSeriesSet FindSetForBook(List<BookSeriesSet> sets, HarryPotterBook book) { var smallestMatchingSet = (from set in sets where !set.Contains(book) orderby set.Count select set).FirstOrDefault(); return smallestMatchingSet; }
public BookSeriesSet FindSetForBook(IEnumerable<BookSeriesSet> sets, HarryPotterBook book) { // works because the first sets in the collection get filled first var firstMatchingSet = (from set in sets where !set.Contains(book) select set).FirstOrDefault(); return firstMatchingSet; }
public bool Contains(HarryPotterBook book) { return _booksInSeries.Contains(book); }
public decimal Add(HarryPotterBook book) { cart.Add(book); return(CalculateTotal()); }
public void GivenIHaveEnteredCopyOfAHarryPotterBookIntoTheShoppingBasket(int harrypottercopies, int othercopies) { switch (harrypottercopies + "" + othercopies) { case "10": var book = new HarryPotterBook("Harry Potter and Philosopher's Stone"); basket.AddItems(book); break; case "20": basket.AddItems(new HarryPotterBook("Harry Potter and Philosopher's Stone")); basket.AddItems(new HarryPotterBook("Harry Potter and the Chamber of Secrets")); break; case "30": basket.AddItems(new HarryPotterBook("Harry Potter and Philosopher's Stone")); basket.AddItems(new HarryPotterBook("Harry Potter and the Chamber of Secrets")); basket.AddItems(new HarryPotterBook("Harry Potter and the Prizoner of Azkaban")); break; case "40": basket.AddItems(new HarryPotterBook("Harry Potter and Philosopher's Stone")); basket.AddItems(new HarryPotterBook("Harry Potter and the Chamber of Secrets")); basket.AddItems(new HarryPotterBook("Harry Potter and the Prizoner of Azkaban")); basket.AddItems(new HarryPotterBook("Harry Potter and the Goblet of Fire")); break; case "70": basket.AddItems(new HarryPotterBook("Harry Potter and Philosopher's Stone")); basket.AddItems(new HarryPotterBook("Harry Potter and the Chamber of Secrets")); basket.AddItems(new HarryPotterBook("Harry Potter and the Prizoner of Azkaban")); basket.AddItems(new HarryPotterBook("Harry Potter and the Order of the Phoenix")); basket.AddItems(new HarryPotterBook("Harry Potter and the Goblet of Fire")); basket.AddItems(new HarryPotterBook("Harry Potter and the Half-Blood Prince")); basket.AddItems(new HarryPotterBook("Harry Potter and the Deathly Hollows")); break; case "21": basket.AddItems(new HarryPotterBook("Harry Potter and Philosopher's Stone")); basket.AddItems(new HarryPotterBook("Harry Potter and the Chamber of Secrets")); basket.AddItems(new Book("Not a Harry POtter Book")); break; case "140": basket.AddItems(new HarryPotterBook("Harry Potter and Philosopher's Stone")); basket.AddItems(new HarryPotterBook("Harry Potter and the Chamber of Secrets")); basket.AddItems(new HarryPotterBook("Harry Potter and the Prizoner of Azkaban")); basket.AddItems(new HarryPotterBook("Harry Potter and the Order of the Phoenix")); basket.AddItems(new HarryPotterBook("Harry Potter and the Goblet of Fire")); basket.AddItems(new HarryPotterBook("Harry Potter and the Half-Blood Prince")); basket.AddItems(new HarryPotterBook("Harry Potter and the Deathly Hollows")); basket.AddItems(new HarryPotterBook("Harry Potter and Philosopher's Stone")); basket.AddItems(new HarryPotterBook("Harry Potter and the Chamber of Secrets")); basket.AddItems(new HarryPotterBook("Harry Potter and the Prizoner of Azkaban")); basket.AddItems(new HarryPotterBook("Harry Potter and the Order of the Phoenix")); basket.AddItems(new HarryPotterBook("Harry Potter and the Goblet of Fire")); basket.AddItems(new HarryPotterBook("Harry Potter and the Half-Blood Prince")); basket.AddItems(new HarryPotterBook("Harry Potter and the Deathly Hollows")); break; case "03": basket.AddItems(new Book("Other Book 1")); basket.AddItems(new Book("Other Book 2")); basket.AddItems(new Book("Other Book 3")); break; default: break; } }