Example #1
0
        public void Create_Saves_Restaurant_When_Valid()
        {
            var db         = new FakeOdeToFoodDb();
            var controller = new RestaurantsController(db);

            controller.Create(new Restaurant());

            Assert.AreEqual(1, db.Added.Count);
            Assert.AreEqual(true, db.Saved);
        }
        public void Create_Does_Not_Save__Restaurant_When_Invalid()
        {
            var db         = new FakeOdeToFoodDb();
            var controller = new RestaurantController(db);

            controller.ModelState.AddModelError("", "Invalid");

            controller.Create(new Restaurant());
            Assert.AreEqual(0, db.Added.Count);
        }
        public void Index()
        {
            // Arrange
            var db = new FakeOdeToFoodDb();

            db.AddSet(TestData.Restaurants);
            HomeController controller = new HomeController(db);

            controller.ControllerContext = new FakeControllerContext();
            // Act
            ViewResult result = controller.Index() as ViewResult;
            IEnumerable <RestaurantViewListModel> model = result.Model as IEnumerable <RestaurantViewListModel>;

            // Assert
            Assert.AreEqual(10, model.Count());
        }
        public void Index()
        {
            // Arrange

            var db = new FakeOdeToFoodDb();

            db.AddSet(TestData.Restaurants);

            HomeController controller = new HomeController(db);

            controller.ControllerContext = new FakeControllerContext();

            // Act
            ViewResult result = controller.Index() as ViewResult;
            IEnumerable <RestaurantListViewModel> model = result.Model as IEnumerable <RestaurantListViewModel>;

            // Assert
            //Assert.AreEqual("Modify this template to jump-start your ASP.NET MVC application.", result.ViewBag.Message);
            Assert.AreEqual(10, model.Count());
        }