public void AddInventoryCommand_Successful() { const string expectedBookName = "AddInventoryUnitTest"; var expectedInterface = new Helpers.TestUserInterface( new List <Tuple <string, string> > { new 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 result = command.RunCommand(); Assert.IsFalse(result.shouldQuit, "AddInventory is not a terminating command."); Assert.IsTrue(result.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 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 Initialize() { var expectedInterface = new Helpers.TestUserInterface( new List <Tuple <string, string> >(), new List <string>(), new List <string>() ); Factory = new InventoryCommandFactory(expectedInterface); }
public void Startup() { var expectedInterface = new Helpers.TestUserInterface( new List <Tuple <string, string> >(), new List <string>(), new List <string>() ); IServiceCollection services = new ServiceCollection(); services.AddSingleton <IInventoryContext, InventoryContext>(); services.AddTransient <Func <string, InventoryCommand> >(InventoryCommand.GetInventoryCommand); Services = services.BuildServiceProvider(); }
public void HelpCommand_Successful() { var expectedInterface = new Helpers.TestUserInterface( new List <Tuple <string, string> >(), new List <string> { "USAGE:", "\taddinventory (a)", "\tgetinventory (g)", "\tupdatequantity (u)", "\tquit (q)", "\t?", "Examples:", "\tNew Inventory", "\t> addinventory", "\tEnter name:The Meaning of Life", "", "\tGet Inventory", "\t> getinventory", "\tThe Meaning of Life Quantity:10", "\tThe Life of a Ninja Quantity:2", "", "\tUpdate Quantity (Increase)", "\t> updatequantity", "\tEnter name:The Meaning of Life", "\t11", "\t11 added to quantity", "", "\tUpdate Quantity (Decrease)", "\t> updatequantity", "\tEnter name:The Life of a Ninja", "\t-3", "\t3 removed from quantity", "" }, new List <string>() ); // create an instance of the command var command = new HelpCommand(expectedInterface); var result = command.RunCommand(); Assert.IsFalse(result.shouldQuit, "Help is not a terminating command."); Assert.IsTrue(result.wasSuccessful, "Help did not complete Successfully."); }
public void UnknownCommand_Successful() { var expectedInterface = new Helpers.TestUserInterface( new List <Tuple <string, string> >(), new List <string>(), new List <string> { "Unable to determine the desired command." } ); // create an instance of the command var command = new UnknownCommand(expectedInterface); var result = command.RunCommand(); Assert.IsFalse(result.shouldQuit, "Unknown is not a terminating command."); Assert.IsFalse(result.wasSuccessful, "Unknown should not complete Successfully."); }
public void UpdateQuantity_ExistingBook_Successful() { const string expectedBookName = "UpdateQuantityUnitTest"; var expectedInterface = new Helpers.TestUserInterface( new List <Tuple <string, string> > { new Tuple <string, string>("Enter name:", expectedBookName), new 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."); }
public void QuitCommand_Successful() { var expectedInterface = new Helpers.TestUserInterface( new List <Tuple <string, string> >(), // ReadValue() new List <string> // WriteMessage() { "Thank you for using FlixOne Inventory Management System" }, new List <string>() // WriteWarning() ); // create an instance of the command var command = new QuitCommand(expectedInterface); // add a new book with parameter "name" var result = command.RunCommand(); expectedInterface.Validate(); Assert.IsTrue(result.shouldQuit, "Quit is a terminating command."); Assert.IsTrue(result.wasSuccessful, "Quit did not complete Successfully."); }