Esempio n. 1
0
        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);
        }
Esempio n. 3
0
 public UnregisterRepoHandler(ITracer tracer, RepoRegistry registry, NamedPipeServer.Connection connection, NamedPipeMessages.UnregisterRepoRequest request)
 {
     this.tracer     = tracer;
     this.registry   = registry;
     this.connection = connection;
     this.request    = request;
 }
 public GetActiveRepoListHandler(
     ITracer tracer,
     RepoRegistry registry,
     NamedPipeServer.Connection connection,
     NamedPipeMessages.GetActiveRepoListRequest request)
 {
     this.tracer     = tracer;
     this.registry   = registry;
     this.connection = connection;
     this.request    = request;
 }
Esempio n. 5
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);
        }
Esempio n. 6
0
        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 TryGetActiveRepos_BeforeAndAfterActivateAndDeactivate()
        {
            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 repo2Root = Path.Combine("mock:", "test", "repo2");
            string owner2SID = Guid.NewGuid().ToString();
            string repo3Root = Path.Combine("mock:", "test", "repo3");
            string owner3SID = Guid.NewGuid().ToString();

            // Register all 3 repos
            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);

            // Confirm all 3 active
            List <RepoRegistration> activeRepos;

            registry.TryGetActiveRepos(out activeRepos, out errorMessage);
            activeRepos.Count.ShouldEqual(3);
            this.VerifyRepo(activeRepos.SingleOrDefault(repo => repo.EnlistmentRoot.Equals(repo1Root)), owner1SID, expectedIsActive: true);
            this.VerifyRepo(activeRepos.SingleOrDefault(repo => repo.EnlistmentRoot.Equals(repo2Root)), owner2SID, expectedIsActive: true);
            this.VerifyRepo(activeRepos.SingleOrDefault(repo => repo.EnlistmentRoot.Equals(repo3Root)), owner3SID, expectedIsActive: true);

            // Deactive repo 2
            registry.TryDeactivateRepo(repo2Root, out errorMessage).ShouldEqual(true);

            // Confirm repos 1 and 3 still active
            registry.TryGetActiveRepos(out activeRepos, out errorMessage);
            activeRepos.Count.ShouldEqual(2);
            this.VerifyRepo(activeRepos.SingleOrDefault(repo => repo.EnlistmentRoot.Equals(repo1Root)), owner1SID, expectedIsActive: true);
            this.VerifyRepo(activeRepos.SingleOrDefault(repo => repo.EnlistmentRoot.Equals(repo3Root)), owner3SID, expectedIsActive: true);

            // Activate repo 2
            registry.TryRegisterRepo(repo2Root, owner2SID, out errorMessage).ShouldEqual(true);

            // Confirm all 3 active
            registry.TryGetActiveRepos(out activeRepos, out errorMessage);
            activeRepos.Count.ShouldEqual(3);
            this.VerifyRepo(activeRepos.SingleOrDefault(repo => repo.EnlistmentRoot.Equals(repo1Root)), owner1SID, expectedIsActive: true);
            this.VerifyRepo(activeRepos.SingleOrDefault(repo => repo.EnlistmentRoot.Equals(repo2Root)), owner2SID, expectedIsActive: true);
            this.VerifyRepo(activeRepos.SingleOrDefault(repo => repo.EnlistmentRoot.Equals(repo3Root)), owner3SID, expectedIsActive: true);
        }
Esempio n. 8
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");
        }
Esempio n. 10
0
        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 RepoRegistryMountsOnlyRegisteredRepos()
        {
            Mock <IRepoMounter> repoMounterMock = new Mock <IRepoMounter>(MockBehavior.Strict);

            repoMounterMock.Setup(mp => mp.MountRepository(ExpectedActiveRepoPath, ExpectedActiveUserId)).Returns(true);

            this.CreateTestRepos(ServiceDataLocation);

            RepoRegistry repoRegistry = new RepoRegistry(
                this.tracer,
                this.fileSystem,
                ServiceDataLocation,
                repoMounterMock.Object);

            repoRegistry.AutoMountRepos(ExpectedActiveUserId.ToString(), ExpectedSessionId);

            repoMounterMock.VerifyAll();
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
        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);
        }
Esempio n. 14
0
        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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
 public WindowsRequestHandler(
     ITracer tracer,
     string etwArea,
     RepoRegistry repoRegistry) : base(tracer, etwArea, repoRegistry)
 {
 }
Esempio n. 17
0
 public RequestHandler(ITracer tracer, string etwArea, RepoRegistry repoRegistry)
 {
     this.tracer       = tracer;
     this.etwArea      = etwArea;
     this.repoRegistry = repoRegistry;
 }