public void MaintenanceTask_Execute_SkipsReposThatDoNotMatchRegisteredUser() { MaintenanceTasks.Task task = MaintenanceTasks.Task.PackFiles; UserAndSession testUser = new UserAndSession("testUserId", sessionId: 1); this.mockRegisteredUserStore.SetupGet(mrus => mrus.RegisteredUser).Returns(testUser); this.mockRepoRegistry.Setup(reg => reg.GetRegisteredRepos()).Returns( new List <ScalarRepoRegistration> { new ScalarRepoRegistration(Path.Combine(MockFileSystem.GetMockRoot(), "Repos", "repoRoot"), "nonMatchingUser"), new ScalarRepoRegistration(Path.Combine(MockFileSystem.GetMockRoot(), "Repos", "repoRoot2"), "nonMatchingUser2") }); MaintenanceTaskScheduler.MaintenanceTask maintenanceTask = new MaintenanceTaskScheduler.MaintenanceTask( this.mockTracer, this.mockFileSystem.Object, this.mockVerbRunner.Object, this.mockRepoRegistry.Object, this.mockRegisteredUserStore.Object, task); maintenanceTask.Execute(); this.mockTracer.RelatedEvents.ShouldContain(entry => entry.Contains("\"reposInRegistryForUser\":0")); }
public void MaintenanceTask_Execute_SkipsRegisteredRepoIfVolumeDoesNotExist() { MaintenanceTasks.Task task = MaintenanceTasks.Task.PackFiles; UserAndSession testUser = new UserAndSession("testUserId", sessionId: 1); this.mockRegisteredUserStore.SetupGet(mrus => mrus.RegisteredUser).Returns(testUser); string repoPath = Path.Combine(MockFileSystem.GetMockRoot(), "Repos", "repoRoot"); this.mockRepoRegistry.Setup(reg => reg.GetRegisteredRepos()).Returns( new List <ScalarRepoRegistration> { new ScalarRepoRegistration(repoPath, testUser.UserId) }); this.mockFileSystem.Setup(fs => fs.DirectoryExists(Path.GetPathRoot(repoPath))).Returns(false); MaintenanceTaskScheduler.MaintenanceTask maintenanceTask = new MaintenanceTaskScheduler.MaintenanceTask( this.mockTracer, this.mockFileSystem.Object, this.mockVerbRunner.Object, this.mockRepoRegistry.Object, this.mockRegisteredUserStore.Object, task); maintenanceTask.Execute(); this.mockTracer.RelatedEvents.ShouldContain(entry => entry.Contains("SkippedRepoWithMissingVolume")); }
public void MaintenanceTask_Execute_NoRegisteredUser() { MaintenanceTasks.Task task = MaintenanceTasks.Task.PackFiles; this.mockRegisteredUserStore.SetupGet(mrus => mrus.RegisteredUser).Returns((UserAndSession)null); MaintenanceTaskScheduler.MaintenanceTask maintenanceTask = new MaintenanceTaskScheduler.MaintenanceTask( this.mockTracer, this.mockFileSystem.Object, this.mockVerbRunner.Object, this.mockRepoRegistry.Object, this.mockRegisteredUserStore.Object, task); maintenanceTask.Execute(); this.mockTracer.RelatedInfoEvents.ShouldContain(entry => entry.Contains($"Skipping '{task}', no registered user")); }
public void MaintenanceTask_Execute_CallsRunVerbOnlyForRegisteredRepos() { MaintenanceTasks.Task task = MaintenanceTasks.Task.PackFiles; UserAndSession testUser = new UserAndSession("testUserId", sessionId: 1); UserAndSession secondUser = new UserAndSession("testUserId2", sessionId: 1); string repoPath1 = Path.Combine(MockFileSystem.GetMockRoot(), "Repos", "repoRoot"); string repoPath2 = Path.Combine(MockFileSystem.GetMockRoot(), "Repos", "repoRoot2"); string secondUsersRepoPath = Path.Combine(MockFileSystem.GetMockRoot(), "Repos", "secondUsersRepo"); this.mockRegisteredUserStore.SetupGet(mrus => mrus.RegisteredUser).Returns(testUser); this.mockRepoRegistry.Setup(reg => reg.GetRegisteredRepos()).Returns( new List <ScalarRepoRegistration> { new ScalarRepoRegistration(repoPath1, testUser.UserId), new ScalarRepoRegistration(secondUsersRepoPath, secondUser.UserId), new ScalarRepoRegistration(repoPath2, testUser.UserId) }); // The root volume and repos exist this.mockFileSystem.Setup(fs => fs.DirectoryExists(Path.GetPathRoot(repoPath1))).Returns(true); this.mockFileSystem.Setup(fs => fs.DirectoryExists(repoPath1)).Returns(true); this.mockFileSystem.Setup(fs => fs.DirectoryExists(repoPath2)).Returns(true); this.mockVerbRunner.Setup(vr => vr.CallMaintenance(task, repoPath1, testUser.SessionId)).Returns(true); this.mockVerbRunner.Setup(vr => vr.CallMaintenance(task, repoPath2, testUser.SessionId)).Returns(true); MaintenanceTaskScheduler.MaintenanceTask maintenanceTask = new MaintenanceTaskScheduler.MaintenanceTask( this.mockTracer, this.mockFileSystem.Object, this.mockVerbRunner.Object, this.mockRepoRegistry.Object, this.mockRegisteredUserStore.Object, task); maintenanceTask.Execute(); }
public void MaintenanceTask_Execute_UnregistersRepoIfMissing() { MaintenanceTasks.Task task = MaintenanceTasks.Task.PackFiles; UserAndSession testUser = new UserAndSession("testUserId", sessionId: 1); this.mockRegisteredUserStore.SetupGet(mrus => mrus.RegisteredUser).Returns(testUser); string repoPath = Path.Combine(MockFileSystem.GetMockRoot(), "Repos", "repoRoot"); this.mockRepoRegistry.Setup(reg => reg.GetRegisteredRepos()).Returns( new List <ScalarRepoRegistration> { new ScalarRepoRegistration(repoPath, testUser.UserId) }); // Validate that TryUnregisterRepo will be called for repoPath string emptyString = string.Empty; this.mockRepoRegistry.Setup(reg => reg.TryUnregisterRepo(repoPath, out emptyString)).Returns(true); // The root volume should exist this.mockFileSystem.Setup(fs => fs.DirectoryExists(Path.GetPathRoot(repoPath))).Returns(true); // The repo itself does not exist this.mockFileSystem.Setup(fs => fs.DirectoryExists(repoPath)).Returns(false); MaintenanceTaskScheduler.MaintenanceTask maintenanceTask = new MaintenanceTaskScheduler.MaintenanceTask( this.mockTracer, this.mockFileSystem.Object, this.mockVerbRunner.Object, this.mockRepoRegistry.Object, this.mockRegisteredUserStore.Object, task); maintenanceTask.Execute(); this.mockTracer.RelatedEvents.ShouldContain(entry => entry.Contains("RemovedMissingRepo")); }