public void visAnsatteSok_modelFeil() { var controller = new AdminController(new Mock<IAuth>().Object, new AdminLogikk(new ansattRepositoryStub()), new ProdukterLogikk(new ProduktRepositoryStub()), new KundeLogikk(new KundeRepositoryStub())); controller.ViewData.ModelState.AddModelError("", "Feil"); //act var resultat = controller.visAlleAnsatteSok(null); //assert Assert.IsTrue(resultat.ViewData.ModelState.Count == 1); Assert.AreEqual(resultat.ViewName, ""); }
public void visAnsatteSok_PosttomModel() { 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 = "", }; liste.Add(ansatte); liste.Add(ansatte); liste.Add(ansatte); var nullansatt= new Admin(); 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.visAlleAnsatteSok(nullansatt); var k = (List<Admin>)viewResult.Model; Assert.IsTrue(viewResult.ViewName == "visAlleAnsatte"); 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); } }
public void visAnsatteSok_authnotloggenin() { 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; //act var resultat = controller.visAlleAnsatteSok(null); //assert Assert.AreEqual(resultat.ViewName, ""); }