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));
        }