示例#1
0
        public void MarksTrackingConfigForGarbageCollection()
        {
            using (TestHostContext hc = Setup())
            {
                // Arrange.
                // It doesn't matter for this test whether the line endings are CRLF or just LF.
                const string TrackingContents = @"{
  ""build_artifactstagingdirectory"": ""b00335b6\\a"",
  ""agent_builddirectory"": ""b00335b6"",
  ""collectionUrl"": ""http://contoso:8080/tfs/DefaultCollection/"",
  ""definitionName"": ""M87_PrintEnvVars"",
  ""repositoryTrackingInfo"": [
    {
      ""identifier"": ""self"",
      ""repositoryType"": ""tfsgit"",
      ""repositoryUrl"": ""http://contoso:8080/tfs/DefaultCollection/_git/gitTest"",
      ""sourcesDirectory"": ""b00335b6\\gitTest""
    }
  ],
  ""fileFormatVersion"": 3,
  ""lastRunOn"": ""09/16/2015 23:56:46 -04:00"",
  ""repositoryType"": ""tfsgit"",
  ""lastMaintenanceAttemptedOn"": ""09/16/2015 23:56:46 -04:00"",
  ""lastMaintenanceCompletedOn"": ""09/16/2015 23:56:46 -04:00"",
  ""build_sourcesdirectory"": ""b00335b6\\gitTest"",
  ""common_testresultsdirectory"": ""b00335b6\\TestResults"",
  ""collectionId"": ""7aee6dde-6381-4098-93e7-50a8264cf066"",
  ""definitionId"": ""7"",
  ""hashKey"": ""b00335b6923adfa64f46f3abb7da1cdc0d9bae6c"",
  ""repositoryUrl"": ""http://contoso:8080/tfs/DefaultCollection/_git/gitTest"",
  ""system"": ""build""
}";
                WriteConfigFile(TrackingContents);
                TrackingConfig config = _trackingManager.LoadExistingTrackingConfig(_ec.Object) as TrackingConfig;
                Assert.NotNull(config);

                // Act.
                _trackingManager.MarkForGarbageCollection(_ec.Object, config);

                // Assert.
                string gcDirectory = Path.Combine(
                    _workFolder,
                    Constants.Build.Path.SourceRootMappingDirectory,
                    Constants.Build.Path.GarbageCollectionDirectory);
                Assert.True(Directory.Exists(gcDirectory));
                string[] gcFiles = Directory.GetFiles(gcDirectory);
                Assert.Equal(1, gcFiles.Length);
                string gcFile     = gcFiles.Single();
                string gcContents = File.ReadAllText(gcFile);
                Assert.Equal(TrackingContents, gcContents);
                // File name should a GUID.
                Assert.True(Regex.IsMatch(Path.GetFileNameWithoutExtension(gcFile), "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"));
                // File name should not be the default GUID.
                Assert.NotEqual("00000000-0000-0000-0000-000000000000", Path.GetFileNameWithoutExtension(gcFile));
            }
        }