public void It_should_throw_InvalidCastException()
        {
            var mvc = new Framework();

            // c.Index() returns a ViewResult.  but, we're typecasting to ContentResult here.  so, should throw InvalidCastException.
            Assert.Throws<InvalidCastException>(() => mvc.HttpGet<SampleController, ContentResult>(c => c.Index()));
        }
        public void It_should_display_a_CreateModelView()
        {
            var mvc = new Framework();

            var result = mvc.HttpGet<CategoryController, ViewResult>(c => c.Create());

            Assert.IsInstanceOf<CreateModelView>(result.ActionResult.Model);
        }
        public void It_should_be_able_to_read_the_value_out()
        {
            //  ARRANGE
            var mvc = new Framework();

            mvc.HttpContext.AddQueryStringFixture("firstName", "peter");

            //  ACT
            var result = mvc.HttpGet<SampleController, ContentResult>(c => c.Index());

            //  ASSERT
            Assert.That(result.ActionResult.Content, Is.EqualTo("peter"));
        }
        public void It_should_display_a_list_of_categories()
        {
            // ARRANGE
            var mvc = new Framework();
            var repoStub = mvc.Inject<Mock<ICategoryRepository>>();
            var categoriesActual = new List<Category> {mvc.New<Category>()};

            repoStub.Setup(r => r.FindAll()).Returns(categoriesActual.AsQueryable());

            // ACT
            var result = mvc.HttpGet<HomeController, ViewResult>(c => c.Index());
            var categoriesExpected = result.ActionResult.Model as List<Category>;

            // ASSERT
            Assert.That(categoriesExpected.Count, Is.EqualTo(1));
            Assert.That(categoriesExpected[0].Id, Is.EqualTo(categoriesActual[0].Id));
        }
        public void It_should_display_no_categories_found_message()
        {
            // ARRANGE
            var mvc = new Framework();
            var repoStub = mvc.Inject<Mock<ICategoryRepository>>();
            IQueryable<Category> categories = null;     // no items

            repoStub.Setup(r => r.FindAll()).Returns(categories);

            // ACT
            var result = mvc.HttpGet<CategoryController, ViewResult>(c => c.Index());

            // ASSERT
            var viewModel = result.ActionResult.Model as IndexViewModel;

            Assert.That(viewModel.GetNoCategoriesMessage(), Is.EqualTo("No categories found."));
        }
        public void It_should_display_a_list_of_categories()
        {
            // ARRANGE
            var mvc = new Framework();
            var repoStub = mvc.Inject<Mock<ICategoryRepository>>();
            var categoriesExpected = new List<Category>
                             {
                                 new Category { Id = 123, Name = "category1" },
                                 new Category { Id = 234, Name = "category2"}
                             };

            repoStub.Setup(r => r.FindAll()).Returns(categoriesExpected.AsQueryable());

            // ACT
            var result = mvc.HttpGet<CategoryController, ViewResult>(c => c.Index());

            // ASSERT
            var viewModel = result.ActionResult.Model as IndexViewModel;
            var categoriesActual = viewModel.Categories.ToArray();

            Assert.That(categoriesActual.Length, Is.EqualTo(2));
            Assert.That(categoriesActual[0].Id, Is.EqualTo(123));
            Assert.That(categoriesActual[1].Id, Is.EqualTo(234));
        }