-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds tests to ensure a QPdf object can only be written once
- Loading branch information
1 parent
b058c73
commit d61f271
Showing
2 changed files
with
97 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright © Stephen (Sven) Vernyi and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information. | ||
|
||
namespace QPdfSharp.Tests; | ||
|
||
public class QPdfWritingTests | ||
{ | ||
[Fact] | ||
public async Task Can_write_pdf_file() | ||
{ | ||
// Arrange | ||
var outputFileName = "qgrug.pdf"; | ||
|
||
using var qpdf = new QPdf(TestAssets.Grug); | ||
|
||
// Act | ||
qpdf.WriteFile(outputFileName); | ||
|
||
// Assert | ||
File.Exists(outputFileName).Should().BeTrue(); | ||
(await File.ReadAllBytesAsync(outputFileName)).Should().NotBeEmpty(); | ||
File.Delete(outputFileName); | ||
} | ||
|
||
[Fact] | ||
public void Can_write_pdf_bytes() | ||
{ | ||
// Arrange | ||
using var qpdf = new QPdf(TestAssets.Grug); | ||
|
||
// Act | ||
var getPdfBytes = qpdf.WriteBytes().ToArray(); | ||
|
||
// Assert | ||
getPdfBytes.Should().NotBeEmpty(); | ||
} | ||
|
||
[Fact] | ||
public void Can_write_pdf_stream() | ||
{ | ||
// Arrange | ||
using var qpdf = new QPdf(TestAssets.Grug); | ||
|
||
// Act | ||
using var pdfStream = qpdf.WriteStream(); | ||
|
||
// Assert | ||
pdfStream.Should().NotHaveLength(0); | ||
pdfStream.Should().BeReadOnly(); | ||
} | ||
|
||
[Fact] | ||
public void Throws_on_consecutive_writes_to_stream() | ||
{ | ||
// Arrange | ||
using var qpdf = new QPdf(TestAssets.Grug); | ||
|
||
_ = qpdf.WriteBytes(); | ||
|
||
// Act | ||
var writeAgain = () => qpdf.WriteStream(); | ||
|
||
// Assert | ||
writeAgain.Should().Throw<InvalidOperationException>(); | ||
} | ||
|
||
[Fact] | ||
public void Throws_on_consecutive_writes_to_bytes() | ||
{ | ||
// Arrange | ||
using var qpdf = new QPdf(TestAssets.Grug); | ||
|
||
_ = qpdf.WriteBytes(); | ||
|
||
// Act | ||
var writeAgain = () => qpdf.WriteBytes().ToArray(); | ||
|
||
// Assert | ||
writeAgain.Should().Throw<InvalidOperationException>(); | ||
} | ||
|
||
[Fact] | ||
public void Throws_on_consecutive_writes_to_file() | ||
{ | ||
// Arrange | ||
var outputFileName = "qgrug.pdf"; | ||
|
||
using var qpdf = new QPdf(TestAssets.Grug); | ||
qpdf.WriteFile(outputFileName); | ||
|
||
// Act | ||
var writeAgain = () => qpdf.WriteFile(outputFileName); | ||
|
||
// Assert | ||
writeAgain.Should().Throw<InvalidOperationException>(); | ||
File.Delete(outputFileName); | ||
} | ||
} |