public void AddSubCategory()
        {
            var sessionMock = new Mock<ISession>();
            var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName);

            var controller = new CategoriesController(nHbernateContextMock.Object);
            controller.SetFakeControllerContext(MvcMockHelpers.FakeUnauthenticatedHttpContext("~/Categories/AddSubCategory", UserName));

            var jsonResult = controller.AddSubCategory("subCat", 4);

            nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny<ICommand>()));

            dynamic json = jsonResult.Data;
            Assert.IsTrue(json.Success);
        }
        public void DeleteCategory_Fail()
        {
            var sessionMock = new Mock<ISession>();
            var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName);
            const string errorMessage = "Error message";
            nHbernateContextMock.Setup(c => c.ExecuteCommand(It.IsAny<ICommand>())).Throws(new DomainException(errorMessage));

            var controller = new CategoriesController(nHbernateContextMock.Object);
            controller.SetFakeControllerContext(MvcMockHelpers.FakeUnauthenticatedHttpContext("~/Categories/DeleteCategory", UserName));

            var jsonResult = controller.DeleteCategory(4);

            nHbernateContextMock.Verify(c => c.ExecuteCommand(It.IsAny<ICommand>()));

            dynamic json = jsonResult.Data;
            Assert.IsFalse(json.Success);
            Assert.AreEqual(errorMessage, json.Message);
        }
        public void Menu()
        {
            var sessionMock = new Mock<ISession>();
            var nHbernateContextMock = new Mock<NHibernateContext>(sessionMock.Object, UserName);
            var categories = new List<Category>();

            nHbernateContextMock.Setup(c => c.ExecuteQuery(It.IsAny<Func<ISession, IList<Category>>>()))
                .Returns(categories);

            var controller = new CategoriesController(nHbernateContextMock.Object);
            controller.SetFakeControllerContext(MvcMockHelpers.FakeUnauthenticatedHttpContext("~/Categories/Menu", UserName));

            controller.Menu();

            Assert.AreEqual(categories, controller.ViewData.Model);
        }