Exercise 3: Testing Cart ActionsIn this exercise, you will learn how to test the main functionality of the ShoppingCartController: adding items to the cart, removing items and displaying the cart’s content. In order to simulate those actions, the tests you will implement will use a TestCartIdProvider instance that will return a new Guid object to simulate the ID of the cart to handle for the test. The MvcMusicStore project, the one used for the application itself, behaves differently: another provider works with the user’s session to store and retrieve the cart ID. Task 1 – Running ShoppingCartController TestsIn this task you will run the 3 tests you will be implementing later during this Exercise. Since they are not implemented with the correct content yet, they will fail.
Task 2 – Implementing the test for the AddToCart action methodIn this task you will implement the test for the AddToCart action method of the ShoppingCart Controller. The AddToCart method receives an album ID that is used to retrieve the album from the database, add it to the shopping cart and then returns the Index View template that will display that album as part of the cart.
Task 3 – Implementing the test for the Index action methodIn this task you will implement the test for the Index action method of the ShoppingCart Controller. The Index method populates a ShoppingCartViewModel object with the cart items and its total cost in order to display them with the corresponding View template.
Task 4 – Implementing the test for the RemoveFromCart action methodIn this task you will implement the test for the RemoveFromCart action method of the ShoppingCart Controller. The RemoveFromCart receives the ID of the album to remove, used for invoking the RemoveFromCart method of the ShoppingCart Model class and then it displays a confirmation message.
Next Step |