コード例 #1
0
        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);
        }
コード例 #2
0
        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());
        }
コード例 #3
0
        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);
        }