public void CreateAndDeleteFile(IFileInfo fi) { FileStreamBase fs = fi.Create(); fs.Close(); fi.Delete(); }
private void Create(IFileInfo zipFile) { using (ZipArchive archive = new ZipArchive(zipFile.Create(), ZipArchiveMode.Create)) { addEntryFromSourceFile(archive); } }
public void SetUp() { _directoryInfo = _fileSystem.DirectoryInfo.FromDirectoryName(FolderPath); _directoryInfo.Create(); _sourceFileInfo = _fileSystem.FileInfo.FromFileName(GetPlatformSourcePath()); _targetFileInfo = _fileSystem.FileInfo.FromFileName(GetPlatformTargetPath()); using Stream stream = _sourceFileInfo.Create(); }
static bool ImportFile(string[] args) { if (args[0] == "?") { Console.WriteLine("Imports file into current directory."); Console.WriteLine("import source filename [-o]"); Console.WriteLine("-o - Overwrite enabled."); return(false); } string source = args[0]; string filename = args[1]; bool overwrite = args.Length > 2 ? args[2] == "-o" : false; IFileInfo[] files = currentDirectory.GetFiles(); for (int i = 0; i < files.Length; i++) { if (files[i].Name.Trim('\0') == filename) { try { if (overwrite) { files[i].WriteAllBytes(File.ReadAllBytes(source)); files[i].Create(); return(true); } else { Console.WriteLine("File already exists."); return(false); } } catch (Exception ex) { Console.WriteLine("ERROR: " + ex.Message); return(false); } } } // If file is new IFileInfo file = currentDirectory.CreateFile(filename); try { file.WriteAllBytes(File.ReadAllBytes(source)); file.Create(); return(true); } catch (Exception ex) { Console.WriteLine("ERROR: " + ex.Message); return(false); } }
public void Check_that_FileInfo_methods_Create_and_Delete_are_called() { // Add mock repository. IFileInfo fileInfoRepository = Substitute.For <IFileInfo>(); FileStreamBase fileStreamRepository = Substitute.For <FileStreamBase>(); // Create expectations fileInfoRepository.Create().Returns(fileStreamRepository); // Test new FileInfoSample().CreateAndDeleteFile(fileInfoRepository); // Verify expectations. fileStreamRepository.Received().Close(); fileInfoRepository.Received().Delete(); }
private void When_creating_file_it_must_succeed() { // Arrange const string path = @"c:\some\file.txt"; IFileSystem fileSystem = new FakeFileSystemBuilder() .IncludingDirectory(@"c:\some") .Build(); IFileInfo fileInfo = fileSystem.ConstructFileInfo(path); // Act using (fileInfo.Create()) { } // Assert fileSystem.File.Exists(path).Should().BeTrue(); fileSystem.File.ReadAllText(path).Should().Be(string.Empty); }
public byte[] Create(byte[] entity) { var fileName = GenerateFileName(); try { IFileInfo fileInfo = FileInfoFactory.CreateFileInfo(fileName); using (var stream = fileInfo.Create()) { stream.Write(entity, 0, entity.Length); } return(entity); } catch (IOException) { throw new RepositoryException(string.Format("Unable to create entry with filename: {0}", fileName)); } catch (Exception e) { throw new UnityException("Unable to create entity", e); } }