/// <summary> /// Verify that OOXML SDK can properly validate an OOXML file /// </summary> /// <param name="filePath">filenae of the file under test</param> private void VerifyValidator(string filePath) { // Get File Information object for the target test file FileInfo fi = GetTestFileOne(filePath).GetCopy(); Log.VerifyNotNull(fi, "Test File is copied successfully."); using (OpenXmlPackage package = OpenXmlDomTestExtension.OpenPackage(fi, true)) { Log.VerifyNotNull(package, "File is opened successfully."); OpenXmlValidator validator = new OpenXmlValidator(FileFormatVersions.Office2013); // Verify the number of validation errrors Log.VerifyValue(validator.Validate(package).Count(), 0, "Verifying the number of validation errors...Errors = {0}", validator.Validate(package).Count()); if (validator.Validate(package).Count() != 0) { foreach (ValidationErrorInfo error in validator.Validate(package)) { // List error information Log.Comment("*** Error: {0}", error.Description); Log.Comment("Type = " + error.ErrorType); Log.Comment("Node = " + error.Node); Log.Comment("Parth = " + error.Path); } } } }
/// <summary> /// Verify that OOXML SDK can read OOXML files containing MOE (WebExtension) feature /// </summary> /// <param name="entry">ITestData object for test file</param> private void VerifyReadWebExtension(string filePath) { // Get File Information object for the target test file FileInfo fi = GetTestFileOne(filePath).GetCopy(); Log.VerifyNotNull(fi, "Test File is copied successfully."); try { using (OpenXmlPackage package = OpenXmlDomTestExtension.OpenPackage(fi, false)) { Log.VerifyNotNull(package, "File is opened successfully."); var xl = package as SpreadsheetDocument; foreach (var wsPart in xl.WorkbookPart.WorksheetParts) { // Try to get WebExtensionPart foreach (WebExtensionPart we in wsPart.DrawingsPart.WebExtensionParts) { Log.VerifyValue(we.WebExtension.WebExtensionStoreReference.Version.ToString(), "1.0", "Verifying WebExtension.OsfWebExtensionReference.Version"); Log.VerifyValue(we.WebExtension.LocalName, "webextension", "Verifying WebExtension.LocalName"); } } } } catch (Exception e) { Log.Fail("File = {0}, Message = {1}", filePath, e.Message); } }
/// <summary> /// Verify that OOXML SDK can write and read T - a specific section of an Excel document. /// The function makes use of SectionFetcher<T> class to fetch a specific section from a spreadsheet. /// The functions /// 1. makes a copy of the original document /// 2. looks for the section specified /// 3. modifies it and closes the file /// 4. reopens the file and verifies that the section is modified in the expected way /// </summary> /// <typeparam name="T">the type which represents the section to be alternated</typeparam> /// <param name="filePath">name of the Excel document under test</param> /// <param name="elemFixer">a "section walker" function for modification</param> /// <param name="elemTester">a "section walker" function for validation the modifications made</param> private void VerifyWriteRead <T>(string filePath, ElementHandler <T> elemFixer, ElementHandler <T> elemTester) { // Get File Information object for the target test file FileInfo fi = GetTestFileOne(filePath).GetCopy(); Log.VerifyNotNull(fi, "Test file is copied successfully into {0}", fi.FullName); try { // Open OOXML File with writable mode using (OpenXmlPackage package = OpenXmlDomTestExtension.OpenPackage(fi, true)) { Log.VerifyNotNull(package, "The file is opened for writing"); // Cast package to SpreadsheetDocument using (var xl = package as SpreadsheetDocument) { foreach (T elem in new SectionFetcher <T>(xl)) { elemFixer(elem); } } } // Re-open the file just saved above with read-only mode using (OpenXmlPackage package = OpenXmlDomTestExtension.OpenPackage(fi, false)) { Log.VerifyNotNull(package, "The file is re-opened read-only"); using (var xl = package as SpreadsheetDocument) { foreach (T elem in new SectionFetcher <T>(xl)) { elemTester(elem); } } } } catch (Exception e) { Log.Fail("File = {0}, Message = {1}", filePath, e.Message); } }