Exemple #1
0
        public void IspitDeleteComfirmed()
        {
            IspitController ik = new IspitController();

            Mock <UnitOfWork>      mockUnit  = new Mock <UnitOfWork>(new Zadatak2Context());
            Mock <IspitRepository> mockIspit = new Mock <IspitRepository>(new Zadatak2Context());

            mockIspit.Setup(x => x.FindIspit(1, 1)).Returns(new Ispit
            {
                BI        = 1,
                PredmetId = 1,
                Oena      = 7
            });
            mockIspit.Setup(x => x.Delete(new Ispit
            {
                BI        = 1,
                PredmetId = 1,
                Oena      = 7
            }));
            mockUnit.Setup(x => x.SaveChanges());

            ik.UnitOfWork        = mockUnit.Object;
            ik.UnitOfWork.Ispiti = mockIspit.Object;
            ViewResult rezultat = ik.DeleteConfirmed(1, 1) as ViewResult;

            mockIspit.Verify((x => x.FindIspit(1, 1)), Times.Once());
            mockIspit.Verify((x => x.Delete(It.IsAny <Ispit>())), Times.Once());
            mockUnit.Verify((x => x.SaveChanges()), Times.Once());
        }
Exemple #2
0
        public void IspitEdit()
        {
            IspitController ik = new IspitController();

            Mock <UnitOfWork>        mockUnit    = new Mock <UnitOfWork>(new Zadatak2Context());
            Mock <IspitRepository>   mockIspit   = new Mock <IspitRepository>(new Zadatak2Context());
            Mock <PredmetRepository> mockPredmet = new Mock <PredmetRepository>(new Zadatak2Context());
            Mock <StudentRepository> mockStudent = new Mock <StudentRepository>(new Zadatak2Context());

            mockIspit.Setup(x => x.Edit(new Ispit {
                BI = 10, PredmetId = 2, Oena = 7
            }));
            mockUnit.Setup(x => x.SaveChanges());
            mockPredmet.Setup(x => x.GetAll()).Returns(SeedClass.GetPredmets());
            mockStudent.Setup(x => x.GetAll()).Returns(SeedClass.GetStudentsTest());

            ik.UnitOfWork        = mockUnit.Object;
            ik.UnitOfWork.Ispiti = mockIspit.Object;
            ViewResult rezultat = ik.Edit(new IspitModel {
                BI = 10, PredmetId = 2, Oena = 7
            }) as ViewResult;

            mockIspit.Verify((x => x.Edit(It.IsAny <Ispit>())), Times.Once());
            mockUnit.Verify((x => x.SaveChanges()), Times.Once());
            mockPredmet.Verify((x => x.GetAll()), Times.Exactly(0));
            mockStudent.Verify((x => x.GetAll()), Times.Exactly(0));
        }
        public void IspitDeleteCorrectID()
        {
            var db = new TestStudentIspitiContext();
            db.Initialize();
            IspitController controller = new IspitController(db);
            int i = 2;

            var result = controller.Delete(i) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(Ispit));
        }
        public void IspitDeleteNotCorrectID()
        {
            var db = new TestStudentIspitiContext();
            db.Initialize();
            IspitController controller = new IspitController(db);
            int i = 100;

            var result = controller.Delete(i);

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
            var httpResult = result as HttpNotFoundResult;
            Assert.AreEqual(404, httpResult.StatusCode);
        }
        public void IspitDeleteConfirmedTest()
        {
            var db = new TestStudentIspitiContext();
            db.Initialize();
            IspitController controller = new IspitController(db);
            int i = 20;

            var result = controller.DeleteConfirmed(i);

            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
            var tempresult = result as RedirectToRouteResult;
            Assert.AreEqual("Index", tempresult.RouteValues["action"]);
        }
        public void IspitDeleteNullTest()
        {
            /*Test Delete when null is passed*/
            var db = new TestStudentIspitiContext();
            db.Initialize();
            IspitController controller = new IspitController(db);
            int? i = null;

            var result = controller.Delete(i);

            Assert.IsInstanceOfType(result, typeof(System.Web.Mvc.HttpStatusCodeResult));
            var httpResult = result as HttpStatusCodeResult;
            Assert.AreEqual(400, httpResult.StatusCode);
        }
Exemple #7
0
        public void IspitDetails()
        {
            IspitController ik = new IspitController();

            Mock <UnitOfWork>      mockUnit  = new Mock <UnitOfWork>(new Zadatak2Context());
            Mock <IspitRepository> mockIspit = new Mock <IspitRepository>(new Zadatak2Context());

            mockIspit.Setup(x => x.FindIspit(1, 1)).Returns(SeedClass.GetIspitsTest()[1]);

            ik.UnitOfWork        = mockUnit.Object;
            ik.UnitOfWork.Ispiti = mockIspit.Object;
            ViewResult rezultat = ik.Details(1, 1) as ViewResult;

            mockIspit.Verify((x => x.FindIspit(1, 1)), Times.Once());
            Assert.IsTrue(rezultat != null);
            Assert.AreEqual(SeedClass.GetIspitsTest()[1].GetType(), rezultat.Model.GetType());
        }
Exemple #8
0
        public void IspitIndex()
        {
            IspitController ik = new IspitController();

            Mock <UnitOfWork>      mockUnit  = new Mock <UnitOfWork>(new Zadatak2Context());
            Mock <IspitRepository> mockIspit = new Mock <IspitRepository>(new Zadatak2Context());

            mockIspit.Setup(x => x.GetAll()).Returns(SeedClass.GetIspitsTest());

            ik.UnitOfWork        = mockUnit.Object;
            ik.UnitOfWork.Ispiti = mockIspit.Object;
            ViewResult rezultat = ik.Index(null) as ViewResult;

            mockIspit.Verify((x => x.GetAll()), Times.Once());
            Assert.IsTrue(rezultat != null);
            Assert.AreEqual(SeedClass.GetIspitsTest().GetType(), rezultat.Model.GetType());
            //Assert.AreSame(SeedClass.GetStudentsTest(), rezultat.Model);
        }
        public void IspitDetailsNotCorrectIDTest()
        {
            //Test Details when id that does not exist in db is passed
            var db = new TestStudentIspitiContext();
            db.Initialize();
            IspitController controller = new IspitController(db);

            var result = controller.Details(100);

            Assert.IsInstanceOfType(result, typeof(HttpNotFoundResult));
            var httpResult = result as HttpNotFoundResult;
            Assert.AreEqual(404, httpResult.StatusCode);
        }
        public void IspitDetailsCorrectIDTest()
        {
            //Test Details when id that exist in db is passed
            var db = new TestStudentIspitiContext();
            db.Initialize();
            IspitController controller = new IspitController(db);

            var result = controller.Details(2) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model,typeof(Ispit));
        }
        public void IspitIndexTest()
        {
            var db = new TestStudentIspitiContext();
            db.Initialize();
            IspitController controller = new IspitController(db);

            ViewResult result = controller.Index() as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result.Model, typeof(List<Ispit>));
        }