Beispiel #1
0
 public HomeModule()
 {
     Get["/"] = _ => {
     return View["index.cshtml"];
       };
       Get["/allItemsList"] = _ => {
     List<InventoryItem> allInventoryItems = InventoryItem.GetAll();
     return View["catalog.cshtml", allInventoryItems];
       };
       Post["/addItemEntry"] = _ => {
     if(InventoryItem.Search(Request.Form["name"]) == -1)
     {
       InventoryItem newEntry = new InventoryItem(Request.Form["name"],Request.Form["description"]);
       newEntry.Save();
       List<InventoryItem> allInventoryItems = InventoryItem.GetAll();
       return View["catalog.cshtml", allInventoryItems];
     }
     else
     {
       return View["error.cshtml"];
     }
       };
       Get["/deleteAll"] = _ => {
     InventoryItem.DeleteAll();
     List<InventoryItem> allInventoryItems = InventoryItem.GetAll();
     return View["catalog.cshtml", allInventoryItems];
       };
       Post["/deleteOne"] = _ => {
     InventoryItem.DeleteOne(Request.Form["deleteOneName"]);
     List<InventoryItem> allInventoryItems = InventoryItem.GetAll();
     return View["catalog.cshtml", allInventoryItems];
       };
 }
Beispiel #2
0
        public void Test_Save_AssignsIdToObject()
        {
            InventoryItem testInventoryItem = new InventoryItem("cat", "it's a cat");
              testInventoryItem.Save();

              InventoryItem foundInventoryItem = InventoryItem.Find(testInventoryItem.GetId());

              Assert.Equal(testInventoryItem, foundInventoryItem);
        }
Beispiel #3
0
        public void Test_DatabaseHasStuff()
        {
            //Arrange, Act
             InventoryItem newInventoryItem = new InventoryItem("cat", "it's a cat");
             newInventoryItem.Save();
             int result = InventoryItem.GetAll().Count;

             //Assert
             Assert.Equal(1, result);
        }
Beispiel #4
0
        public void Test_DeleteOne_DeletesGivenOne()
        {
            InventoryItem firstInventoryItem = new InventoryItem("cat", "it's a cat");
              firstInventoryItem.Save();
              InventoryItem secondInventoryItem = new InventoryItem("dog", "it's a dog");
              secondInventoryItem.Save();
              InventoryItem thirdInventoryItem = new InventoryItem("fish", "it's a fish");
              thirdInventoryItem.Save();

              InventoryItem.DeleteOne("dog");
              int newInventory=InventoryItem.GetAll().Count;

              Assert.Equal(2, newInventory);
        }
Beispiel #5
0
        public void Test_Save_SavesToDatabase()
        {
            //Arrange
              InventoryItem newInventoryItem = new InventoryItem("cat", "it's a cat");

              //Act
              newInventoryItem.Save();
              List<InventoryItem> result = InventoryItem.GetAll();
              List<InventoryItem> testList = new List<InventoryItem>{newInventoryItem};

              //Assert
              Assert.Equal(testList, result);
        }
Beispiel #6
0
        public void Test_Search_FindsIdByName()
        {
            InventoryItem testInventoryItem = new InventoryItem("cat", "it's a cat");
              testInventoryItem.Save();

              int result = InventoryItem.Search(testInventoryItem.GetName());

              Assert.Equal(testInventoryItem.GetId(), result);
        }
Beispiel #7
0
        public void Test_Search_DoesntFindIdForUnused()
        {
            InventoryItem testInventoryItem = new InventoryItem("cat", "it's a cat");
              testInventoryItem.Save();

              int result = InventoryItem.Search("dog");

              Assert.Equal(-1, result);
        }