Skip to content

Commit

Permalink
add framework test
Browse files Browse the repository at this point in the history
  • Loading branch information
twsouthwick committed Jan 9, 2024
1 parent cdac38f commit 01c6f0a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [3.1.0]
## [3.0.1]

### Fixed

- Fixed issue where document type would not be correct unless content type was checked first (#1625)
- Added check to only seek on packages where it is supported (#1644)
- If a malformed URI is encountered, the exception is now the same as v2.x (`OpenXmlPackageException` with an inner `UriFormatException`) (#1644)

## [3.0.0] - 2023-11-15

## Added
### Added

- `DocumentFormat.OpenXml.Office.PowerPoint.Y2023.M02.Main` namespace
- `DocumentFormat.OpenXml.Office.PowerPoint.Y2022.M03.Main` namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ private void InitializePackage(FileMode? mode = default, FileAccess? access = de
SetStream(GetStream(mode.Value, access.Value));
}

_package = Package.Open(_stream, mode.Value, access.Value);
try
{
_package = Package.Open(_stream, mode.Value, access.Value);
}
catch (ArgumentException ex)
{
throw new OpenXmlPackageException(ExceptionMessages.FailedToOpenPackage, ex);
}
}

protected override Package Package => _package;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -411,4 +411,7 @@
<data name="MalformedUri" xml:space="preserve">
<value>The package contains malformed URI relationships. Please ensure the package is opened with a stream (that is seekable) or a file path to have the SDK automatically handle these scenarios.</value>
</data>
<data name="FailedToOpenPackage" xml:space="preserve">
<value>Package could not be opened for stream. See inner exception for details and be aware that there are behavior differences in stream support between .NET Framework and Core.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,21 @@ public void NonSeekableRewriteMalformedUri()
{
// Arrange
using var stream = GetStream(TestFiles.Malformed_uri_xlsx);
using var doc = SpreadsheetDocument.Open(new NonSeekableStream(stream), isEditable: false);

// Act/Assert
var worksheetPart = doc.WorkbookPart.WorksheetParts.Single();
var exception = Assert.Throws<OpenXmlPackageException>(() => worksheetPart.HyperlinkRelationships.Single());
var exception = Assert.Throws<OpenXmlPackageException>(() =>
{
using var doc = SpreadsheetDocument.Open(new NonSeekableStream(stream), isEditable: false);
// Act/Assert
var worksheetPart = doc.WorkbookPart.WorksheetParts.Single();
var link = worksheetPart.HyperlinkRelationships.Single();
});

#if NETFRAMEWORK
Assert.IsType<ArgumentException>(exception.InnerException);
#else
Assert.IsType<UriFormatException>(exception.InnerException);
#endif
}

[Fact]
Expand All @@ -111,7 +119,12 @@ public void NonSeekableRewriteMalformedUriCompatMode()

// Act/Assert
var exception = Assert.Throws<OpenXmlPackageException>(() => SpreadsheetDocument.Open(new NonSeekableStream(stream), isEditable: false, new OpenSettings { CompatibilityLevel = CompatibilityLevel.Version_2_20 }));

#if NETFRAMEWORK
Assert.IsType<ArgumentException>(exception.InnerException);
#else
Assert.IsType<UriFormatException>(exception.InnerException);
#endif
}

private sealed class NonSeekableStream : DelegatingStream
Expand Down

0 comments on commit 01c6f0a

Please sign in to comment.