示例#1
0
        public void new_should_return_app_model()
        {
            // Act
            var controller = new AppController(null,null,null);
            var view = controller.New();

            // Assert
            Assert.NotNull(view);
            controller.AssertGetAttribute("New");
        }
示例#2
0
        public void new_should_return_app_model()
        {
            // Arrange
            var demoService = new Mock<IDemoDataService>();

            // Act
            var controller = new AppController(null, demoService.Object);
            var view = controller.New();

            // Assert
            Assert.IsTrue(controller.HasGetAttribute("New"), "HttpGet attribute not found on AppController's New() action method");
            Assert.NotNull(view);
            demoService.Verify(x => x.GetAnApp(), Times.Once);
        }
示例#3
0
        public void new_should_redirect_if_model_is_valid()
        {
            // Arrange
            var validModel = new AppModel { Name = "test name", Url = "test.com", Description = "test description" };

            // Act
            var controller = new AppController(null, null);
            var view = controller.New(validModel) as RedirectResult;

            // Assert
            Assert.NotNull(view);
            Assert.AreEqual(view.Url, "/user/apps");
            Assert.IsTrue(controller.HasPostAttribute("New", new[] { typeof(AppModel) }), "HttpPost attribute not found or ValidateAntiForgeryToken attribute not added on AppController's New() action method");
        }
示例#4
0
        public void new_should_return_app_model_if_model_is_invalid()
        {
            // Arrange
            var inValidModel = new AppModel { Name = "test name", Url = "test.com" };

            // Act
            var controller = new AppController(null, null);
            var view = controller.New(inValidModel) as ViewResult;

            // Assert
            Assert.NotNull(view);
            Assert.NotNull(view.Model);

            var model = view.Model as AppModel;
            Assert.NotNull(model);

            Assert.IsTrue(controller.HasPostAttribute("New", new[] { typeof(AppModel) }), "HttpPost attribute not found or ValidateAntiForgeryToken attribute not added on AppController's New() action method");
        }
示例#5
0
        public void new_should_return_app_model_if_model_is_invalid()
        {
            // Arrange
            var appService = new Mock<IAppService>();
            var inValidModel = new AppModel { Name = "test name", Url = "test.com" };

            // Act
            var controller = new AppController(null, null, appService.Object);
            var view = controller.New(inValidModel).Result as ViewResult;

            // Assert
            Assert.NotNull(view);
            Assert.NotNull(view.Model);
            var model = view.Model as AppModel;

            Assert.NotNull(model);

            controller.AssertPostAttribute("New", new[] { typeof(AppModel) });
        }