/// <summary> /// Saves the changes made to the specified catalog on disk. /// </summary> /// <param name="catalog">The catalog to save.</param> /// <param name="backup">Whether to create a backup of the original catalog.</param> /// <param name="wrapReferences">Whether to word-wrap comment references.</param> /// <returns></returns> public static bool SaveChanges(this ICatalog catalog, bool backup = false, bool wrapReferences = false) { try { // save the changes to a temporary file location var tempname = new PoFileWriter(catalog) { WordWrapReferences = wrapReferences }.SaveChanges(); var catalogName = catalog.FileName; if (File.Exists(catalogName)) { if (backup) { File.Move(catalogName, $"{catalogName}.{DateTime.Now.ToString("yyyy-MM-dd-HHmmss")}.bak"); } else { File.Delete(catalogName); } } File.Copy(tempname, catalogName); return(true); } catch //(Exception ex) { //System.Diagnostics.Trace.WriteLine(ex); } return(false); }
public PoFileWriter CreateTestee(string testString) { var fileHelperMock = A.Fake <IFileHelper>(); _extendedStreamReaderMock = new ExtendedStreamReaderFake(testString); A.CallTo(() => fileHelperMock.GetExtendedStreamReader(TestFileInputPath)).Returns(_extendedStreamReaderMock); A.CallTo(() => fileHelperMock.GetStreamWriter(TestFileOutputPath)).Returns(_streamWriterMock); var persistentFileConversionPropertiesMock = A.Fake <IPersistentFileConversionProperties>(); A.CallTo(() => persistentFileConversionPropertiesMock.OriginalFilePath).Returns(TestFileInputPath); var nativeOutputFilePropertiesMock = A.Fake <INativeOutputFileProperties>(); A.CallTo(() => nativeOutputFilePropertiesMock.OutputFilePath).Returns(TestFileOutputPath); var outputFileInfoMock = A.Fake <IOutputFileInfo>(); var filePropertiesMock = A.Fake <IFileProperties>(); var testee = new PoFileWriter(fileHelperMock, _segmentReaderMock, _lineParserMock, _entryBuilderMock); testee.SetOutputProperties(nativeOutputFilePropertiesMock); testee.GetProposedOutputFileInfo(persistentFileConversionPropertiesMock, outputFileInfoMock); testee.SetFileProperties(filePropertiesMock); return(testee); }
public void Should_Write_PO_File() { // ARRANGE var catalog = PoFileReader.Parse(Resources.admin_fr_FR, CULTURE); // ACT var output = new PoFileWriter(catalog).Export(); // ASSERT Assert.IsFalse(string.IsNullOrEmpty(output)); Trace.WriteLine(output); }