public async Task GetDetailsAsync_WithId_ShouldReturnManufacturerDetailsViewModel() { this._dbContext.Products.Add(new Product() { Name = string.Format(TestsConstants.Product, 1), ManufacturerId = 1 }); this._dbContext.Products.Add(new Product() { Name = string.Format(TestsConstants.Product, 2), ManufacturerId = 1 }); this._dbContext.SaveChanges(); var manufacturerFromService = await this._service.GetDetails(1); var manufacturerDetailsViewModel = new ManufacturerDetailsViewModel() { Name = string.Format(TestsConstants.Manufacturer, 1), LogoUrl = string.Format(TestsConstants.Logo, 1) }; Assert.AreEqual(manufacturerDetailsViewModel.LogoUrl, manufacturerFromService.LogoUrl); Assert.AreEqual(manufacturerDetailsViewModel.Name, manufacturerFromService.Name); }
public async Task GetDetailsAsync_WithId_ShouldReturnTypeofManufacturerDetailsViewModel() { var manufacturerFromService = await this._service.GetDetails(1); var manufacturerDetailsViewModel = new ManufacturerDetailsViewModel() { Name = string.Format(TestsConstants.Test, 1), LogoUrl = string.Format(TestsConstants.Logo, 1) }; Assert.IsInstanceOfType(manufacturerFromService, typeof(ManufacturerDetailsViewModel)); }
private ManufacturerDetailsViewModel CreateModel(dynamic manufacturer) { var model = new ManufacturerDetailsViewModel(); model.LogoUrl = manufacturer.LogoId; model.Name = manufacturer.Name; var products = new List <ProductIndexViewModel>(); foreach (var product in manufacturer.Products) { products.Add(new ProductIndexViewModel { Id = product.Id, Name = product.Name, Price = product.Price, Discount = product.Discount, PictureUrl = product.PictureUrl }); } model.Products = products; return(model); }
private ManufacturerProductsViewModel ManufacturerProductsViewModel(int id, int currentPage, int maxPage, string actionName, ManufacturerDetailsViewModel manufacturerDetailsViewModel) { var pageViewModel = new PagesViewModel { CurrentPage = currentPage, MaxPage = maxPage, AreaName = "", ActionName = actionName, ControllerName = _controllerName, RouteId = id }; var manufacturers = GetAllManufacturers(); return(new ManufacturerProductsViewModel { Manufacturers = manufacturers, ManufacturerWithProducts = manufacturerDetailsViewModel, Page = pageViewModel }); }