示例#1
0
        public void CleanupHandlesDirectoryExceptions()
        {
            IFileService fileServiceProvider = Substitute.For<IFileService>();
            MemoryStream memoryStream = new MemoryStream();
            fileServiceProvider.CreateFileStream("").ReturnsForAnyArgs(memoryStream);
            IDirectoryInformation directoryInfo = Substitute.For<IDirectoryInformation>();
            IFileInformation fileInfo = Substitute.For<IFileInformation>();
            directoryInfo.EnumerateChildren().ReturnsForAnyArgs(new IFileInformation[] { fileInfo });
            fileServiceProvider.GetPathInfo("").ReturnsForAnyArgs(directoryInfo);

            using (FileCleaner cleaner = new FileCleaner("Test", fileServiceProvider))
            {
                fileServiceProvider.WhenForAnyArgs(f => f.DeleteDirectory("")).Do(a => { throw new Exception("TestException"); });
            }
        }
示例#2
0
        public void FlagFileCreationTest()
        {
            IFileService fileServiceProvider = Substitute.For<IFileService>();
            MemoryStream memoryStream = new MemoryStream();
            fileServiceProvider.CreateFileStream("").ReturnsForAnyArgs(memoryStream);

            using (FileCleaner cleaner = new FileCleaner("Test", fileServiceProvider))
            {
                cleaner.TempFolder.Should().StartWith(Path.Combine(Path.GetTempPath(), "Test"));
                fileServiceProvider.Received(1).CreateFileStream(
                    Path.Combine(cleaner.TempFolder, TestFileCleaner.TestFlagFileName),
                    FileMode.OpenOrCreate,
                    FileAccess.ReadWrite);

                memoryStream.Position = 0;
                StreamReader reader = new StreamReader(memoryStream);
                reader.ReadToEnd().Should().StartWith(XTaskStrings.FlagFileContent);
            }
        }