Ejemplo n.º 1
0
        public void Innlogging_POST_feil()
        {
            // Arrange
            var controller = new AdminController(new AdminLogikk(new AdminRepositoryStub()));
            var innloggingsmodell = new AdminInnlogging();
            controller.ModelState.AddModelError("Epost", "Epost mangler.");
            controller.ModelState.AddModelError("Passord", "Passord mangler.");

            // Act

            var result = (ViewResult)controller.Innlogging(innloggingsmodell);

            // Assert

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

            var controller = new AdminController(new AdminLogikk(new AdminRepositoryStub()));
            var builder = new TestControllerBuilder();
            builder.InitializeController(controller);

            controller.Session["AdminInnlogget"] = true;

            // Act

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

            // Assert

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

            var controller = new AdminController(new AdminLogikk(new AdminRepositoryStub()));
            var builder = new TestControllerBuilder();
            builder.InitializeController(controller);

            controller.Session["AdminInnlogget"] = false;

            // Act

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

            // Assert

            //Assert.IsTrue((bool)controller.Session["AdminInnlogget"]);
            Assert.AreEqual(result.ViewName, "");
        }
Ejemplo n.º 4
0
        public void Innlogging_POST_ok()
        {
            // Arrange

            var controller = new AdminController(new AdminLogikk(new AdminRepositoryStub()));
            var builder = new TestControllerBuilder();
            builder.InitializeController(controller);
            var innloggingsmodell = new AdminInnlogging() {
                Epost = "*****@*****.**",
                Passord = "admin"
            };
            var hashPassord = Crypto.LagHash(innloggingsmodell.Passord);

            // Act

            var result = (RedirectToRouteResult)controller.Innlogging(innloggingsmodell);
            var innloggetAdminBruker = (AdminBruker)controller.Session["AdminBruker"];

            // Assert

            Assert.AreEqual(controller.Session["AdminInnlogget"], true);
            Assert.AreEqual(innloggetAdminBruker.Epost, innloggingsmodell.Epost);

            for (var i = 0; i < innloggetAdminBruker.Passord.Length; i++) {
                Assert.AreEqual(innloggetAdminBruker.Passord[i], hashPassord[i]);
            }

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