Exercise 2: Testing CRUD actions
In this exercise, you will learn how to test CRUD actions that modify the database. One of the premises to take into account is that tests don’t necessarily run in a specific order. Another one is that every test could be executed as many times as needed. So your tests should not depend on previous tests executions. For instance, if your test is going to delete a record in the database, the setup of the test should provide the record to be deleted. This way, the test could be executed repeatedly.
Task 1 – Reviewing the provided solution
Some changes where performed to the end solution of the last exercise in order to prepare it for this one.
In this task, you will review those changes before moving on, in the following tasks, with the particular additions for testing CRUD actions.
Task 2 – Adding transaction capabilities to the Test Methods
In this task, you will learn how to use transactions to limit the scope of the test. This way, you could execute the test as many times as you want, without altering the database content.
Task 2 – Testing Create Action Method
In this task, you will learn how to test the creation of new records in the database by adding new albums.
Task 3 – Testing Delete Action Method
In this task, you will learn how to test the deletion of albums.
Task 4 – Testing Edit Action Method
In this task, you will learn how to test the HTTP-GET edit action method.
Task 5 – Testing Index Action Method
In this task, you will test the Index action method that obtains the list of genres from the store.
Task 6 – Testing Details Action Method
In this task, you will test the Details method. This method obtains a specific album based on its ID.
Task 7 – Testing Browse Action Method for StoreController
In this task, you will learn how to test the Browse method. This method returns a list of albums for a specific genre.