public void AttemptToSaveWithInvalidXml() { Expect.Call(executionEnvironment.GetDefaultProgramDataFolder(ApplicationType.Server)).IgnoreArguments().Constraints(Rhino.Mocks.Constraints.Is.NotNull()).Return(applicationDataPath); Expect.Call(delegate { fileSystem.EnsureFolderExists(applicationDataPath); }); Expect.Call(delegate { fileSystem.AtomicSave(string.Empty, string.Empty); }).IgnoreArguments().Constraints(Rhino.Mocks.Constraints.Is.NotNull(), Rhino.Mocks.Constraints.Is.Anything()); mocks.ReplayAll(); result = IntegrationResultMother.CreateSuccessful(); result.Label = "<&/<>"; result.AddTaskResult("<badxml>>"); state = new FileStateManager(fileSystem, executionEnvironment); state.SaveState(result); }
public void SaveToNonExistingFolder() { string newDirectory = Directory.GetCurrentDirectory() + "\\NewDirectory"; Assert.IsFalse(Directory.Exists(newDirectory), "The test directory should not exist"); Expect.Call(executionEnvironment.GetDefaultProgramDataFolder(ApplicationType.Server)).IgnoreArguments(). Constraints(Rhino.Mocks.Constraints.Is.NotNull()).Return(applicationDataPath); Expect.Call(delegate { fileSystem.EnsureGivenFolderExists(newDirectory); }); Expect.Call(delegate { fileSystem.AtomicSave(string.Empty, string.Empty); }).IgnoreArguments().Constraints( Rhino.Mocks.Constraints.Is.NotNull(), Rhino.Mocks.Constraints.Is.Anything()); mocks.ReplayAll(); state = new FileStateManager(fileSystem, executionEnvironment); state.StateFileDirectory = newDirectory; result = IntegrationResultMother.CreateSuccessful(); result.ProjectName = "my project"; state.SaveState(result); }
/// <summary> /// Write the state to disk, ensuring that it gets there in its entirety. /// </summary> /// <param name="result">The integration to save the state for.</param> public void SaveState(IIntegrationResult result) { XmlSerializer serializer = new XmlSerializer(typeof(IntegrationResult)); StringWriter buffer = new Utf8StringWriter(); serializer.Serialize(buffer, result); string path = GetFilePath(result.ProjectName); try { fileSystem.AtomicSave(path, buffer.ToString()); } catch (SystemException e) { throw new CruiseControlException( string.Format(System.Globalization.CultureInfo.CurrentCulture, "Unable to save the IntegrationResult to the specified directory: {0}{1}{2}", path, Environment.NewLine, buffer), e); } }