コード例 #1
0
        public void Create_Post_PutsValidContactIntoRepository()
        {
            // Arrange
            InMemoryIndividualRepository repository = new InMemoryIndividualRepository();
            cIndividualController        controller = Harness.GetController(repository);
            cIndividual indiv = GetIndividual();

            // Act
            controller.Create(indiv);

            // Assert
            IEnumerable <cIndividual> individuals = repository.GetAllIndividuals();

            Assert.IsTrue(individuals.Contains(indiv));
        }
コード例 #2
0
        public void Create_Post_ReturnsViewIfModelStateIsNotValid()
        {
            // Arrange
            cIndividualController controller = Harness.GetController(new InMemoryIndividualRepository());

            // Simply executing a method during a unit test does just that - executes a method, and no more.
            // The MVC pipeline doesn't run, so binding and validation don't run.
            controller.ModelState.AddModelError("", "mock error message");
            cIndividual model = GetIndividual(1, "", "", DateTime.Now, "", "");

            // Act
            var result = (ViewResult)controller.Create(model);

            // Assert
            Assert.AreEqual("Create", result.ViewName);
        }