public void CreateWithNoAutoSaveTest() { this.MyTestInitialize(TestContext.GetCurrentMethod()); var testfiles = CopyTestFiles("bvt") .Where(fi => fi.IsOpenXmlFile()); OpenXmlPackage createdPackage = null; foreach (var testfile in testfiles) { string newlyCreatedName = null; if (testfile.IsWordprocessingFile()) { newlyCreatedName = Path.Combine(TestUtil.TestResultsDirectory, Guid.NewGuid().ToString() + ".docx"); } else if (testfile.IsSpreadsheetFile()) { newlyCreatedName = Path.Combine(TestUtil.TestResultsDirectory, Guid.NewGuid().ToString() + ".xlsx"); } else if (testfile.IsPresentationFile()) { newlyCreatedName = Path.Combine(TestUtil.TestResultsDirectory, Guid.NewGuid().ToString() + ".pptx"); } Log.Comment("Opening source package in readOnly mode..."); var sourcePackage = testfile.OpenPackage(false); Log.Comment("Creating new package with overload that no autoSave option"); if (testfile.IsWordprocessingFile()) { createdPackage = WordprocessingDocument.Create(newlyCreatedName, WordprocessingDocumentType.Document); } else if (testfile.IsSpreadsheetFile()) { createdPackage = SpreadsheetDocument.Create(newlyCreatedName, SpreadsheetDocumentType.Workbook); } else if (testfile.IsPresentationFile()) { createdPackage = PresentationDocument.Create(newlyCreatedName, PresentationDocumentType.Presentation); } else { Log.Fail("Unexpected document type passed in."); } if (createdPackage != null) { Log.Comment("Feeding main part with DOM operations..."); duplicteMainPart(sourcePackage, createdPackage); Log.Comment("Closing package..."); createdPackage.Close(); } Log.Warning("Reopening...Expecting null for root element of main part as AutoSave default value is true thus DOM changes will be saved."); if (testfile.IsWordprocessingFile()) { createdPackage = WordprocessingDocument.Open(newlyCreatedName, false); } else if (testfile.IsSpreadsheetFile()) { createdPackage = SpreadsheetDocument.Open(newlyCreatedName, false); } else if (testfile.IsPresentationFile()) { createdPackage = PresentationDocument.Open(newlyCreatedName, false); } else { Log.Fail("Unexpected document type passed in."); } var mainpart = createdPackage.MainPart(); var dom = mainpart.RootElement; if (dom != null) { Log.Pass("Root element of main part is not null just as expected."); } else { Log.Fail("Null root element of main part. Something must be wrong."); } createdPackage.Close(); FileInfo fz = new FileInfo(newlyCreatedName); if (fz.Exists) { fz.Delete(); } } }