public async Task SaveFile_Test() { string fileName = "carousel1.jpg"; mockFormFile = new Mock <IFormFile>(); mockFormFile.Setup(x => x.FileName) .Returns(fileName); mockFormFile.Setup(x => x.CopyToAsync(It.IsAny <Stream>(), It.IsAny <CancellationToken>())); string resultFileName = await _service.SaveFile(mockFormFile.Object, AppContext.BaseDirectory); Assert.AreNotEqual(fileName, resultFileName); mockFormFile.Verify(x => x.CopyToAsync(It.IsAny <Stream>(), It.IsAny <CancellationToken>())); }
public async Task <IActionResult> AddItem(ItemModel model) { if (ModelState.IsValid) { string directory = "Images"; string fileName = await _saveFileService.SaveFile(model.image, Path.Combine(_env.WebRootPath, directory)); Item item = new Item() { description = model.description, price = model.price, title = model.title, imagePath = Path.Combine(directory, fileName), CategoryId = model.categoryId }; await _itemService.AddItem(item); } return(RedirectToAction("GetItemsPage")); }