コード例 #1
0
        public void Get_DirectoryDoesntExist_NotFoundAsync()
        {
            // arrange
            const string path             = "this/path/does/not/exist";
            var          stubFileProvider = new Mock <IFileProvider>();
            var          mockDirectory    = new Mock <IDirectoryContents>();

            mockDirectory.Setup(x => x.Exists).Returns(false);

            stubFileProvider.Setup(x => x.GetDirectoryContents(path)).Returns(mockDirectory.Object);
            var mockConfigProvider = new Mock <IConfiguration>();

            var sut = new rest_file_api.controllers.FileRestApiController(mockConfigProvider.Object, stubFileProvider.Object);

            // act
            var result = sut.Get(path);

            // assert
            var actionResult = Assert.IsType <ActionResult <ApiDirectory> >(result);

            Assert.IsAssignableFrom <NotFoundObjectResult>(actionResult.Result);
        }
コード例 #2
0
        public void Get_DirectoryExists_ReturnsDirectory()
        {
            // arrange
            const string path             = "this/path/exists";
            var          stubFileProvider = new Mock <IFileProvider>();
            var          mockDirectory    = new Mock <IDirectoryContents>();

            mockDirectory.Setup(x => x.Exists).Returns(true);
            mockDirectory.Setup(x => x.GetEnumerator()).Returns(new List <IFileInfo>().GetEnumerator());

            stubFileProvider.Setup(x => x.GetDirectoryContents(path)).Returns(mockDirectory.Object);
            var mockConfigProvider = new Mock <IConfiguration>();

            var sut = new rest_file_api.controllers.FileRestApiController(mockConfigProvider.Object, stubFileProvider.Object);

            // act
            var result = sut.Get(path);

            // assert
            var actionResult = Assert.IsType <ActionResult <ApiDirectory> >(result);
            var apiResult    = Assert.IsType <ApiDirectory>(actionResult.Value);

            Assert.NotNull(apiResult);
        }