public void UpdatesTopLevelTrackingConfig() { using (TestHostContext hc = Setup()) { // Arrange. string trackingFile = Path.Combine(_workFolder, "trackingconfig.json"); _trackingManager.Create(_ec.Object, _repository, "some hash key", trackingFile, false); DateTimeOffset testStartOn = DateTimeOffset.Now; // Act. _trackingManager.Create(_ec.Object, _repository, "some hash key", trackingFile, false); // Assert. string topLevelFile = Path.Combine( _workFolder, Constants.Build.Path.SourceRootMappingDirectory, Constants.Build.Path.TopLevelTrackingConfigFile); TopLevelTrackingConfig config = JsonConvert.DeserializeObject <TopLevelTrackingConfig>( value: File.ReadAllText(topLevelFile)); Assert.Equal(2, config.LastBuildDirectoryNumber); // Manipulate the expected seconds due to loss of granularity when the // date-time-offset is serialized in a friendly format. Assert.True(testStartOn.AddSeconds(-1) <= config.LastBuildDirectoryCreatedOn); Assert.True(DateTimeOffset.Now.AddSeconds(1) >= config.LastBuildDirectoryCreatedOn); } }
public TrackingConfig2 Create( IExecutionContext executionContext, string repositoryUrl, string hashKey, string file) { Trace.Entering(); // Get or create the top-level tracking config. TopLevelTrackingConfig topLevelConfig; string topLevelFile = Path.Combine( IOUtil.GetWorkPath(HostContext), Constants.Build.Path.SourceRootMappingDirectory, Constants.Build.Path.TopLevelTrackingConfigFile); Trace.Verbose($"Loading top-level tracking config if exists: {topLevelFile}"); if (!File.Exists(topLevelFile)) { topLevelConfig = new TopLevelTrackingConfig(); } else { topLevelConfig = JsonConvert.DeserializeObject <TopLevelTrackingConfig>( value: File.ReadAllText(topLevelFile)); } // Update the top-level tracking config. topLevelConfig.LastBuildDirectoryCreatedOn = DateTimeOffset.Now; topLevelConfig.LastBuildDirectoryNumber++; WriteToFile(topLevelFile, topLevelConfig); // Create the new tracking config. TrackingConfig2 config = new TrackingConfig2( executionContext, repositoryUrl, topLevelConfig.LastBuildDirectoryNumber, hashKey); WriteToFile(file, config); return(config); }