public void Endre_feil_validering_Post() { // Arrange var controller = new VareController(new VareBLL(new VareDALStub())); var innVare = new Vare(); controller.ViewData.ModelState.AddModelError("feil", "ID = 0"); // Act var actionResult = (ViewResult)controller.endreVare(0, innVare); // Assert Assert.IsTrue(actionResult.ViewData.ModelState.Count == 1); Assert.AreEqual(actionResult.ViewData.ModelState["feil"].Errors[0].ErrorMessage, "ID = 0"); Assert.AreEqual(actionResult.ViewName, ""); }
public void Endre_funnet() { // Arrange var controller = new VareController(new VareBLL(new VareDALStub())); var innVare = new Vare() { Varenavn = "eple", Pris = 5, Varebeholdning = 77 }; // Act var actionResultat = (RedirectToRouteResult)controller.endreVare(1, innVare); // Assert Assert.AreEqual(actionResultat.RouteName, ""); Assert.AreEqual(actionResultat.RouteValues.Values.First(), "VareListe"); }
public void Endre_ikke_funnet_Post() { // Arrange var controller = new VareController(new VareBLL(new VareDALStub())); var innKunde = new Vare() { ID = 1, Varenavn = "eple", Pris = 5, Varebeholdning = 77 }; // Act var actionResult = (ViewResult)controller.endreVare(0, innKunde); // Assert Assert.AreEqual(actionResult.ViewName, ""); }