public void CopyToMillisecondPresent_HFS() { FileInfo input = new FileInfo(Path.Combine(TestDirectory, GetTestFileName())); input.Create().Dispose(); FileInfo output = new FileInfo(Path.Combine(TestDirectory, GetTestFileName(), input.Name)); string driveFormat = new DriveInfo(input.DirectoryName).DriveFormat; if (driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase)) { output.Directory.Create(); output = input.CopyTo(output.FullName, true); Assert.Equal(0, input.LastWriteTime.Millisecond); Assert.Equal(0, output.LastWriteTime.Millisecond); } }
[PlatformSpecific(TestPlatforms.AnyUnix)] // Windows tested below, and OSX HFS driver format does not support millisec granularity public void TimesIncludeMillisecondPart_Unix() { T item = GetExistingItem(); string driveFormat = new DriveInfo(GetItemPath(item)).DriveFormat; if (!PlatformDetection.IsOSX || !driveFormat.Equals(HFS, StringComparison.InvariantCultureIgnoreCase)) { Assert.All(TimeFunctions(), (function) => { var msec = 0; for (int i = 0; i < 5; i++) { DateTime time = function.Getter(item); msec = time.Millisecond; if (msec != 0) { break; } // This case should only happen 1/1000 times, unless the OS/Filesystem does // not support millisecond granularity. // If it's 1/1000, or low granularity, this may help: Thread.Sleep(1234); // If it's the OS/Filesystem often returns 0 for the millisecond part, this may // help prove it. This should only be written 1/1000 runs, unless the test is going to // fail. Console.WriteLine($"## TimesIncludeMillisecondPart got a file time of {time.ToString("o")} on {driveFormat}"); item = GetExistingItem(); // try a new file/directory } Assert.NotEqual(0, msec); }); } }