예제 #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);
        }
예제 #2
0
        public void EditPrijavasParam()
        {
            var repMockPri = new Mock<IFakultetRepository<Prijavas>>();
            var repMockStud = new Mock<IFakultetRepository<Students>>();
            var repMockIsp = new Mock<IFakultetRepository<Ispits>>();

            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" };
            Prijavas prijavas = new Prijavas() { BI = "10011", IspitID = 1, Ocena = 8, Students = s1, Ispits = i1 };

            repMockPri.Setup(x => x.UpdateEntity(prijavas));

            controller = new PrijavasController(repMockPri.Object);
            controller.SetIspitsRepository(repMockIsp.Object);
            controller.SetStudentsRepository(repMockStud.Object);

            var result = controller.Edit(prijavas);
            var viewResult = result as ViewResult;
            var rtaResult = result as RedirectToRouteResult;

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

            Assert.AreEqual("Index", rtaResult.RouteValues["Action"]);
        }
예제 #3
0
        public void EditIdParam()
        {
            var repMockPri = new Mock<IFakultetRepository<Prijavas>>();
            var repMockStud = new Mock<IFakultetRepository<Students>>();
            var repMockIsp = new Mock<IFakultetRepository<Ispits>>();

            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" };
            Prijavas prijavas = new Prijavas() { BI = "10011", IspitID = 1, Ocena = 8, Students = s1, Ispits = i1 };
            var studentList = new List<Students>();
            studentList.Add(s1);
            studentList.Add(s2);
            var ispitList = new List<Ispits>();
            ispitList.Add(i1);
            ispitList.Add(i2);

            object[] con = { prijavas.BI, prijavas.IspitID };
            repMockPri.Setup(x => x.GetEntityById(con)).Returns(prijavas);
            repMockStud.Setup(x => x.GetEntities()).Returns(studentList);
            repMockIsp.Setup(x => x.GetEntities()).Returns(ispitList);

            controller = new PrijavasController(repMockPri.Object);
            controller.SetIspitsRepository(repMockIsp.Object);
            controller.SetStudentsRepository(repMockStud.Object);

            var result = controller.Edit(prijavas.BI, prijavas.IspitID + "") as ViewResult;
            var sList = result.ViewBag.BI as SelectList;
            var iList = result.ViewBag.IspitID as SelectList;

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

            Assert.AreEqual("Edit", result.ViewName);
            Assert.AreEqual(sList.ElementAt(0).Value, "10011");
            Assert.AreEqual(sList.ElementAt(1).Value, "20011");
            Assert.AreEqual(iList.ElementAt(0).Value, 1+"");
            Assert.AreEqual(iList.ElementAt(1).Value, 2+"");
        }