Example #1
0
        public void Create_Post_PutsValidContactIntoRepository()
        {
            // Arrange
            InMemoryStudentRepository repository = new InMemoryStudentRepository();
            HomeController            controller = GetHomeController(repository);

            Student s1 = GetPerson();

            //Act
            controller.Create(s1);

            //Assert
            IEnumerable <Student> students = repository.GetStudents();

            Assert.IsTrue(students.Contains(s1));
        }
Example #2
0
        public void Index_Get_RetrievesAllContactsFromRepository()
        {
            //Arrange
            Student p1 = GetPerson(1, "Sammy", "Hagar");
            Student p2 = GetPerson(2, "Johnny", "Walker");
            InMemoryStudentRepository repository = new InMemoryStudentRepository();

            repository.InsertStudent(p1);
            repository.InsertStudent(p2);
            var controller = GetHomeController(repository);

            //Act
            var result = controller.Index();

            //Assert
            var model = (IEnumerable <Student>)result.ViewData.Model;

            CollectionAssert.Contains(model.ToList(), p1);
            CollectionAssert.Contains(model.ToList(), p2);
        }
Example #3
0
        public void Create_Post_ReturnsViewIfRepositoryThrowsException()
        {
            //Arrange
            InMemoryStudentRepository repository = new InMemoryStudentRepository();
            Exception exception = new Exception();

            repository.ExceptionToThrow = exception;
            HomeController controller = GetHomeController(repository);
            Student        s1         = GetPerson();

            //Act
            var result = controller.Create(s1);

            //Assert
            Assert.AreEqual("Create", result.ViewName);
            ModelState modelState = result.ViewData.ModelState[""];

            Assert.IsNotNull(modelState);
            Assert.IsTrue(modelState.Errors.Any());
            Assert.AreEqual(exception, modelState.Errors[0].Exception);
        }