Exemplo n.º 1
0
        public void Create()
        {
            var repMockIsp = new Mock<IFakultetRepository<Ispits>>();
            var repMockStud = repMockIsp.As<IFakultetRepository<Students>>();

            Students s1 = new Students() { BI = "10011", Ime = "Pera", Prezime = "Peric", Adresa = "Ulica1", Grad = "Grad1" };
            Students s2 = new Students() { BI = "20011", Ime = "Marko", Prezime = "Markovic", Adresa = "Ulica2", Grad = "Grad2" };
            Ispits i1 = new Ispits() { IspitID = 1, Naziv = "Ispit1" };
            Ispits i2 = new Ispits() { IspitID = 2, Naziv = "Ispit2" };
            var studentList = new List<Students>();
            studentList.Add(s1);
            studentList.Add(s2);
            var ispitList = new List<Ispits>();
            ispitList.Add(i1);
            ispitList.Add(i2);
            repMockStud.Setup(x => x.GetEntities()).Returns(studentList);
            repMockIsp.Setup(x => x.GetEntities()).Returns(ispitList);

            controller = new PrijavasController();
            controller.SetStudentsRepository(repMockStud.Object);
            controller.SetIspitsRepository(repMockIsp.Object);
            var result = controller.Create();
            ViewResult viewRes = result as ViewResult;
            var selectList = viewRes.ViewBag.BI as SelectList;

            repMockIsp.VerifyAll();
            repMockStud.VerifyAll();

            Assert.AreEqual("Create", viewRes.ViewName);
            Assert.AreEqual(selectList.ElementAt(0).Text, s1.BI+" - "+s1.Ime+" "+s1.Prezime);
            Assert.AreEqual(selectList.ElementAt(1).Text, s2.BI + " - " + s2.Ime + " " + s2.Prezime);
        }
Exemplo n.º 2
0
        public void CreatePrijavaParam()
        {
            var repMock = new Mock<IFakultetRepository<Prijavas>>();

            Students s1 = new Students() { BI = "10011", Ime = "Pera", Prezime = "Peric", Adresa = "Ulica1", Grad = "Grad1" };
            Ispits i1 = new Ispits() { IspitID = 1, Naziv = "Ispit1" };
            Prijavas prijavas = new Prijavas() { BI = "10011", IspitID = 1, Ocena = 8, Students = s1, Ispits = i1 };
            repMock.Setup(x => x.InsertEntity(prijavas));
            controller = new PrijavasController(repMock.Object);
            var result = controller.Create(prijavas) as RedirectToRouteResult;
            repMock.VerifyAll();
            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }