예제 #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();
        }
        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();
        }
        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();
        }
        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();
        }