public void Grades_Controller_Test_On_EditModel_With_Invalid_Id()
        {
            //Arrange
            Guid     id    = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            int      value = 10;
            DateTime date  = DateTime.Now;

            Grade expectedGrades = new Grade(value, date);

            expectedGrades.Id = id;

            GradeModel expectedModel = new GradeModel();

            Guid faultId = new Guid("1e4966f0-68f7-4f24-9f4f-53d528787be5");

            expectedModel.Value = 1;

            var repo = Substitute.For <IRepository>();
            var sut  = new GradesController(repo);

            repo.Update(expectedGrades);

            //Act
            var actual = sut.Edit(faultId, expectedGrades).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(NotFoundResult));
        }
        public void Grades_Controller_Test_On_EditModel_With_Invalid_Model()
        {
            //Arrange
            Guid     id    = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            int      value = 10;
            DateTime date  = DateTime.Now;

            Grade expectedGrades = new Grade(value, date);

            expectedGrades.Id = id;

            GradeModel expectedModel = new GradeModel();

            expectedModel.Value = 1;

            var repo = Substitute.For <IRepository>();
            var sut  = new GradesController(repo);

            repo.Update(expectedGrades);

            //Act
            sut.ModelState.AddModelError("FirstName", "Firstname Required");
            var actual = sut.Edit(id, expectedGrades).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(ViewResult));
        }
Exemplo n.º 3
0
        public void Edit_NoId()
        {
            int?id     = null;
            var result = (ViewResult)controller.Edit(id);

            Assert.AreEqual("Error", result.ViewName);
        }
        public void Grades_Controller_Test_On_Edit_With_NonExistent_Id()
        {
            //Arrange
            Guid id   = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            var  repo = Substitute.For <IRepository>();
            var  sut  = new GradesController(repo);

            repo.GetById <Grade>(id);

            //Act
            var actual = sut.Edit(id).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(NotFoundResult));
        }
        public void Grades_Controller_Test_On_EditModel_With_Valid_Model()
        {
            //Arrange
            Guid     id    = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            int      value = 10;
            DateTime date  = DateTime.Now;

            Grade expectedGrades = new Grade(value, date);

            expectedGrades.Id = id;

            var repo = Substitute.For <IRepository>();
            var sut  = new GradesController(repo);

            repo.Update(expectedGrades);

            //Act
            var actual = sut.Edit(id, expectedGrades).Result;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(RedirectToActionResult));
        }
        public void Grades_Controller_Test_On_Edit_With_Existent_Id()
        {
            //Arrange
            Guid     id    = new Guid("f616cc8c-2223-4145-b7d0-232a1f6f0795");
            int      value = 10;
            DateTime date  = DateTime.Now;

            Grade expectedGrades = new Grade(value, date);

            expectedGrades.Id = id;

            var repo = Substitute.For <IRepository>();
            var sut  = new GradesController(repo);

            repo.GetById <Grade>(id).Returns(expectedGrades);
            //Act
            var actual = sut.Edit(id).Result as ViewResult;

            //Assert
            Assert.IsInstanceOfType(actual, typeof(ViewResult));
            var viewResult = actual;

            Assert.AreEqual(expectedGrades, viewResult.Model);
        }