public async Task ShouldDetectBranchChange() { Logger.Trace("Starting ShouldDetectBranchChange"); try { InitializePlatformAndEnvironment(TestRepoMasterCleanSynchronized); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanSynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent); repositoryWatcher.Initialize(); repositoryWatcher.Start(); repositoryWatcher.Stop(); try { Logger.Trace("Issuing Command"); await GitClient.SwitchBranch("feature/document").StartAsAsync(); await TaskManager.Wait(); Logger.Trace("Completed Command"); repositoryWatcher.Start(); watcherAutoResetEvent.HeadChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.IndexChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RepositoryChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); Logger.Trace("Continue test"); repositoryWatcherListener.Received(1).HeadChanged(); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.Received(1).IndexChanged(); repositoryWatcherListener.Received(1).RepositoryChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchesChanged(); repositoryWatcherListener.DidNotReceive().RemoteBranchesChanged(); } finally { repositoryWatcher.Stop(); } } } finally { Logger.Trace("Ending ShouldDetectBranchChange"); } }
public async Task ShouldDetectGitFetch() { Logger.Trace("Starting ShouldDetectGitFetch"); try { InitializePlatformAndEnvironment(TestRepoMasterCleanUnsynchronized); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanUnsynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent, true); repositoryWatcher.Initialize(); repositoryWatcher.Start(); try { Logger.Trace("Issuing Command"); await GitClient.Fetch("origin").StartAsAsync(); await TaskManager.Wait(); Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchesChanged(); repositoryWatcherListener.DidNotReceive().RemoteBranchesChanged(); } finally { repositoryWatcher.Stop(); } } } finally { Logger.Trace("Ending ShouldDetectGitFetch"); } }
public async Task ShouldDetectGitFetch() { await Initialize(TestRepoMasterCleanUnsynchronized); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanUnsynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent, true); repositoryWatcher.Initialize(); repositoryWatcher.Start(); try { Logger.Trace("Issuing Command"); await GitClient.Fetch("origin").StartAsAsync(); await TaskManager.Wait(); watcherAutoResetEvent.RemoteBranchCreated.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RemoteBranchCreated.WaitOne(TimeSpan.FromSeconds(2)); Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchChanged(Args.String); repositoryWatcherListener.DidNotReceive().RemoteBranchChanged(Args.String, Args.String); repositoryWatcherListener.Received(1).RemoteBranchCreated("origin", "feature/new-feature"); repositoryWatcherListener.Received(1).RemoteBranchCreated("origin", "feature/other-feature"); repositoryWatcherListener.DidNotReceive().RemoteBranchDeleted(Args.String, Args.String); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); } finally { repositoryWatcher.Stop(); } } }
public async Task ShouldDetectFileChanges() { await Initialize(TestRepoMasterCleanSynchronized); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanSynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent); repositoryWatcher.Initialize(); repositoryWatcher.Start(); try { var foobarTxt = TestRepoMasterCleanSynchronized.Combine("foobar.txt"); Logger.Trace("Issuing Changes"); foobarTxt.WriteAllText("foobar"); await TaskManager.Wait(); watcherAutoResetEvent.IndexChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RepositoryChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); Logger.Trace("Continue test"); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.Received().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchChanged(Args.String); repositoryWatcherListener.DidNotReceive().RemoteBranchChanged(Args.String, Args.String); repositoryWatcherListener.DidNotReceive().RemoteBranchCreated(Args.String, Args.String); repositoryWatcherListener.DidNotReceive().RemoteBranchDeleted(Args.String, Args.String); repositoryWatcherListener.Received().RepositoryChanged(); } finally { repositoryWatcher.Stop(); } } }
public static void AttachListener(this IRepositoryWatcherListener listener, IRepositoryWatcher repositoryWatcher, RepositoryWatcherAutoResetEvent autoResetEvent = null, bool trace = false) { var logger = trace ? Logging.GetLogger <IRepositoryWatcherListener>() : null; repositoryWatcher.HeadChanged += () => { logger?.Trace("HeadChanged"); listener.HeadChanged(); autoResetEvent?.HeadChanged.Set(); }; repositoryWatcher.ConfigChanged += () => { logger?.Trace("ConfigChanged"); listener.ConfigChanged(); autoResetEvent?.ConfigChanged.Set(); }; repositoryWatcher.IndexChanged += () => { logger?.Trace("IndexChanged"); listener.IndexChanged(); autoResetEvent?.IndexChanged.Set(); }; repositoryWatcher.LocalBranchChanged += s => { logger?.Trace("LocalBranchChanged: {0}", s); listener.LocalBranchChanged(s); autoResetEvent?.LocalBranchChanged.Set(); }; repositoryWatcher.LocalBranchCreated += s => { logger?.Trace("LocalBranchCreated: {0}", s); listener.LocalBranchCreated(s); autoResetEvent?.LocalBranchCreated.Set(); }; repositoryWatcher.LocalBranchDeleted += s => { logger?.Trace("LocalBranchDeleted: {0}", s); listener.LocalBranchDeleted(s); autoResetEvent?.LocalBranchDeleted.Set(); }; repositoryWatcher.RemoteBranchCreated += (s, s1) => { logger?.Trace("RemoteBranchCreated: {0} {1}", s, s1); listener.RemoteBranchCreated(s, s1); autoResetEvent?.RemoteBranchCreated.Set(); }; repositoryWatcher.RemoteBranchDeleted += (s, s1) => { logger?.Trace("RemoteBranchDeleted: {0} {1}", s, s1); listener.RemoteBranchDeleted(s, s1); autoResetEvent?.RemoteBranchDeleted.Set(); }; repositoryWatcher.RepositoryChanged += () => { logger?.Trace("RepositoryChanged"); listener.RepositoryChanged(); autoResetEvent?.RepositoryChanged.Set(); }; }
public async Task ShouldDetectChangesToRemotes() { await Initialize(TestRepoMasterCleanSynchronized); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanSynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent); repositoryWatcher.Initialize(); repositoryWatcher.Start(); try { Logger.Trace("Issuing Command"); await GitClient.RemoteRemove("origin").StartAsAsync(); await TaskManager.Wait(); watcherAutoResetEvent.ConfigChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RemoteBranchDeleted.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RemoteBranchDeleted.WaitOne(TimeSpan.FromSeconds(2)); watcherAutoResetEvent.RemoteBranchDeleted.WaitOne(TimeSpan.FromSeconds(2)); Logger.Trace("Continue test"); repositoryWatcherListener.Received().ConfigChanged(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchChanged(Args.String); repositoryWatcherListener.Received(1).RemoteBranchDeleted("origin", "feature/document-2"); repositoryWatcherListener.Received(1).RemoteBranchDeleted("origin", "feature/other-feature"); repositoryWatcherListener.Received(1).RemoteBranchDeleted("origin", "master"); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.ClearReceivedCalls(); watcherAutoResetEvent.ConfigChanged.Reset(); Logger.Trace("Issuing 2nd Command"); await GitClient.RemoteAdd("origin", "https://github.com/EvilStanleyGoldman/IOTestsRepo.git").StartAsAsync(); // give the fs watcher a bit of time to catch up await TaskEx.Delay(500); await TaskManager.Wait(); watcherAutoResetEvent.ConfigChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); Logger.Trace("Continue 2nd test"); repositoryWatcherListener.Received().ConfigChanged(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchCreated(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchDeleted(Args.String); repositoryWatcherListener.DidNotReceive().LocalBranchChanged(Args.String); repositoryWatcherListener.DidNotReceive().RemoteBranchChanged(Args.String, Args.String); repositoryWatcherListener.DidNotReceive().RemoteBranchCreated(Args.String, Args.String); repositoryWatcherListener.DidNotReceive().RemoteBranchDeleted(Args.String, Args.String); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); } finally { repositoryWatcher.Stop(); } } }
public static void AttachListener(this IRepositoryWatcherListener listener, IRepositoryWatcher repositoryWatcher, RepositoryWatcherAutoResetEvent autoResetEvent = null, bool trace = false) { var logger = trace ? LogHelper.GetLogger <IRepositoryWatcherListener>() : null; repositoryWatcher.HeadChanged += () => { logger?.Trace("HeadChanged"); listener.HeadChanged(); autoResetEvent?.HeadChanged.Set(); }; repositoryWatcher.IndexChanged += () => { logger?.Trace("IndexChanged"); listener.IndexChanged(); autoResetEvent?.IndexChanged.Set(); }; repositoryWatcher.ConfigChanged += () => { logger?.Trace("ConfigChanged"); listener.ConfigChanged(); autoResetEvent?.ConfigChanged.Set(); }; repositoryWatcher.RepositoryCommitted += () => { logger?.Trace("ConfigChanged"); listener.RepositoryCommitted(); autoResetEvent?.RepositoryCommitted.Set(); }; repositoryWatcher.RepositoryChanged += () => { logger?.Trace("RepositoryChanged"); listener.RepositoryChanged(); autoResetEvent?.RepositoryChanged.Set(); }; repositoryWatcher.LocalBranchesChanged += () => { logger?.Trace("LocalBranchesChanged"); listener.LocalBranchesChanged(); autoResetEvent?.LocalBranchesChanged.Set(); }; repositoryWatcher.RemoteBranchesChanged += () => { logger?.Trace("RemoteBranchesChanged"); listener.RemoteBranchesChanged(); autoResetEvent?.RemoteBranchesChanged.Set(); }; }
public async Task ShouldDetectChangesToRemotes() { Logger.Trace("Starting ShouldDetectChangesToRemotes"); try { InitializePlatformAndEnvironment(TestRepoMasterCleanSynchronized); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanSynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent); repositoryWatcher.Initialize(); repositoryWatcher.Start(); repositoryWatcher.Stop(); try { Logger.Trace("Issuing Command"); await GitClient.RemoteRemove("origin").StartAsAsync(); await TaskManager.Wait(); Logger.Trace("Continue test"); repositoryWatcher.Start(); watcherAutoResetEvent.ConfigChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RemoteBranchesChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.Reset(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.Received(1).ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchesChanged(); repositoryWatcherListener.Received(1).RemoteBranchesChanged(); repositoryWatcherListener.ClearReceivedCalls(); repositoryWatcher.Stop(); Logger.Trace("Issuing 2nd Command"); await GitClient.RemoteAdd("origin", "https://github.com/EvilStanleyGoldman/IOTestsRepo.git").StartAsAsync(); await TaskManager.Wait(); Logger.Trace("Continue 2nd test"); repositoryWatcher.Start(); watcherAutoResetEvent.ConfigChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.RemoteBranchesChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.Received(1).ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchesChanged(); repositoryWatcherListener.Received(1).RemoteBranchesChanged(); } finally { repositoryWatcher.Stop(); } } } finally { Logger.Trace("Ending ShouldDetectChangesToRemotes"); } }
public async Task ShouldDetectFileChangesAndCommit() { Logger.Trace("Starting ShouldDetectFileChangesAndCommit"); try { InitializePlatformAndEnvironment(TestRepoMasterCleanSynchronized); using (var repositoryWatcher = CreateRepositoryWatcher(TestRepoMasterCleanSynchronized)) { var watcherAutoResetEvent = new RepositoryWatcherAutoResetEvent(); var repositoryWatcherListener = Substitute.For <IRepositoryWatcherListener>(); repositoryWatcherListener.AttachListener(repositoryWatcher, watcherAutoResetEvent); repositoryWatcher.Initialize(); repositoryWatcher.Start(); repositoryWatcher.Stop(); try { var foobarTxt = TestRepoMasterCleanSynchronized.Combine("foobar.txt"); Logger.Trace("Issuing Changes"); foobarTxt.WriteAllText("foobar"); await TaskManager.Wait(); Logger.Trace("Continue test"); repositoryWatcher.Start(); watcherAutoResetEvent.RepositoryChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.Reset(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.DidNotReceive().IndexChanged(); repositoryWatcherListener.Received().RepositoryChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchesChanged(); repositoryWatcherListener.DidNotReceive().RemoteBranchesChanged(); repositoryWatcherListener.ClearReceivedCalls(); repositoryWatcher.Stop(); Logger.Trace("Issuing Command"); await GitClient.AddAll().StartAsAsync(); Logger.Trace("Completed Command"); repositoryWatcher.Start(); watcherAutoResetEvent.IndexChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.Reset(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.DidNotReceive().RepositoryCommitted(); repositoryWatcherListener.Received(1).IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.DidNotReceive().LocalBranchesChanged(); repositoryWatcherListener.DidNotReceive().RemoteBranchesChanged(); repositoryWatcherListener.ClearReceivedCalls(); repositoryWatcher.Stop(); Logger.Trace("Issuing Command"); await GitClient.Commit("Test Commit", string.Empty).StartAsAsync(); Logger.Trace("Completed Command"); repositoryWatcher.Start(); watcherAutoResetEvent.RepositoryCommitted.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.IndexChanged.WaitOne(TimeSpan.FromSeconds(2)).Should().BeTrue(); watcherAutoResetEvent.Reset(); repositoryWatcherListener.DidNotReceive().HeadChanged(); repositoryWatcherListener.DidNotReceive().ConfigChanged(); repositoryWatcherListener.Received(1).RepositoryCommitted(); repositoryWatcherListener.Received(1).IndexChanged(); repositoryWatcherListener.DidNotReceive().RepositoryChanged(); repositoryWatcherListener.Received(1).LocalBranchesChanged(); repositoryWatcherListener.DidNotReceive().RemoteBranchesChanged(); repositoryWatcherListener.ClearReceivedCalls(); } finally { repositoryWatcher.Stop(); } } } finally { Logger.Trace("Ending ShouldDetectFileChangesAndCommit"); } }