public void CreateWithDbError() { //Arrange var controller = new ItemController(new ItemBLL(new ItemServiceStub())); var forventet = new Item(); forventet.ItemDesc = ""; //Act var actionResult = (RedirectToRouteResult)controller.Create(forventet); //Assert Assert.AreEqual(actionResult.RouteName, ""); }
public void CreateOK() { var controller = new ItemController(new ItemBLL(new ItemServiceStub())); var forventet = new Item { ItemID = 1, ItemCode = "DFGHJ", ItemDesc = "Dette er et kjempebra produkt", Category = 1, ImgPath = "", InStock = 5, Price = 100 }; var actionResult = (RedirectToRouteResult)controller.Create(forventet); Assert.AreEqual(actionResult.RouteName, ""); Assert.IsTrue(actionResult.RouteValues.Values.Count == 1); Assert.AreEqual(actionResult.RouteValues.Values.First(), "Index"); }
public void CreateWithModelError() { //Arrange var controller = new ItemController(new ItemBLL(new ItemServiceStub())); var forventet = new Item(); controller.ViewData.ModelState.AddModelError("ItemDesc", ""); //Act var actionResult = (ViewResult)controller.Create(forventet); //Assert Assert.IsTrue(actionResult.ViewData.ModelState.Count == 1); Assert.AreEqual(actionResult.ViewName, ""); }
public void ItemList() { //Arrange var controller = new ItemController(new ItemBLL(new ItemServiceStub())); List<Item> forventetListe = new List<Item>(); var Item = new Item { ItemID = 1, ItemCode = "DFGHJ", ItemDesc = "Dette er et kjempebra produkt", Category = 1, ImgPath = "", InStock = 5, Price = 100 }; forventetListe.Add(Item); forventetListe.Add(Item); forventetListe.Add(Item); //Act var actionResultat = (ViewResult)controller.Index(); var resultat = (List<Item>)actionResultat.Model; //Result Assert.AreEqual(actionResultat.ViewName, ""); for(var i = 0; i < resultat.Count; i++) { Assert.AreEqual(forventetListe[i].ItemID, resultat[i].ItemID); Assert.AreEqual(forventetListe[i].ItemCode, resultat[i].ItemCode); Assert.AreEqual(forventetListe[i].ItemDesc, resultat[i].ItemDesc); Assert.AreEqual(forventetListe[i].InStock, resultat[i].InStock); Assert.AreEqual(forventetListe[i].ImgPath, resultat[i].ImgPath); Assert.AreEqual(forventetListe[i].Category, resultat[i].Category); Assert.AreEqual(forventetListe[i].Price, resultat[i].Price); } }
public void GetItemsAsJson() { //Arrange var controller = new ItemController(new ItemBLL(new ItemServiceStub())); List<Item> forventetListe = new List<Item>(); var Item = new Item { ItemID = 1, ItemCode = "DFGHJ", ItemDesc = "Dette er et kjempebra produkt", Category = 1, ImgPath = "", InStock = 5, Price = 100 }; forventetListe.Add(Item); forventetListe.Add(Item); forventetListe.Add(Item); //Act var resultat = controller.GetItemsAsJson() as JsonResult; dynamic data = resultat.Data; //Assert for(var i = 0; i < forventetListe.Count; i++) { Assert.AreEqual(forventetListe[i].ItemID, data[i].ItemID); Assert.AreEqual(forventetListe[i].ItemCode, data[i].ItemCode); Assert.AreEqual(forventetListe[i].ItemDesc, data[i].ItemDesc); Assert.AreEqual(forventetListe[i].InStock, data[i].InStock); Assert.AreEqual(forventetListe[i].ImgPath, data[i].ImgPath); Assert.AreEqual(forventetListe[i].Category, data[i].Category); Assert.AreEqual(forventetListe[i].Price, data[i].Price); } }
public void DetailsValidID() { var controller = new ItemController(new ItemBLL(new ItemServiceStub())); var forventet = new Item { ItemID = 1, ItemCode = "DFGHJ", ItemDesc = "Dette er et kjempebra produkt", Category = 1, ImgPath = "", InStock = 5, Price = 100 }; var actionResultat = (ViewResult)controller.Details(1); var resultat = (Item)actionResultat.Model; Assert.AreEqual(forventet.ItemID, resultat.ItemID); Assert.AreEqual(forventet.ItemCode, resultat.ItemCode); Assert.AreEqual(forventet.ItemDesc, resultat.ItemDesc); Assert.AreEqual(forventet.InStock, resultat.InStock); Assert.AreEqual(forventet.ImgPath, resultat.ImgPath); Assert.AreEqual(forventet.Category, resultat.Category); Assert.AreEqual(forventet.Price, resultat.Price); }