public void registreradmin_notOK() { 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.registrerAdmin(); var k = (RegisterAnsattModel)viewResult.Model; Assert.AreEqual("s1000", k.AnsattNr); }
public void endreAnsatt_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.endreAnsattAdmDetaljer(null); 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); }
public void registreradmin_notauth() { var mock = new Mock<ControllerContext>(); mock.SetupGet(u => u.HttpContext.Request.IsAuthenticated).Returns(true); mock.SetupGet(u => u.HttpContext.User.Identity.Name).Returns(""); 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.registrerAdmin(); 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-->) }
public void visAnsatte_PostOk() { 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 liste = new List<Admin>(); var ansatte = new Admin() { AnsattId = "s1", Epost = "*****@*****.**", Firstname = "Arne", Lastname = "Hansen", Stilling = "Leder" }; liste.Add(ansatte); liste.Add(ansatte); liste.Add(ansatte); 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 = (PartialViewResult)controller.visAlleAnsatte("Leder"); var k = (List<Admin>)viewResult.Model; Assert.IsTrue(viewResult.ViewData.Model == k); for (int i = 0; i<k.Count;i++) { Assert.AreEqual(liste[i].AnsattId, k[i].AnsattId); Assert.AreEqual(liste[i].Epost, k[i].Epost); Assert.AreEqual(liste[i].Firstname, k[i].Firstname); Assert.AreEqual(liste[i].Lastname, k[i].Lastname); Assert.AreEqual(liste[i].Stilling, k[i].Stilling); } }