public void TraceStatus() { string dataLocation = Path.Combine("mock:", "registryDataFolder"); MockFileSystem fileSystem = new MockFileSystem(new MockDirectory(dataLocation, null, null)); MockTracer tracer = new MockTracer(); RepoRegistry registry = new RepoRegistry(tracer, fileSystem, dataLocation, this.mockRepoMounter.Object); string repo1Root = Path.Combine("mock:", "test", "repo1"); string owner1SID = Guid.NewGuid().ToString(); string repo2Root = Path.Combine("mock:", "test", "repo2"); string owner2SID = Guid.NewGuid().ToString(); string repo3Root = Path.Combine("mock:", "test", "repo3"); string owner3SID = Guid.NewGuid().ToString(); string errorMessage; registry.TryRegisterRepo(repo1Root, owner1SID, out errorMessage).ShouldEqual(true); registry.TryRegisterRepo(repo2Root, owner2SID, out errorMessage).ShouldEqual(true); registry.TryRegisterRepo(repo3Root, owner3SID, out errorMessage).ShouldEqual(true); registry.TryDeactivateRepo(repo2Root, out errorMessage).ShouldEqual(true); registry.TraceStatus(); Dictionary <string, RepoRegistration> repos = registry.ReadRegistry(); repos.Count.ShouldEqual(3); foreach (KeyValuePair <string, RepoRegistration> kvp in repos) { tracer.RelatedInfoEvents.SingleOrDefault(message => message.Equals(kvp.Value.ToString())).ShouldNotBeNull(); } }
public void ReadRegistry_Upgrade_ExistingVersion1() { string dataLocation = Path.Combine("mock:", "registryDataFolder"); MockFileSystem fileSystem = new MockFileSystem(new MockDirectory(dataLocation, null, null)); string repo1 = Path.Combine("mock:", "code", "repo1"); string repo2 = Path.Combine("mock:", "code", "repo2"); // Create a version 1 registry file fileSystem.WriteAllText( Path.Combine(dataLocation, RepoRegistry.RegistryName), $@"1 {{""EnlistmentRoot"":""{repo1.Replace("\\", "\\\\")}"",""IsActive"":false}} {{""EnlistmentRoot"":""{repo2.Replace("\\", "\\\\")}"",""IsActive"":true}} "); RepoRegistry registry = new RepoRegistry( new MockTracer(), fileSystem, dataLocation, this.mockRepoMounter.Object, this.mockNotificationHandler.Object); registry.Upgrade(); Dictionary <string, RepoRegistration> repos = registry.ReadRegistry(); repos.Count.ShouldEqual(2); this.VerifyRepo(repos[repo1], expectedOwnerSID: null, expectedIsActive: false); this.VerifyRepo(repos[repo2], expectedOwnerSID: null, expectedIsActive: true); }
public void ReadRegistry_Upgrade_NoRegistry() { string dataLocation = Path.Combine("mock:", "registryDataFolder"); MockFileSystem fileSystem = new MockFileSystem(new MockDirectory(dataLocation, null, null)); RepoRegistry registry = new RepoRegistry(new MockTracer(), fileSystem, dataLocation, this.mockRepoMounter.Object); registry.Upgrade(); Dictionary <string, RepoRegistration> repos = registry.ReadRegistry(); repos.Count.ShouldEqual(0); }
public void ReadRegistry_Upgrade_NoRegistry() { string dataLocation = @"mock:\registryDataFolder"; MockFileSystem fileSystem = new MockFileSystem(new MockDirectory(dataLocation, null, null)); RepoRegistry registry = new RepoRegistry(new MockTracer(), fileSystem, dataLocation); registry.Upgrade(); Dictionary <string, RepoRegistration> repos = registry.ReadRegistry(); repos.Count.ShouldEqual(0); }
public void ReadRegistry_Upgrade_NoRegistry() { string dataLocation = Path.Combine(GetTestWorkingDir(), Guid.NewGuid().ToString()); Directory.CreateDirectory(dataLocation); RepoRegistry registry = new RepoRegistry(new MockTracer(), dataLocation); registry.Upgrade(); var repos = registry.ReadRegistry(); repos.Count.ShouldEqual(0); }
public void TryDeactivateRepo() { string dataLocation = Path.Combine("mock:", "registryDataFolder"); MockFileSystem fileSystem = new MockFileSystem(new MockDirectory(dataLocation, null, null)); RepoRegistry registry = new RepoRegistry( new MockTracer(), fileSystem, dataLocation, this.mockRepoMounter.Object, this.mockNotificationHandler.Object); string repo1Root = Path.Combine("mock:", "test", "repo1"); string owner1SID = Guid.NewGuid().ToString(); string errorMessage; registry.TryRegisterRepo(repo1Root, owner1SID, out errorMessage).ShouldEqual(true); List <RepoRegistration> activeRepos; registry.TryGetActiveRepos(out activeRepos, out errorMessage); activeRepos.Count.ShouldEqual(1); this.VerifyRepo(activeRepos.SingleOrDefault(repo => repo.EnlistmentRoot.Equals(repo1Root)), owner1SID, expectedIsActive: true); // Deactivate repo registry.TryDeactivateRepo(repo1Root, out errorMessage).ShouldEqual(true); registry.TryGetActiveRepos(out activeRepos, out errorMessage); activeRepos.Count.ShouldEqual(0); // Deactivate repo again (no-op) registry.TryDeactivateRepo(repo1Root, out errorMessage).ShouldEqual(true); registry.TryGetActiveRepos(out activeRepos, out errorMessage); activeRepos.Count.ShouldEqual(0); // Repo should still be in the registry Dictionary <string, RepoRegistration> verifiableRegistry = registry.ReadRegistry(); verifiableRegistry.Count.ShouldEqual(1); this.VerifyRepo(verifiableRegistry[repo1Root], owner1SID, expectedIsActive: false); // Deactivate non-existent repo should fail string nonExistantPath = Path.Combine("mock:", "test", "doesNotExist"); registry.TryDeactivateRepo(nonExistantPath, out errorMessage).ShouldEqual(false); errorMessage.ShouldContain("Attempted to deactivate non-existent repo"); }
public void TryRegisterRepo_EmptyRegistry() { string dataLocation = @"mock:\registryDataFolder"; MockFileSystem fileSystem = new MockFileSystem(new MockDirectory(dataLocation, null, null)); RepoRegistry registry = new RepoRegistry(new MockTracer(), fileSystem, dataLocation); string repoRoot = @"c:\test"; string ownerSID = Guid.NewGuid().ToString(); string errorMessage; registry.TryRegisterRepo(repoRoot, ownerSID, out errorMessage).ShouldEqual(true); Dictionary <string, RepoRegistration> verifiableRegistry = registry.ReadRegistry(); verifiableRegistry.Count.ShouldEqual(1); this.VerifyRepo(verifiableRegistry[repoRoot], ownerSID, expectedIsActive: true); }
public void TryRegisterRepo_EmptyRegistry() { string dataLocation = Path.Combine(GetTestWorkingDir(), Guid.NewGuid().ToString()); Directory.CreateDirectory(dataLocation); RepoRegistry registry = new RepoRegistry(new MockTracer(), dataLocation); string repoRoot = "c:\test"; string ownerSID = Guid.NewGuid().ToString(); string errorMessage; registry.TryRegisterRepo(repoRoot, ownerSID, out errorMessage).ShouldEqual(true); var verifiableRegistry = registry.ReadRegistry(); verifiableRegistry.Count.ShouldEqual(1); this.VerifyRepo(verifiableRegistry[repoRoot], ownerSID, expectedIsActive: true); }
public void ReadRegistry_Upgrade_ExistingVersion1() { /* * {"EnlistmentRoot":"c:\\code\\repo1","IsActive":false} * {"EnlistmentRoot":"c:\\code\\repo2","IsActive":true} */ string dataLocation = Path.Combine(GetTestWorkingDir(), Guid.NewGuid().ToString()); Directory.CreateDirectory(dataLocation); File.Copy(GetDataPath("Version1Registry"), Path.Combine(dataLocation, RepoRegistry.RegistryName)); RepoRegistry registry = new RepoRegistry(new MockTracer(), dataLocation); registry.Upgrade(); var repos = registry.ReadRegistry(); repos.Count.ShouldEqual(2); this.VerifyRepo(repos["c:\\code\\repo1"], expectedOwnerSID: null, expectedIsActive: false); this.VerifyRepo(repos["c:\\code\\repo2"], expectedOwnerSID: null, expectedIsActive: true); }
public void TryRegisterRepo_EmptyRegistry() { string dataLocation = Path.Combine("mock:", "registryDataFolder"); MockFileSystem fileSystem = new MockFileSystem(new MockDirectory(dataLocation, null, null)); RepoRegistry registry = new RepoRegistry( new MockTracer(), fileSystem, dataLocation, this.mockRepoMounter.Object, this.mockNotificationHandler.Object); string repoRoot = Path.Combine("c:", "test"); string ownerSID = Guid.NewGuid().ToString(); string errorMessage; registry.TryRegisterRepo(repoRoot, ownerSID, out errorMessage).ShouldEqual(true); Dictionary <string, RepoRegistration> verifiableRegistry = registry.ReadRegistry(); verifiableRegistry.Count.ShouldEqual(1); this.VerifyRepo(verifiableRegistry[repoRoot], ownerSID, expectedIsActive: true); }
public void ReadRegistry_Upgrade_ExistingVersion1() { string dataLocation = @"mock:\registryDataFolder"; MockFileSystem fileSystem = new MockFileSystem(new MockDirectory(dataLocation, null, null)); // Create a version 1 registry file fileSystem.WriteAllText( Path.Combine(dataLocation, RepoRegistry.RegistryName), @"1 {""EnlistmentRoot"":""c:\\code\\repo1"",""IsActive"":false} {""EnlistmentRoot"":""c:\\code\\repo2"",""IsActive"":true} "); RepoRegistry registry = new RepoRegistry(new MockTracer(), fileSystem, dataLocation); registry.Upgrade(); Dictionary <string, RepoRegistration> repos = registry.ReadRegistry(); repos.Count.ShouldEqual(2); this.VerifyRepo(repos["c:\\code\\repo1"], expectedOwnerSID: null, expectedIsActive: false); this.VerifyRepo(repos["c:\\code\\repo2"], expectedOwnerSID: null, expectedIsActive: true); }