Example #1
0
 private static void SetupDirectories(IFileSystem fs, string[] names)
 {
     fs.GetFileSystemEntries(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <SearchOption>())
     .ReturnsForAnyArgs(c => names);
     fs.GetFileAttributes(Arg.Any <string>())
     .ReturnsForAnyArgs(c => FileAttributes.Directory);
 }
 public static IFileInfo Delete(IFileSystem fileSystem, string path) {
     var fi = Substitute.For<IFileInfo>();
     fi.FullName.Returns(path);
     fi.Exists.Returns(false);
     fi.Directory.Returns((IDirectoryInfo)null);
     fileSystem.FileExists(path).Returns(false);
     try {
         fileSystem.GetFileAttributes(path).Throws<FileNotFoundException>();
     } catch (IOException) { }
     return fi;
 }
Example #3
0
        public static IFileInfo Delete(IFileSystem fileSystem, string path)
        {
            var fi = Substitute.For <IFileInfo>();

            fi.FullName.Returns(path);
            fi.Exists.Returns(false);
            fi.Directory.Returns((IDirectoryInfo)null);
            fileSystem.FileExists(path).Returns(false);
            try {
                fileSystem.GetFileAttributes(path).Throws <FileNotFoundException>();
            } catch (IOException) { }
            return(fi);
        }
        public static IFileInfo Create(IFileSystem fileSystem, string path) {
            var fi = Substitute.For<IFileInfo>();
            fi.FullName.Returns(path);
            fi.Exists.Returns(true);
            fi.Directory.Returns((IDirectoryInfo)null);
            fileSystem.FileExists(path).Returns(true);

            try {
                fileSystem.GetFileAttributes(path);
            } catch (IOException) {
                default(FileAttributes).Returns(FileAttributes.Normal);
            }

            return fi;
        }
Example #5
0
        private static bool IsFileAllowed(string rootDirectory, string fullPath, IFileSystem fileSystem, IMsBuildFileSystemFilter filter, out string relativePath)
        {
            if (!fullPath.StartsWithIgnoreCase(rootDirectory))
            {
                relativePath = null;
                return(false);
            }

            relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
            try {
                return(filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath)));
            } catch (IOException) {
                // File isn't allowed if it isn't accessable
                return(false);
            }
        }
