/// <summary> /// Stores a snapshot of a project build. /// </summary> /// <param name="result">The result that the snapshot is for.</param> /// <param name="snapshot">The project snapshot.</param> public void StoreProjectSnapshot(IIntegrationResult result, ItemStatus snapshot) { var dirPath = this.RootFolder(result.ArtifactDirectory, this.SnapshotsFolder); Log.Info("Writing snapshot (XML) to [" + dirPath + "]"); var logFile = new LogFile(result); var filePath = Path.ChangeExtension( Path.Combine(dirPath, logFile.Filename), "snapshot"); this.FileSystem.EnsureFolderExists(filePath); Log.Debug("Creating new snapshot (XML) [" + filePath + "]"); using (var stream = this.FileSystem.OpenOutputStream(filePath)) { using (var writer = new StreamWriter(stream)) { Log.Debug("Writing snapshot (XML)"); writer.Write(snapshot.ToString()); Log.Debug("Snapshot (XML) written"); } } }
public void ToStringGeneratesXml() { var item = new ItemStatus(); var theName = "myItemName"; var theDesc = "A description"; var theError = "any error here"; var theStatus = ItemBuildStatus.CompletedFailed; var startTime = new DateTime(2010, 1, 1, 12, 12, 12); var completedTime = new DateTime(2010, 1, 1, 13, 12, 12); var estimatedTime = new DateTime(2010, 1, 1, 14, 12, 12); var aChild = new ItemStatus("aChild"); item.Name = theName; item.Description = theDesc; item.Error = theError; item.Status = theStatus; item.TimeStarted = startTime; item.TimeCompleted = completedTime; item.TimeOfEstimatedCompletion = estimatedTime; item.ChildItems.Add(aChild); var xml = item.ToString(); var expected = "<itemStatus xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" name=\"myItemName\" status=\"CompletedFailed\">" + "<description>A description</description>" + "<error>any error here</error>" + "<timeStarted>2010-01-01T12:12:12</timeStarted>" + "<timeCompleted>2010-01-01T13:12:12</timeCompleted>" + "<timeOfEstimatedCompletion>2010-01-01T14:12:12</timeOfEstimatedCompletion>" + "<childItems>" + "<childItem name=\"aChild\" status=\"Unknown\">" + "<timeStarted xsi:nil=\"true\" />" + "<timeCompleted xsi:nil=\"true\" />" + "<timeOfEstimatedCompletion xsi:nil=\"true\" />" + "<childItems />" + "</childItem>" + "</childItems>" + "</itemStatus>"; Assert.AreEqual(expected, xml); }