public void GetInventoryCommand_Successful() { var expectedInterface = new Helpers.TestUserInterface( new List <System.Tuple <string, string> >(), new List <string> { "Gremlins \tQuantity:7", "Willowsong \tQuantity:3", }, new List <string>() ); var context = new TestInventoryContext(new Dictionary <string, Book> { { "Gremlins", new Book { Id = 1, Name = "Gremlins", Quantity = 7 } }, { "Willowsong", new Book { Id = 2, Name = "Willowsong", Quantity = 3 } }, }); var command = new GetInventoryCommand(expectedInterface, context); var(wasSuccessful, shouldQuit) = command.RunCommand(); Assert.IsFalse(shouldQuit, "GetInventory is not a terminating command."); Assert.IsTrue(wasSuccessful, "GetInventory did not complete Successfully."); Assert.AreEqual(0, context.GetAddedBooks().Length, "GetInventory should not have added any books."); Assert.AreEqual(0, context.GetUpdatedBooks().Length, "GetInventory should not have updated any books."); }
public void AddInventoryCommand_Successful() { const string expectedBookName = "AddInventoryUnitTest"; var expectedInterface = new TestUserInterface( new List <System.Tuple <string, string> > { new System.Tuple <string, string>("Enter name:", expectedBookName) }, new List <string>(), new List <string>() ); var context = new TestInventoryContext(new Dictionary <string, Book> { { "Gremlins", new Book { Id = 1, Name = "Gremlins", Quantity = 7 } } }); // create an instance of the command var command = new AddInventoryCommand(expectedInterface, context); // add a new book with parameter "name" var(wasSuccessful, shouldQuit) = command.RunCommand(); Assert.IsFalse(shouldQuit, "AddInventory is not a terminating command."); Assert.IsTrue(wasSuccessful, "AddInventory did not complete Successfully."); // verify the book was added with the given name with 0 quantity Assert.AreEqual(1, context.GetAddedBooks().Length, "AddInventory should have added one new book."); var newBook = context.GetAddedBooks().First(); Assert.AreEqual(expectedBookName, newBook.Name, "AddInventory did not add book successfully."); }
public void UpdateQuantity_ExistingBook_Successful() { const string expectedBookName = "UpdateQuantityUnitTest"; var expectedInterface = new TestUserInterface( new List <System.Tuple <string, string> > { new System.Tuple <string, string>("Enter name:", expectedBookName), new System.Tuple <string, string>("Enter quantity:", "6") }, new List <string>(), new List <string>() ); var context = new TestInventoryContext(new Dictionary <string, Book> { { "Beavers", new Book { Id = 1, Name = "Beavers", Quantity = 3 } }, { expectedBookName, new Book { Id = 2, Name = expectedBookName, Quantity = 7 } }, { "Ducks", new Book { Id = 3, Name = "Ducks", Quantity = 12 } } }); // create an instance of the command var command = new UpdateQuantityCommand(expectedInterface, context); var result = command.RunCommand(); Assert.IsFalse(result.shouldQuit, "UpdateQuantity is not a terminating command."); Assert.IsTrue(result.wasSuccessful, "UpdateQuantity did not complete Successfully."); Assert.AreEqual(0, context.GetAddedBooks().Length, "UpdateQuantity should not have added one new book."); var updatedBooks = context.GetUpdatedBooks(); Assert.AreEqual(1, updatedBooks.Length, "UpdateQuantity should have updated one new book."); Assert.AreEqual(expectedBookName, updatedBooks.First().Name, "UpdateQuantity did not update the correct book."); Assert.AreEqual(13, updatedBooks.First().Quantity, "UpdateQuantity did not update book quantity successfully."); }