public void ShouldStartAndStopWatcherWhenSyncWhenWatchedAndStopped()
        {
            //Arrange
            var syncInfo = new SyncInfo { Source = @"C:\A", Target = @"C:\B" };
            var fileSystemSyncMock = new Mock<IFileSystemSync>();
            var fileSystemWatcherMock = new Mock<IFileSystemWatcher>();

            fileSystemWatcherMock.Setup(x => x.Start(syncInfo.Source));
            fileSystemWatcherMock.Setup(x => x.Stop());

            //Act
            var fileSystemSyncWhenWatched = new FileSystemSyncWhenWatched(fileSystemSyncMock.Object, fileSystemWatcherMock.Object) { Name = "TestWhenWatched", SyncInfo = syncInfo };
            fileSystemSyncWhenWatched.Start();
            fileSystemSyncWhenWatched.Stop();

            //Assert
            fileSystemWatcherMock.Verify(x => x.Start(syncInfo.Source));
            fileSystemWatcherMock.Verify(x => x.Stop());
        }
        private static void ShouldStartWatcherThrowExceptionSyncWhenSyncInfoIsNotCorrectly(SyncInfo syncInfo)
        {
            //Arrange
            var fileSystemSyncMock = new Mock<IFileSystemSync>();
            var fileSystemWatcherMock = new Mock<IFileSystemWatcher>();

            //Act
            var fileSystemSyncWhenWatched = new FileSystemSyncWhenWatched(fileSystemSyncMock.Object, fileSystemWatcherMock.Object)
            {
                Name = "TestWhenWatched",
                SyncInfo = syncInfo
            };
            fileSystemSyncWhenWatched.Start();
            //Assert
            Assert.Fail("The SyncInfoIsNotCorrectlySet exception should have been thrown");
        }
        public void ShouldSyncEventsRaisedWhenWatcherIsTriggeredByFileSystemRename(string source, string target, string triggeredName, string originalName)
        {
            //Arrange
            var isFsSyncChangeTriggeredOnStart = false;
            var isFsSyncCompletedTriggeredOnStart = false;
            var syncInfo = new SyncInfo { Source = source, Target = target };
            var triggerPath = $@"{syncInfo.Source}\{triggeredName}";
            var originalPath = $@"{syncInfo.Target}\{originalName}";
            var targetPath = $@"{syncInfo.Target}\{triggeredName}";

            var fileSystemSyncMock = new Mock<IFileSystemSync>();
            var fileSystemWatcherStub = new FileSystemWatcherStub();

            fileSystemSyncMock.Setup(x => x.Rename(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>()));

            //Act
            var fileSystemSyncWhenWatched = new FileSystemSyncWhenWatched(fileSystemSyncMock.Object, fileSystemWatcherStub) { Name = "TestWhenWatched", SyncInfo = syncInfo };
            fileSystemSyncWhenWatched.OnRunStart += name => { isFsSyncChangeTriggeredOnStart = true; };
            fileSystemSyncWhenWatched.OnRunComplete += name => { isFsSyncCompletedTriggeredOnStart = true; };

            fileSystemSyncWhenWatched.Start();
            fileSystemWatcherStub.TriggerRenameEvent(triggerPath, originalPath);
            fileSystemSyncWhenWatched.Stop();

            //Assert
            fileSystemSyncMock.Verify(x => x.Rename(triggerPath, originalPath, targetPath));
            Assert.IsTrue(isFsSyncChangeTriggeredOnStart);
            Assert.IsTrue(isFsSyncCompletedTriggeredOnStart);
        }