public void ShouldReturnOrder() { // Arrange var fixture = new Fixture(); var controller = new CheckoutController(); var cart = fixture.CreateMany <CartItem>(); // Act var order = controller.Checkout(cart); // Assert order.Should().NotBeNull(); order.TotalQuantity.Should().Be(cart.Count()); order.TotalPrice.Should().Be(cart.Sum(item => item.Book.Price)); }
/// <summary> /// Method which represents rendering a view. /// Calls are made to the CheckoutConstructor based on user input. /// </summary> public static void Display() { const string checkoutTemplate = "1. Checkout Items\n" + "2. View Price Catalogue\n" + "3. View Promotion Catalogue\n" + "4. Sign Out\n" + "Please select an action: "; var input = ' '; while (input != '4') { // Show main screen Console.Write(checkoutTemplate); input = Console.ReadKey().KeyChar; Console.WriteLine(); var output = ""; switch (input) { // Start Checkout case '1': output += _checkoutController.Checkout(); break; // View Price Catalogue case '2': output += _checkoutController.ShowPriceCatalogue(); break; // View PromotionCatalogue case '3': output += _checkoutController.ShowPromotionCatalogue(); break; // Close the program case '4': output += "Signing out..."; break; // No match; try again default: output += $"Invalid Selection: Expected [1-4] - Recieved [{input}]"; break; } Console.WriteLine(output); } }
public static void Main() { // Load all data required to run the program var priceList = GroceryItemLoader.Load(File.ReadAllText(".\\GroceryItems.json")) .ToDictionary(i => i.Id, i => i); var promotions = PromotionLoader.Load(File.ReadAllText(".\\Promotions.json"), priceList); var basket = BasketItemLoader.Load(File.ReadAllText(".\\Basket.json")); // Instantiate the controller var controller = new CheckoutController(priceList, promotions); // Checkout the items var view = controller.Checkout(basket); // Render the view view.Render(); System.Console.WriteLine("Press a key to continue"); System.Console.ReadKey(); }