public void CopyTo() { using (var testDirectory = new Infrastructure.TestDirectory()) { var sourceFile = Path.Combine(testDirectory.FullPath, Guid.NewGuid().ToString()); var destinationFile = Path.Combine(testDirectory.FullPath, Guid.NewGuid().ToString()); var fileText = Guid.NewGuid().ToString(); File.WriteAllText(sourceFile, fileText); IItem destinationCopyFile = null; string destinationCopyPath = null; var file = new DirectorySync.Models.File(sourceFile); file.CopiedFromToEvent += (IItem destinationItem, string destinationPath) => { destinationCopyFile = destinationItem; destinationCopyPath = destinationPath; }; file.CopyTo(destinationFile).Wait(); Assert.True(File.Exists(sourceFile)); Assert.True(File.Exists(destinationFile)); Assert.Equal(fileText, File.ReadAllText(destinationFile)); Assert.NotNull(destinationCopyFile); Assert.Equal(destinationFile, destinationCopyFile.FullPath); Assert.Equal(destinationFile, destinationCopyPath); } }
public void CopyToWithError() { using (var testDirectory = new Infrastructure.TestDirectory()) { var sourceFile = Path.Combine(testDirectory.FullPath, Guid.NewGuid().ToString()); var destinationFile = Path.Combine(testDirectory.FullPath, Guid.NewGuid().ToString()); var fileText = Guid.NewGuid().ToString(); File.WriteAllText(sourceFile, fileText); var file = new DirectorySync.Models.File(sourceFile); string error = null; file.SyncErrorEvent += (string message) => { error = message; }; using (var stream = File.Create(destinationFile)) file.CopyTo(destinationFile).Wait(); Assert.NotNull(error); } }