public void RegistrerBok_Post_OK() { var SessionMock = new TestControllerBuilder(); var controller = new AdminController(new AdminBLL(new AdminRepositoryStub())); SessionMock.InitializeController(controller); controller.Session["AdminLoggetInn"] = true; var forventetBok = new Boken() { ForfatterId = 100, SjangerId = 100, Tittel = "Isprinsessen", Pris = 399, Sjanger = "Krim", Forfatter = "Camilla Läckberg" }; // Act var result = (RedirectToRouteResult)controller.registrerBok(forventetBok); // Assert Assert.AreEqual(result.RouteName, ""); Assert.AreEqual(result.RouteValues.Values.First(), "hentAlleBoker"); }
public void RegistrerBok_Post_DB_feil() { var SessionMock = new TestControllerBuilder(); var controller = new AdminController(new AdminBLL(new AdminRepositoryStub())); SessionMock.InitializeController(controller); controller.Session["AdminLoggetInn"] = true; var forventetBok = new Boken(); forventetBok.Tittel = ""; // Act var actionResult = (ViewResult)controller.registrerBok(forventetBok); // Assert Assert.AreEqual(actionResult.ViewName, ""); }
public void RegistrerBok_Post_Model_feil() { var SessionMock = new TestControllerBuilder(); var controller = new AdminController(new AdminBLL(new AdminRepositoryStub())); SessionMock.InitializeController(controller); controller.Session["AdminLoggetInn"] = true; var forventetBok = new Boken(); controller.ViewData.ModelState.AddModelError("Tittel", "Ikke oppgitt tittel"); // Act var actionResult = (ViewResult)controller.registrerBok(forventetBok); // Assert Assert.IsTrue(actionResult.ViewData.ModelState.Count == 1); Assert.AreEqual(actionResult.ViewName, ""); }
public void registrerBok() { var SessionMock = new TestControllerBuilder(); var controller = new AdminController(new AdminBLL(new AdminRepositoryStub())); SessionMock.InitializeController(controller); controller.Session["AdminLoggetInn"] = true; // Act var actionResult = (ViewResult)controller.registrerBok(); // Assert Assert.AreEqual(actionResult.ViewName, ""); }