public void TestExtractDateStringSuccess() { Regex regex = new Regex(@"^C:\\Music\\(\d{4}-\d{2}-\d{2})\ recording.mp3$"); string path = @"C:\Music\2020-01-31 recording.mp3"; Assert.AreEqual(FileSync.ExtractDateString(regex, path), "2020-01-31&"); regex = new Regex(@"^C:\\Music\\(\d{4}-\d{2}-\d{2})\ recording.mp3$"); path = @"C:\Music\2020-01-30 recording.mp3"; Assert.AreEqual(FileSync.ExtractDateString(regex, path), "2020-01-30&"); }
public void TestExtractDateStringExceptions() { Regex regex = new Regex(@"^C:\\Music\\(\d{4}-\d{2}-\d{2})\ recording.mp3$"); string path = @"C:\Music\2020-01-30.mp3"; try { FileSync.ExtractDateString(regex, path); Assert.Fail(); } catch { Assert.IsTrue(true); } regex = new Regex(@"^C:\\Music\\(\d{4}-\d{2}-\d{2})\ recording.mp3$"); path = @"C:\Music\2020-01-3 recording.mp3"; try { FileSync.ExtractDateString(regex, path); Assert.Fail(); } catch { Assert.IsTrue(true); } }