public async Task FiresEventCorrectlyWithOverwrite() { var fs = new MockFileSystem(); var directoryCopier = new DirectoryCopier(fs, "C:\\fakeDir", "C:\\SFM", true); var d1 = Encoding.UTF8.GetBytes("Hello"); var d2 = Encoding.UTF8.GetBytes("Konnichiwa"); fs.CreateFile("C:\\fakeDir\\file1.txt", d1); fs.CreateFile("C:\\SFM\\file1.txt", d2); DirectoryCopierFileExistsEventArgs eventArgs = null; directoryCopier.OnFileExists += delegate(object sender, DirectoryCopierFileExistsEventArgs e) { eventArgs = e; e.FileCopyMode = DirectoryCopierFileCopyMode.Copy; }; await directoryCopier.Execute(); Assert.AreNotEqual(null, eventArgs); Assert.AreEqual(eventArgs.File1, "C:\\fakeDir\\file1.txt"); Assert.AreEqual(fs.ReadFile("C:\\fakeDir\\file1.txt"), d1); Assert.AreEqual(eventArgs.File2, "C:\\SFM\\file1.txt"); Assert.AreEqual(fs.ReadFile("C:\\SFM\\file1.txt"), d1); }
public async Task FiresEventCorrectly() { var fs = new MockFileSystem(); var directoryCopier = new DirectoryCopier(fs, "C:\\fakeDir", "C:\\SFM", true); var copiedFiles = new List <Tuple <string, string> >(); var progressHistory = new List <int>(); fs.CreateFile("C:\\fakeDir\\file1.txt"); fs.CreateFile("C:\\SFM\\file1.txt"); DirectoryCopierFileExistsEventArgs eventArgs = null; directoryCopier.OnFileExists += delegate(object sender, DirectoryCopierFileExistsEventArgs e) { eventArgs = e; }; directoryCopier.OnFileCopy += delegate(object sender, DirectoryCopierCopyEventArgs e) { copiedFiles.Add(new Tuple <string, string>(e.File1, e.File2)); }; directoryCopier.OnProgress += delegate(object sender, DirectoryProgressEventArgs e) { progressHistory.Add(e.Progress); }; await directoryCopier.Execute(); Assert.AreNotEqual(null, eventArgs); Assert.AreEqual(eventArgs.File1, "C:\\fakeDir\\file1.txt"); Assert.AreEqual(eventArgs.File2, "C:\\SFM\\file1.txt"); Assert.IsTrue(copiedFiles.Contains(new Tuple <string, string>("C:\\fakeDir\\file1.txt", "C:\\SFM\\file1.txt"))); Assert.IsTrue(progressHistory.Contains(100)); }
public void OnFileExistsTriggered(object sender, DirectoryCopierFileExistsEventArgs e) { e.FileCopyMode = OnFileExists(e.File1, e.File2); }