예제 #1
0
        public void Gallery_Product_PassDataViewWithApiMock()
        {
            var webhost = new Mock <IWebHostEnvironment>();
            var product = new GetProductViewModel {
                Customer = "Test"
            };
            var GetAllProductvm = new GetAllProductViewModel {
                CountOnPage = 1, CurrentPage = 1, Products = new List <GetProductViewModel> {
                    product
                }
            };
            var api = new Mock <IGetProductApi>();

            api.Setup(c => c.GetAll(It.IsAny <GetAllProductViewModel>())).Returns(new GetAllProductViewModel {
                Products = new List <GetProductViewModel> {
                    product
                }
            });
            var mycontroller = new HomeController(api.Object, webhost.Object);

            var result = mycontroller.Gallery(new GetAllProductViewModel {
                Products = new List <GetProductViewModel> {
                    product
                }
            });

            var ViewResult     = Assert.IsType <ViewResult>(result);
            var myobjectresult = Assert.IsType <GetAllProductViewModel>(ViewResult.Model);

            Assert.True(myobjectresult.Products.Count > 0);
        }
예제 #2
0
 public IActionResult Gallery(GetAllProductViewModel model)
 {
     ViewBag.TotalPage = api.TotalPage(new TotalPageProductViewModel {
         CountOnPage = model.CountOnPage
     });
     return(View(api.GetAll(model)));
 }
예제 #3
0
        public IActionResult Index(GetAllProductViewModel model)
        {
            var TotalPage = api.TotalPage(new TotalPageProductViewModel {
                CountOnPage = 50
            });

            model.CountOnPage = 50;
            var GetAllProduct     = api.GetAll(model);
            var ListProductUpdate = GetAllProduct.Products.Select(c => new UpdateProductViewModel
            {
                Product = new GetProductViewModel
                {
                    Category    = c.Category,
                    Customer    = c.Customer,
                    Description = c.Description,
                    EndDate     = c.EndDate,
                    Images      = c.Images,
                    Services    = c.Services,
                    SiteName    = c.SiteName,
                    SiteUrl     = c.SiteUrl,
                    StartDate   = c.StartDate,
                    Tags        = c.Tags
                },
                ProductBefore = new FindProductViewModel
                {
                    Customer = c.Customer,
                    SiteName = c.SiteName,
                    SiteUrl  = c.SiteUrl
                }
            }).ToList();

            var NewModel = new GetAllProductForAdminViewModel
            {
                Products    = ListProductUpdate,
                CountOnPage = 50,
                CurrentPage = model.CurrentPage,
                TotalPage   = TotalPage
            };

            return(View(NewModel));
        }