public async Task LoadWithoutUnsafeNodes_DifferentContent() { var sampleFileInfo = GetSampleFileInfo(SampleFileName); using (var fileReadStream = sampleFileInfo.OpenRead()) { // loading document first time var firstDocument = new Fb2Document(); await firstDocument.LoadAsync(fileReadStream); RewindStream(fileReadStream); // loading document without unsafe nodes var secondDocument = new Fb2Document(); await secondDocument.LoadAsync(fileReadStream, new Fb2StreamLoadingOptions(false)); firstDocument.Should().NotBe(secondDocument); var firstBook = firstDocument.Book; var secondBook = secondDocument.Book; // different content due to skipped unsafe nodes firstBook.Should().NotBe(secondBook); } }
public async Task Load_WithCloseInput_ClosesStream() { var sampleFileInfo = GetSampleFileInfo(SampleFileName); using (var fileReadStream = sampleFileInfo.OpenRead()) { // loading document without unsafe nodes var firstDocument = new Fb2Document(); await firstDocument .LoadAsync(fileReadStream, new Fb2StreamLoadingOptions(closeInputStream : true)); await fileReadStream .Invoking(async s => await s.WriteAsync(new byte[5] { 4, 2, 0, 6, 9 })) .Should() .ThrowExactlyAsync <ObjectDisposedException>(); } }
public async Task SameFile_DifferentLoads_SameContent() { var sampleFileInfo = GetSampleFileInfo(SampleFileName); var fileStringContent = await ReadFileAsString(sampleFileInfo); var xDocument = await ReadFileAsXDocument(sampleFileInfo); var stringLoadedFb2Document = new Fb2Document(); stringLoadedFb2Document.Load(fileStringContent); // string var stringLoadedAsyncFb2Document = new Fb2Document(); await stringLoadedAsyncFb2Document.LoadAsync(fileStringContent); var xmlLoadedFb2Document = new Fb2Document(); xmlLoadedFb2Document.Load(xDocument); // xDocument var streamLoadedFb2Document = new Fb2Document(); var streamLoadedAsyncFb2Document = new Fb2Document(); using (var stream = sampleFileInfo.OpenRead()) { streamLoadedFb2Document.Load(stream); // sync stream RewindStream(stream); await streamLoadedAsyncFb2Document.LoadAsync(stream); // async stream } stringLoadedFb2Document .Should().Be(stringLoadedAsyncFb2Document) .And.Be(xmlLoadedFb2Document) .And.Be(streamLoadedFb2Document) .And.Be(streamLoadedAsyncFb2Document); stringLoadedFb2Document.Book .Should().Be(stringLoadedAsyncFb2Document.Book) .And.Be(xmlLoadedFb2Document.Book) .And.Be(streamLoadedFb2Document.Book) .And.Be(streamLoadedAsyncFb2Document.Book); }
public async Task ExportDocument_AndReload_SameContent() { var sampleFileInfo = GetSampleFileInfo(SampleFileName); using (var fileReadStream = sampleFileInfo.OpenRead()) { // loading document first time var firstDocument = new Fb2Document(); await firstDocument.LoadAsync(fileReadStream); var firstDocXml = firstDocument.ToXml(); var secondDocument = new Fb2Document(); secondDocument.Load(firstDocXml); firstDocument.Should().Be(secondDocument); var firstBook = firstDocument.Book; var secondBook = secondDocument.Book; firstBook.Should().Be(secondBook); } }
public async Task InstancesOfBookAreSame() { var sampleFileInfo = GetSampleFileInfo(SampleFileName); using (var fileReadStream = sampleFileInfo.OpenRead()) { var firstDocument = new Fb2Document(); await firstDocument.LoadAsync(fileReadStream); RewindStream(fileReadStream); var secondDocument = Fb2Document.CreateDocument(); await secondDocument.LoadAsync(fileReadStream); firstDocument.Should().Be(secondDocument); var firstBook = firstDocument.Book; var secondBook = secondDocument.Book; firstBook.Should().Be(secondBook); fileReadStream.Close(); } }
public async Task LoadWithoutMetadata_DifferentContent() { var sampleFileInfo = GetSampleFileInfo(SampleFileName); using (var fileReadStream = sampleFileInfo.OpenRead()) { // loading document first time var firstDocument = new Fb2Document(); await firstDocument.LoadAsync(fileReadStream); RewindStream(fileReadStream); // loading document without unsafe nodes var secondDocument = new Fb2Document(); await secondDocument.LoadAsync(fileReadStream, new Fb2StreamLoadingOptions(loadNamespaceMetadata : false)); firstDocument.Book !.NodeMetadata.Should().NotBeNull(); secondDocument.Book !.NodeMetadata.Should().BeNull(); firstDocument.Bodies.First().NodeMetadata.Should().NotBeNull(); secondDocument.Bodies.First().NodeMetadata.Should().BeNull(); } }
public async Task BookContentCheck() { var sampleFileInfo = GetSampleFileInfo(SampleFileName); using (var fileReadStream = sampleFileInfo.OpenRead()) { var document = new Fb2Document(); await document.LoadAsync(fileReadStream); document.Bodies.Should().HaveCount(3); var firstBody = document.Bodies[0]; var firstBodyTitle = firstBody.GetFirstChild <Title>(); firstBodyTitle.Should().NotBeNull(); var firstBodySections = firstBody.GetChildren <BodySection>(); firstBodySections.Should().HaveCount(9); var secondBody = document.Bodies[1]; var secondBodyAttributes = secondBody.Attributes.Should().HaveCount(1); var secondBodyNameAttribute = secondBody.Attributes.First(); secondBodyNameAttribute.Key.Should().Be(AttributeNames.Name); secondBodyNameAttribute.Value.Should().Be("notes"); var secondBodyTitle = secondBody.GetFirstChild <Title>(); secondBodyTitle.Should().NotBeNull(); var secondBodySections = secondBody.GetChildren <BodySection>(); secondBodySections.Should().HaveCount(20); var thirdBody = document.Bodies[2]; var thirdBodySections = thirdBody.GetChildren <BodySection>(); thirdBodySections.Should().HaveCount(1); document.BinaryImages.Should().HaveCount(33); } }