To illustrate the issues that the singleton pattern addresses, let's start with a simple unit test that adds 30 books to the repository, updates the quantity of the different books, and then verifies the result. The following code shows the overall unit test, and we will explain each step individually:
[TestClass]public class InventoryContextTests{ [TestMethod] public void MaintainBooks_Successful() { var context = new InventoryContext(); // add thirty books ... // let's update the quantity of the books by adding 1, 2, 3, 4, 5 ... ... // let's update the quantity of the books by subtracting 1, 2, 3, 4, 5 ... ... // all quantities should be 0 ... } }
To add 30 books, the context instance is used to add books from Book_1 to