Example #6
0
        public static IFileInfo Create(IFileSystem fileSystem, string path)
        {
            var fi = Substitute.For <IFileInfo>();

            fi.FullName.Returns(path);
            fi.Exists.Returns(true);
            fi.Directory.Returns((IDirectoryInfo)null);
            fileSystem.FileExists(path).Returns(true);

            try {
                fileSystem.GetFileAttributes(path);
            } catch (IOException) {
                default(FileAttributes).Returns(FileAttributes.Normal);
            }

            return(fi);
        }
            public NoDelayNoFiltering()
            {
                _fileSystem = Substitute.For<IFileSystem>();
                _fileSystem.GetFileAttributes(Arg.Any<string>()).Throws<FileNotFoundException>();
                var watchers = GetWatchersFromMsBuildFileSystemWatcher(_fileSystem);

                var fileSystemFilter = Substitute.For<IMsBuildFileSystemFilter>();
                fileSystemFilter.IsFileAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);
                fileSystemFilter.IsDirectoryAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);

                _taskScheduler = new ControlledTaskScheduler(SynchronizationContext.Current);

                _fileSystemWatcher = new MsBuildFileSystemWatcher(ProjectDirectory, "*", 0, _fileSystem, fileSystemFilter, _taskScheduler, NullLog.Instance);
                _fileSystemWatcher.Start();

                _fileWatcher = watchers.FileWatcher;
                _directoryWatcher = watchers.DirectoryWatcher;
                _attributesWatcher = watchers.AttributesWatcher;
            }
            public NoDelayNoFiltering()
            {
                _fileSystem = Substitute.For <IFileSystem>();
                _fileSystem.GetFileAttributes(Arg.Any <string>()).Throws <FileNotFoundException>();
                var watchers = GetWatchersFromMsBuildFileSystemWatcher(_fileSystem);

                var fileSystemFilter = Substitute.For <IMsBuildFileSystemFilter>();

                fileSystemFilter.IsFileAllowed(Arg.Any <string>(), Arg.Any <FileAttributes>()).ReturnsForAnyArgs(true);
                fileSystemFilter.IsDirectoryAllowed(Arg.Any <string>(), Arg.Any <FileAttributes>()).ReturnsForAnyArgs(true);

                _taskScheduler = new ControlledTaskScheduler(SynchronizationContext.Current);

                DirectoryInfoStubFactory.Create(_fileSystem, ProjectDirectory);
                _fileSystemWatcher = new MsBuildFileSystemWatcher(ProjectDirectory, "*", 0, 0, _fileSystem, fileSystemFilter, _taskScheduler, NullLog.Instance);
                _fileSystemWatcher.Start();

                _fileWatcher       = watchers.FileWatcher;
                _directoryWatcher  = watchers.DirectoryWatcher;
                _attributesWatcher = watchers.AttributesWatcher;
            }
            public NoDelayNoFiltering() {
                _fileSystem = Substitute.For<IFileSystem>();
                _fileSystem.GetFileAttributes(Arg.Any<string>()).Throws<FileNotFoundException>();
                _fileSystem.ToLongPath(Arg.Any<string>()).Returns(ci => ci[0]);
                _fileSystem.ToShortPath(Arg.Any<string>()).Returns(ci => ci[0]);
                var watchers = GetWatchersFromMsBuildFileSystemWatcher(_fileSystem);

                var fileSystemFilter = Substitute.For<IMsBuildFileSystemFilter>();
                fileSystemFilter.IsFileAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);
                fileSystemFilter.IsDirectoryAllowed(Arg.Any<string>(), Arg.Any<FileAttributes>()).ReturnsForAnyArgs(true);

                _taskScheduler = new ControlledTaskScheduler(SynchronizationContext.Current);

                DirectoryInfoStubFactory.Create(_fileSystem, ProjectDirectory);
                _fileSystemWatcher = new MsBuildFileSystemWatcher(ProjectDirectory, "*", 0, 0, _fileSystem, fileSystemFilter, Substitute.For<IActionLog>(), _taskScheduler);
                _fileSystemWatcher.Start();

                _fileWatcher = watchers.FileWatcher;
                _directoryWatcher = watchers.DirectoryWatcher;
                _attributesWatcher = watchers.AttributesWatcher;
            }
Example #10
0
 private static bool IsFileAllowed(string rootDirectory, string fullPath,
                                   IFileSystem fileSystem, IMsBuildFileSystemFilter filter,
                                   out string relativePath, out string shortRelativePath)
 {
     relativePath      = null;
     shortRelativePath = null;
     if (fullPath.StartsWithIgnoreCase(rootDirectory))
     {
         relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
         try {
             shortRelativePath = fileSystem.ToShortRelativePath(fullPath, rootDirectory);
             return(!string.IsNullOrEmpty(shortRelativePath) && filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath)));
         } catch (IOException) { } catch (UnauthorizedAccessException) { } // File isn't allowed if it isn't accessible
     }
     return(false);
 }
 public static int GetFileAttributes(String szFilename, out FileAttributesEnum dwFileAttributes)
 {
     return(m_fileSystemIo.GetFileAttributes(szFilename, out dwFileAttributes));
 }
        private static bool IsFileAllowed(string rootDirectory, string fullPath, IFileSystem fileSystem, IMsBuildFileSystemFilter filter, out string relativePath) {
            if (!fullPath.StartsWithIgnoreCase(rootDirectory)) {
                relativePath = null;
                return false;
            }

            relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
            try {
                return filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath));
            } catch (IOException) {
                // File isn't allowed if it isn't accessable
                return false;
            }
        }
 private static bool IsFileAllowed(string rootDirectory, string fullPath,
     IFileSystem fileSystem, IMsBuildFileSystemFilter filter,
     out string relativePath, out string shortRelativePath) {
     relativePath = null;
     shortRelativePath = null;
     if (fullPath.StartsWithIgnoreCase(rootDirectory)) {
         relativePath = PathHelper.MakeRelative(rootDirectory, fullPath);
          try {
             shortRelativePath = fileSystem.ToShortRelativePath(fullPath, rootDirectory);
             return !string.IsNullOrEmpty(shortRelativePath) && filter.IsFileAllowed(relativePath, fileSystem.GetFileAttributes(fullPath));
         } catch (IOException) { } catch (UnauthorizedAccessException) { } // File isn't allowed if it isn't accessible
     }
     return false;
 }