예제 #1
0
        public ContinuousJobRunnerFacts()
        {
            FileSystemHelpers.Instance = new FileSystem();

            _job = new ContinuousJob
            {
                Name = "testjob",
                JobBinariesRootPath = @"c:\test\data\continuous\testjob"
            };
            _environment = new TestEnvironment
            {
                TempPath = @"c:\temp",
                JobsBinariesPath = @"c:\test\data\continuous\testjob",
                JobsDataPath = Path.GetTempPath(),
                DataPath = @"c:\test\data"
            };

            string jobDirectory = Path.Combine(_environment.JobsDataPath, "continuous", _job.Name);
            _logFilePath = Path.Combine(jobDirectory, "job_log.txt");

            MockDeploymentSettingsManager mockSettingsManager = new MockDeploymentSettingsManager();
            Mock<ITraceFactory> mockTraceFactory = new Mock<ITraceFactory>(MockBehavior.Strict);
            Mock<IAnalytics> mockAnalytics = new Mock<IAnalytics>(MockBehavior.Strict);

            Mock<ITracer> mockTracer = new Mock<ITracer>(MockBehavior.Strict);
            mockTracer.Setup(p => p.Trace(It.IsAny<string>(), It.IsAny<IDictionary<string, string>>()));
            mockTraceFactory.Setup(p => p.GetTracer()).Returns(mockTracer.Object);

            _runner = new ContinuousJobRunner(_job, _environment, mockSettingsManager, mockTraceFactory.Object, mockAnalytics.Object);

            FileSystemHelpers.DeleteFileSafe(_logFilePath);
        }
예제 #2
0
        public void GitClearLockRemovesHeadAndIndexLocks()
        {
            using (var testRepo = GetRepository())
            {
                // Arrange
                Git.Init(testRepo.PhysicalPath);
                string fileToWrite = Path.Combine(testRepo.PhysicalPath, "some file.txt");
                File.WriteAllText(Path.Combine(testRepo.PhysicalPath, ".git", "index.lock"), "");
                File.WriteAllText(Path.Combine(testRepo.PhysicalPath, ".git", "HEAD.lock"), "");
                File.WriteAllText(fileToWrite, "Hello world");
                var env = new TestEnvironment
                {
                    RepositoryPath = testRepo.PhysicalPath
                };
                var gitRepo = new GitExeRepository(env, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);


                // Assert - 1
                var ex = Assert.Throws<CommandLineException>(() => Git.Add(testRepo.PhysicalPath, fileToWrite));
                Assert.Contains(".git/index.lock': File exists.", ex.Message);
                
                // Act - 2
                gitRepo.ClearLock();
                Git.Add(testRepo.PhysicalPath, fileToWrite);
            }

        }
예제 #3
0
        public void GitRepoDoesntExistIfGitRepoOnlyOnParentDirectory()
        {
            using (TestRepository testRepository = GetRepository())
            {
                // Create a repository
                var gitRepo = new GitExeRepository(testRepository.Environment, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);
                gitRepo.Initialize();

                // Checkout for existence in subdirectory
                var testedPath = Path.Combine(testRepository.PhysicalPath, "subdirectory");
                Directory.CreateDirectory(testedPath);
                var environment = new TestEnvironment { RepositoryPath = testedPath };
                gitRepo = new GitExeRepository(environment, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);
                Assert.False(gitRepo.Exists, "git repository shouldn't exist yet");
            }
        }
예제 #4
0
        public void GitClearLockRemovesHeadAndIndexLocks(Type gitRepoType)
        {
            using (var testRepo = GetRepository())
            {
                // Arrange
                Git.Init(testRepo.PhysicalPath);
                string fileToWrite = Path.Combine(testRepo.PhysicalPath, "some file.txt");
                File.WriteAllText(Path.Combine(testRepo.PhysicalPath, ".git", "index.lock"), "");
                File.WriteAllText(Path.Combine(testRepo.PhysicalPath, ".git", "HEAD.lock"), "");
                File.WriteAllText(Path.Combine(testRepo.PhysicalPath, ".git", "refs", "heads", "master.lock"), "");
                File.WriteAllText(Path.Combine(testRepo.PhysicalPath, ".git", "refs", "heads", "dev.lock"), "");
                File.WriteAllText(fileToWrite, "Hello world");
                var env = new TestEnvironment
                {
                    RepositoryPath = testRepo.PhysicalPath
                };
                var gitRepo = (IGitRepository)Activator.CreateInstance(gitRepoType, env, new MockDeploymentSettingsManager(), NullTracerFactory.Instance);


                // Assert - 1
                var ex = Assert.Throws<CommandLineException>(() => Git.Add(testRepo.PhysicalPath, fileToWrite));
                Assert.Contains(".git/index.lock': File exists.", ex.Message);
                
                // Act - 2
                gitRepo.ClearLock();
                Git.Add(testRepo.PhysicalPath, fileToWrite);

                Assert.Equal(0, Directory.EnumerateFiles(Path.Combine(testRepo.PhysicalPath, ".git", "refs", "heads"), "*.lock", SearchOption.TopDirectoryOnly).Count());
            }

        }