Ejemplo n.º 1
0
        public void IndexActionMethodReturnsAViewResult()
        {
            var dbConnection = MockRepository.GenerateStrictMock<IDbExecutor>();

            dbConnection
                .Stub<IDbExecutor>(connection => connection.Query<ProductBoxViewModel>(string.Empty))
                .IgnoreArguments()
                .Return(new ProductBoxViewModel[] { });

            var homeController = new HomeController(dbConnection, MockRepository.GenerateMock<IResponse>());

            var actual = ((ViewResult)homeController.Index()).Model;

            Assert.IsInstanceOf<HomePageViewModel>(actual);

            dbConnection.VerifyAllExpectations();
        }
Ejemplo n.º 2
0
        public void IndexActionMethodShouldCallTheDatabaseToReturnDataToBeUsedToPopulateTheModel()
        {
            var dbConnection = MockRepository.GenerateStrictMock<IDbExecutor>();
            var homeController = new HomeController(dbConnection, MockRepository.GenerateMock<IResponse>());

            dbConnection
                .Expect(connection => connection.Query<ProductBoxViewModel>(
                    "SELECT id, prdct.Url AS productUrl, prdct.Name AS productName, prdct.UnitPrice AS productPrice, [image].Url AS imageUrl, [image].Name AS imageTitle, [image].[Description] AS imageAlternateText FROM Product AS prdct CROSS APPLY (SELECT TOP 1 imgs.Url, imgs.Name, imgs.[Description] FROM Images AS imgs WHERE imgs.ProductId = prdct.Id AND imgs.[Primary] = 1) AS [image]",
                    null,
                    null,
                    true,
                    null,
                    null))
                .Return(new ProductBoxViewModel[] { });

            homeController.Index();

            dbConnection.VerifyAllExpectations();
        }