public void ShouldSaveUnicodeToFile() { SystemPath tempFile = tempRoot.Combine("foo.txt"); Assert.IsFalse(tempFile.Exists()); new SystemIoFileSystem().Save(tempFile.ToString(), "hi there? håkan! \u307b"); Assert.IsTrue(tempFile.Exists()); using (StreamReader reader = File.OpenText(tempFile.ToString())) { Assert.AreEqual("hi there? håkan! \u307b", reader.ReadToEnd()); } }
protected void DeleteTempDir() { if (tempDir.Exists()) { tempDir.DeleteDirectory(); } }
public void ShouldAllowOverwrites() { SystemPath sourceFile = tempRoot.CreateEmptyFile("File1"); SystemPath targetFile = tempSubRoot.CreateEmptyFile("File2"); new SystemIoFileSystem().Copy(sourceFile.ToString(), targetFile.ToString()); Assert.IsTrue(targetFile.Exists()); }
public void ShouldSaveToFileAtomically() { SystemPath tempFile = tempRoot.Combine("foo.txt"); Assert.IsFalse(tempFile.Exists()); new SystemIoFileSystem().AtomicSave(tempFile.ToString(), "bar"); Assert.IsTrue(tempFile.Exists()); using (StreamReader reader = File.OpenText(tempFile.ToString())) { Assert.AreEqual("bar", reader.ReadToEnd()); } new SystemIoFileSystem().AtomicSave(tempFile.ToString(), "baz"); Assert.IsTrue(tempFile.Exists()); using (StreamReader reader = File.OpenText(tempFile.ToString())) { Assert.AreEqual("baz", reader.ReadToEnd()); } }
public void ShouldAllowOverwritesEvenWhenDestinationHasReadOnlyAttributeSet() { SystemPath sourceFile = tempRoot.CreateEmptyFile("File1"); SystemPath targetFile = tempSubRoot.CreateEmptyFile("File2"); File.SetAttributes(targetFile.ToString(), FileAttributes.ReadOnly); new SystemIoFileSystem().Copy(sourceFile.ToString(), targetFile.ToString()); Assert.IsTrue(targetFile.Exists()); }
public void MissingDirectoryThrowsException() { Assert.IsFalse(tempRoot.Exists(), "Temporary directory should not exist: " + tempRoot.ToString()); Assert.That(delegate { sc.GetModifications(IntegrationResult(DateTime.MinValue), IntegrationResult(DateTime.MaxValue)); }, Throws.TypeOf <DirectoryNotFoundException>()); }