コード例 #1
0
        public void endreAnsattPost1_ok()
        {
            var mock = new Mock<ControllerContext>();
            mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(true);
            mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns("123");
            var ansatte = new Admin()
            {
                AnsattId = "s1",
                Epost = "*****@*****.**",
                Firstname = "Arne",
                Lastname = "Hansen",
                Stilling = "Leder"
            };

            var controller = new AdminController(new Mock<IAuth>().Object, new AdminLogikk(new ansattRepositoryStub()),
                new ProdukterLogikk(new ProduktRepositoryStub()), new KundeLogikk(new KundeRepositoryStub()));
            controller.ControllerContext = mock.Object;
            var viewResult = (RedirectToRouteResult)controller.endreAnsattDetaljer(ansatte);

            Assert.AreEqual("Index", viewResult.RouteValues["Action"]); //<---view som blir vist hvis er requested-->)
            Assert.AreEqual("Admin", viewResult.RouteValues["Controller"]); //<---view som blir vist hvis er requested-->)
        }
コード例 #2
0
        public void endreAnsatt1_ok()
        {
            var mock = new Mock<ControllerContext>();
            mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(true);
            mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns("123");
            var ansatte = new Admin()
            {
                AnsattId = "s1",
                Epost = "*****@*****.**",
                Firstname = "Arne",
                Lastname = "Hansen",
                Stilling = "Leder"
            };

            var controller = new AdminController(new Mock<IAuth>().Object, new AdminLogikk(new ansattRepositoryStub()),
                new ProdukterLogikk(new ProduktRepositoryStub()), new KundeLogikk(new KundeRepositoryStub()));
            controller.ControllerContext = mock.Object;
            var viewResult = (ViewResult)controller.endreAnsattDetaljer();
            var k = (Admin)viewResult.Model;
            Assert.AreEqual(ansatte.AnsattId, k.AnsattId);
            Assert.AreEqual(ansatte.Epost, k.Epost);
            Assert.AreEqual(ansatte.Firstname, k.Firstname);
            Assert.AreEqual(ansatte.Lastname, k.Lastname);
            Assert.AreEqual(ansatte.Stilling, k.Stilling);
        }
コード例 #3
0
        public void endreAnsattPost1_modelfeil()
        {
            var mock = new Mock<ControllerContext>();
            /*mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(true);
            //mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns("123");

            var ansatte = new Admin()
            {
                AnsattId = "s1",
                Epost = "*****@*****.**",
                Firstname = "Arne",
                Lastname = "Hansen",
                Stilling = "Leder"
            };

            */
            var controller = new AdminController(new Mock<IAuth>().Object, new AdminLogikk(new ansattRepositoryStub()),
                new ProdukterLogikk(new ProduktRepositoryStub()), new KundeLogikk(new KundeRepositoryStub()));
            controller.ControllerContext = mock.Object;
            controller.ViewData.ModelState.AddModelError("", "Feil");
            var resultat = (ViewResult)controller.endreAnsattDetaljer(null);

            //act
            //assert
            Assert.IsTrue(resultat.ViewData.ModelState.Count == 1);
            Assert.IsTrue(resultat.ViewName == "");
        }
コード例 #4
0
        public void endreAnsatt1_authfeil()
        {
            var mock = new Mock<ControllerContext>();
            mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(false);
            mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns("");

            var controller = new AdminController(new Mock<IAuth>().Object, new AdminLogikk(new ansattRepositoryStub()),
                new ProdukterLogikk(new ProduktRepositoryStub()), new KundeLogikk(new KundeRepositoryStub()));
            controller.ControllerContext = mock.Object;
            var viewResult = (RedirectToRouteResult)controller.endreAnsattDetaljer();

            Assert.AreEqual("logginn", viewResult.RouteValues["Action"]); //<---view som blir vist hvis er requested-->)
            Assert.AreEqual("Admin", viewResult.RouteValues["Controller"]); //<---view som blir vist hvis er requested-->)
        }