コード例 #1
0
        public void About()
        {
            // Arrange
            HomeController controller = new HomeController();

            // Act
            ViewResult result = controller.About() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
コード例 #2
0
        public void Index()
        {         
           // Arrange
            List<ValidationResult> vErrors=new List<ValidationResult>();
            HomeController controller = new HomeController();
            var m=new Module()
            {
                Memo = "123"
            };
            ValidationContext vc = new ValidationContext(m, null, null);

            Validator.TryValidateObject(m, vc, vErrors, false);
            foreach (var e in vErrors)
            {
                throw new Exception(e.ErrorMessage);
            }
            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.AreEqual("Welcome to ASP.NET MVC!", result.ViewBag.Message);
        }