Ejemplo n.º 1
0
        public void LagNy()
        {
            // Arrange

            var controller = new KategoriController(new KategoriLogikk(new KategoriRepositoryStub()));
            var builder = new TestControllerBuilder();
            builder.InitializeController(controller);

            controller.Session["AdminInnlogget"] = true;

            // Act

            var result = (ViewResult)controller.LagNy();

            // Assert

            Assert.AreEqual(result.ViewName, "");
        }
Ejemplo n.º 2
0
        public void LagNy_ikke_innlogget()
        {
            // Arrange

            var controller = new KategoriController(new KategoriLogikk(new KategoriRepositoryStub()));
            var builder = new TestControllerBuilder();
            builder.InitializeController(controller);

            controller.Session["AdminInnlogget"] = false;

            // Act

            var result = (RedirectToRouteResult)controller.LagNy();

            // Assert

            Assert.AreEqual(result.RouteName, "");
            Assert.AreEqual(result.RouteValues.Values.ElementAt(0), "Innlogging");
            Assert.AreEqual(result.RouteValues.Values.ElementAt(1), "Admin");
        }
Ejemplo n.º 3
0
        public void LagNy_POST_model_feil()
        {
            // Arrange

            var controller = new KategoriController(new KategoriLogikk(new KategoriRepositoryStub()));
            var builder = new TestControllerBuilder();
            builder.InitializeController(controller);

            controller.Session["AdminInnlogget"] = true;
            controller.ViewData.ModelState.AddModelError("Navn", "Ikke oppgitt kategorinavn.");

            var forventetKategori = new Kategori();

            // Act

            var result = (ViewResult)controller.LagNy(forventetKategori);

            // Assert

            Assert.IsTrue(result.ViewData.ModelState.Count == 1);
            Assert.AreEqual(result.ViewName, "");
        }
Ejemplo n.º 4
0
        public void LagNy_POST_ok()
        {
            // Arrange

            var controller = new KategoriController(new KategoriLogikk(new KategoriRepositoryStub()));
            var builder = new TestControllerBuilder();
            builder.InitializeController(controller);

            controller.Session["AdminInnlogget"] = true;

            var forventetKategori = new Kategori() {
                Navn = "Datamaskiner"
            };

            // Act

            var result = (RedirectToRouteResult)controller.LagNy(forventetKategori);

            // Assert

            Assert.AreEqual(result.RouteName, "");
            Assert.AreEqual(result.RouteValues.Values.First(), "Liste");
        }