public virtual void TestRenameNonexistentFile() { Describe("rename a file into a new file in the same directory"); Path missing = Path("testRenameNonexistentFileSrc"); Path target = Path("testRenameNonexistentFileDest"); bool renameReturnsFalseOnFailure = IsSupported(ContractOptions.RenameReturnsFalseIfSourceMissing ); Mkdirs(missing.GetParent()); try { bool renamed = Rename(missing, target); //expected an exception if (!renameReturnsFalseOnFailure) { string destDirLS = GenerateAndLogErrorListing(missing, target); NUnit.Framework.Assert.Fail("expected rename(" + missing + ", " + target + " ) to fail," + " got a result of " + renamed + " and a destination directory of " + destDirLS ); } else { // at least one FS only returns false here, if that is the case // warn but continue GetLog().Warn("Rename returned {} renaming a nonexistent file", renamed); NUnit.Framework.Assert.IsFalse("Renaming a missing file returned true", renamed); } } catch (FileNotFoundException e) { if (renameReturnsFalseOnFailure) { ContractTestUtils.Fail("Renaming a missing file unexpectedly threw an exception", e); } HandleExpectedException(e); } catch (IOException e) { HandleRelaxedException("rename nonexistent file", "FileNotFoundException", e); } AssertPathDoesNotExist("rename nonexistent file created a destination file", target ); }