public async Task DeleteAsync_Test() { var dmsFileService = new DmsFileService(_context); var dmsContorller = new PdfController(dmsFileService); //Act var result = await dmsContorller.DeleteAsync("Test.pdf"); //Assert var afterCount = await _context.DmsFiles.CountAsync(); Assert.IsTrue(afterCount == 0); Assert.IsNotNull(result); }
public async Task DeleteAsync_FileNotFoundTest() { var fileName = "Test.pdf"; var mockFileService = new Mock <IDmsFileService>(); mockFileService.Setup(x => x.CheckFileExistAsync(It.IsAny <string>())) .Returns(Task.FromResult <bool>(false)) .Verifiable(); var contorller = new PdfController(mockFileService.Object); //Act var result = await contorller.DeleteAsync(fileName) as ObjectResult; //Assert Assert.IsInstanceOf <IActionResult>(result); Assert.AreEqual(400, result.StatusCode); Assert.AreEqual("File not found: Test.pdf", result.Value.ToString()); }
public async Task DeleteAsync_Test() { var fileName = "Test.pdf"; var mockFileService = new Mock <IDmsFileService>(); mockFileService.Setup(x => x.CheckFileExistAsync(It.IsAny <string>())) .Returns(Task.FromResult <bool>(true)) .Verifiable(); mockFileService.Setup(x => x.DeleteFileAsync(fileName)) .Verifiable(); var contorller = new PdfController(mockFileService.Object); //Act var result = await contorller.DeleteAsync(fileName); //Assert Assert.IsInstanceOf <IActionResult>(result); }