Exemplo n.º 1
0
        public void DirectoryController_DeleteFileTest_DeleteFile_ReturnedCorrectView()
        {
            //controller = new DirectoryController(mockFileService.Object);
            //controller.ControllerContext = new ControllerContext(HttpContextBaseMock.Object, new RouteData(), controller);
            mockFileService.Setup(a => a.DeleteFile(It.IsAny <string>())).Returns(true);


            var result = controller.DeleteFile("D\\hhhhh\\New Text Document.txt") as RedirectToRouteResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Table", result.RouteValues["action"]);
        }
        public void DeleteFile_ThrowException_ReturnJsonResult()
        {
            directoryServiceMock.Setup(a => a.GetAllDirectories(It.IsAny <String>())).Throws <UnauthorizedAccessException>();
            DirectoryController controller = new DirectoryController(directoryServiceMock.Object, fileServiceMock.Object, searchServiceMock.Object);

            JsonResult result = controller.DeleteFile("D/") as JsonResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("{ Status = NotAcceptable }", result.Data.ToString());
        }
        public void DeleteFile_EmptyPath_RedirectToAnotherUrl()
        {
            string expected = "/Drive/GetDrives/";
            DirectoryController controller = new DirectoryController(directoryServiceMock.Object, fileServiceMock.Object, searchServiceMock.Object);

            RedirectResult result = controller.DeleteFile("") as RedirectResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result.Url);
        }
        public void DeleteFile_PositiveTest_DeleteDirectory()
        {
            fileServiceMock.Setup(a => a.GetParrent(It.IsAny <string>())).Returns("D/");
            DirectoryController controller = new DirectoryController(directoryServiceMock.Object, fileServiceMock.Object, searchServiceMock.Object);

            controller.ControllerContext = new ControllerContext(HttpContextBaseMock.Object, new RouteData(), controller);

            ViewResult result = controller.DeleteFile("D/data/") as ViewResult;

            Assert.IsNotNull(result);
            fileServiceMock.Verify(a => a.DeleteFile("D:/data"));
        }
        public void DeleteFile_PositiveTest_ReturnCorrectModel()
        {
            fileServiceMock.Setup(a => a.GetParrent(It.IsAny <string>())).Returns("D/");
            DirectoryController controller = new DirectoryController(directoryServiceMock.Object, fileServiceMock.Object, searchServiceMock.Object);

            controller.ControllerContext = new ControllerContext(HttpContextBaseMock.Object, new RouteData(), controller);

            ViewResult result = controller.DeleteFile("D/data/") as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("D\\\\", result.ViewData["LastPath"]);
        }