public void OpenWithFileFormatVersionsDefaultValueNoMCProcessTest() { this.MyTestInitialize(TestContext.GetCurrentMethod()); var testfiles = CopyTestFiles("bvt") .Where(fi => fi.IsOpenXmlFile()); var testfile = testfiles.FirstOrDefault(); FileFormatVersions format = FileFormatVersions.None; var mcmodes = new MarkupCompatibilityProcessMode[] { MarkupCompatibilityProcessMode.NoProcess }; foreach (var mcmode in mcmodes) { var invalidSettings = new OpenSettings() { MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(mcmode, format) }; Log.Comment("New OpenSettings with..."); Log.Comment("ProcessMode = {0}", invalidSettings.MarkupCompatibilityProcessSettings.ProcessMode); Log.Comment("TargetFileFormatVersions = {0}", invalidSettings.MarkupCompatibilityProcessSettings.TargetFileFormatVersions); try { Log.Comment("Opening package with constructed OpenSettings..."); var package = testfile.OpenPackage(true, invalidSettings); package.Close(); Log.Pass("No exception thrown for default value of FileFormatVersions as MarkupCompatibilityProcessMode.NoProcess"); } catch (Exception ex) { Log.Fail("{0} caught with detailed information: \n{1}", ex.GetType().Name, ex.ToString()); } } }
public void OpenWithFileFormatVersionsDefaultValue(MarkupCompatibilityProcessMode mode, int format) { using (var file = OpenFile(TestDataStorage.V2FxTestFiles.Bvt.Complex2005_12rtm, false)) { var invalidSettings = new OpenSettings() { MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(mode, (FileFormatVersions)format), }; using (var package = file.Open(false, invalidSettings)) { Assert.NotNull(package); } } }
public void OpenMcPackage(FileFormatVersions format, MarkupCompatibilityProcessMode mcMode) { using (var file = OpenFile(Path, true)) { var settings = new OpenSettings() { MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(mcMode, format) }; using (var package = file.Open(true, settings)) { Assert.NotNull(package); } } }
public void OpenWithInvalidFileFormatTest(MarkupCompatibilityProcessMode mode, int format) { using (var file = OpenFile(TestDataStorage.V2FxTestFiles.Bvt.Complex2005_12rtm, false)) { var invalidSettings = new OpenSettings() { MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(mode, (FileFormatVersions)format), }; Assert.Throws <ArgumentException>(() => { using (var package = file.Open(false, invalidSettings)) { } }); } }
private void OpenMcPackage(FileFormatVersions format, MarkupCompatibilityProcessMode mcMode) { var testfiles = CopyTestFiles(@"bvt") .Where(f => f.IsOpenXmlFile()); foreach (var testfile in testfiles) { string logGroupName = testfile.FullName; Log.BeginGroup(logGroupName); Log.Comment("Opening stream with FileAccess.ReadWrite..."); Stream st = testfile.Open(FileMode.Open, FileAccess.ReadWrite); var settings = new OpenSettings() { MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(mcMode, format) }; Log.Comment("Opening Package with AutoSave: {0}, mcProcessmode: {1}, FileFormat: {2} ...", bool.TrueString, settings.MarkupCompatibilityProcessSettings.ProcessMode, settings.MarkupCompatibilityProcessSettings.TargetFileFormatVersions); if (testfile.IsWordprocessingFile()) { var package = WordprocessingDocument.Open(st, true, settings); package.MainPart().RootElement.FirstChild.Remove(); package.Close(); } if (testfile.IsSpreadsheetFile()) { var package = SpreadsheetDocument.Open(st, true, settings); package.MainPart().RootElement.FirstChild.Remove(); package.Close(); } if (testfile.IsPresentationFile()) { var package = PresentationDocument.Open(st, true, settings); package.MainPart().RootElement.FirstChild.Remove(); package.Close(); } Log.Pass("Package Closed without any errors."); } }
/// <summary> /// Open specified existing package. /// </summary> /// <param name="file">File to be opened.</param> /// <param name="writable">Open package in read/write mode if true, false for readonly.</param> /// <returns>OpenXmlPackage instance for opened package.</returns> public static OpenXmlPackage OpenPackage(this FileInfo file, bool writable, FileFormatVersions format, MarkupCompatibilityProcessMode mcProcessMode) { var settings = new OpenSettings() { MarkupCompatibilityProcessSettings = new MarkupCompatibilityProcessSettings(mcProcessMode, format), }; return(OpenPackage(file, writable, settings)); }
/// <summary> /// Creates a MarkupCompatibilityProcessSettings object using the supplied process mode and file format versions. /// </summary> /// <param name="processMode">The process mode.</param> /// <param name="targetFileFormatVersions">The file format versions. This parameter is ignored if the value is NoProcess.</param> public MarkupCompatibilityProcessSettings(MarkupCompatibilityProcessMode processMode, FileFormatVersions targetFileFormatVersions) { ProcessMode = processMode; TargetFileFormatVersions = targetFileFormatVersions; }