コード例 #1
0
        public void ReturnDefaultView_WhenGetToIndex()
        {
            // Arrange
            var brandsService = new Mock <IBrandsService>();

            var controller = new BrandsController(brandsService.Object);

            // Act && Assert
            controller.WithCallTo(c => c.Index()).ShouldRenderDefaultView();
        }
コード例 #2
0
        public void ReturnJsonResult_WhenGetToBrands_Read()
        {
            //Arrange
            var brandsService    = new Mock <IBrandsService>();
            var brands           = DataHelper.GetBrands();
            var kendoDataRequest = new DataSourceRequest();

            brandsService.Setup(x => x.GetAll()).Returns(brands);

            var controller = new BrandsController(brandsService.Object);

            //Act & Assert
            controller.WithCallTo(c => c.Brands_Read(kendoDataRequest)).ShouldReturnJson();
        }
コード例 #3
0
        public void ReturnJsonResult_WhenGetToBrands_Create()
        {
            //Arrange
            var brandsService    = new Mock <IBrandsService>();
            var brandViewModel   = DataHelper.GetAdminBrandViewModel();
            var kendoDataRequest = new DataSourceRequest();

            brandsService.Setup(x => x.Create(It.IsAny <Brand>())).Verifiable();

            var controller = new BrandsController(brandsService.Object);

            //Act & Assert
            controller.WithCallTo(c => c.Brands_Create(kendoDataRequest, brandViewModel)).ShouldReturnJson();
        }
コード例 #4
0
        public void IndexPageShouldWorkCorrectlyPassingBrandName()
        {
            IQueryable<Product> productsAsQueryable = this.products.AsQueryable();
            productServiceMock.Setup(h => h.GetAllByBrand("Adidas", null))
                .Returns(productsAsQueryable.Where(p => p.Brand.Name == "Adidas"));

            var controller = new BrandsController(productServiceMock.Object);
            controller.WithCallTo(h => h.Index("Adidas", 1, null, "Likes", "Desc"))
                .ShouldRenderPartialView("_ProductsPartial")
                .WithModel<PaginationViewModel>(viewModel =>
                {
                    Assert.AreEqual(1, viewModel.Products.Count);
                })
                .AndNoModelErrors();
        }
コード例 #5
0
        public void IndexPageShouldWorkCorrectlyPassingSortByLikesAsc()
        {
            const string SortBy = "Likes";
            IQueryable<Product> productsAsQueryable = this.products.AsQueryable();
            productServiceMock.Setup(h => h.GetAllByBrand(null, null))
                .Returns(productsAsQueryable);

            var controller = new BrandsController(productServiceMock.Object);
            controller.WithCallTo(h => h.Index(null, 1, null, SortBy, "Asc"))
                .ShouldRenderPartialView("_ProductsPartial")
                .WithModel<PaginationViewModel>(viewModel =>
                {
                    Assert.AreEqual("Product 3", viewModel.Products.FirstOrDefault().Title);
                })
                .AndNoModelErrors();
        }
コード例 #6
0
        public void IndexPageShouldWorkCorrectlyPassingQuery()
        {
            const string Query = "Product 2";
            IQueryable<Product> productsAsQueryable = this.products.AsQueryable();
            productServiceMock.Setup(h => h.GetAllByBrand(null, Query))
                .Returns(productsAsQueryable.Where(p => p.Title.Contains(Query)));

            var controller = new BrandsController(productServiceMock.Object);
            controller.WithCallTo(h => h.Index(null, 1, Query, "Likes", "Desc"))
                .ShouldRenderPartialView("_ProductsPartial")
                .WithModel<PaginationViewModel>(viewModel =>
                {
                    Assert.AreEqual(1, viewModel.Products.Count);
                })
                .AndNoModelErrors();
        }