public void endrepassord_post_ok() { /*var mock = new Mock<ControllerContext>(); 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.registrerAdmin(null, "Leder"); //act //assert Assert.IsTrue(resultat.ViewData.ModelState.Count == 1); Assert.IsTrue(resultat.ViewName == "");*/ 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 passord = new ChangeUserPassword() { Password = "******", OldPassword = "******", ConfirmPassword = "******", }; 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.endrePassord(passord); Assert.AreEqual("Index", viewResult.RouteValues["Action"]); //<---view som blir vist hvis er requested-->) Assert.AreEqual("Admin", viewResult.RouteValues["Controller"]); }
public void endrepassord_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 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.endrePassord(); Assert.AreEqual("", viewResult.ViewName); }
public void endrepassord_post_notloggedin() { var mock = new Mock<ControllerContext>(); mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(false); mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns(""); var passord = new ChangeUserPassword(); 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.endrePassord(passord); Assert.IsTrue(viewResult.ViewName == ""); }
public void endrepassord_notadmin() { var mock = new Mock<ControllerContext>(); mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(true); 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.endrePassord(); 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-->) }