public ActionResult AdminProductUpdate(AdminProductUpdate model, IEnumerable <HttpPostedFileBase> files) { var productservice = new ProductsService(); var photoservice = new ProductPhotoService(); var product = new Products() { ProductID = model.ProductID, ProductName = model.ProductName, UnitPrice = model.UnitPrice, CategoryID = model.CategoryID, ProductDetails = model.ProductDetails, Size = model.Size, Color = model.Color, UnitsInStock = model.UnitsInStock }; productservice.Update(product); foreach (var file in files) { if (file != null && file.ContentLength > 0) { var fileName = Path.GetFileName(file.FileName); var path = Path.Combine(Server.MapPath("~/Images"), fileName); file.SaveAs(path); photoservice.Create(new ProductPhoto { ProductID = model.ProductID, PhotoPath = "https://bingshop.azurewebsites.net/Images/" + fileName }); } } return(RedirectToAction("Product", "admin")); }
public async void Create() { var mock = new ServiceMockFacade <IProductPhotoRepository>(); var model = new ApiProductPhotoRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <ProductPhoto>())).Returns(Task.FromResult(new ProductPhoto())); var service = new ProductPhotoService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.ProductPhotoModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLProductPhotoMapperMock, mock.DALMapperMockFactory.DALProductPhotoMapperMock, mock.BOLMapperMockFactory.BOLProductProductPhotoMapperMock, mock.DALMapperMockFactory.DALProductProductPhotoMapperMock); CreateResponse <ApiProductPhotoResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.ProductPhotoModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiProductPhotoRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <ProductPhoto>())); }