Пример #1
0
        public void Fb2Document_Empty_EqualityTest()
        {
            var emptyFirstDocument = new Fb2Document();

            emptyFirstDocument.Book.Should().BeNull();
            emptyFirstDocument.IsLoaded.Should().BeFalse();

            emptyFirstDocument.Equals(null).Should().BeFalse();

            var emptySecondDocument = new Fb2Document();

            emptySecondDocument.Book.Should().BeNull();
            emptySecondDocument.IsLoaded.Should().BeFalse();

            emptyFirstDocument.Should().Be(emptySecondDocument);

            var emptyCreatedFirstDocument = Fb2Document.CreateDocument();

            emptyCreatedFirstDocument.Book.Should().BeNull();
            emptyCreatedFirstDocument.IsLoaded.Should().BeFalse();

            var emptyCreatedSecondDocument = Fb2Document.CreateDocument();

            emptyCreatedSecondDocument.Book.Should().BeNull();
            emptyCreatedSecondDocument.IsLoaded.Should().BeFalse();

            emptyCreatedFirstDocument.Should().Be(emptyCreatedSecondDocument);

            emptyFirstDocument.Should().Be(emptyCreatedFirstDocument);
        }
Пример #2
0
        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);
            }
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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();
            }
        }