public void ShouldBuildArchiveFromExistingFile() { var fieldMetaDataBuilder = FieldsMetaDataBuilder.Fields() .AutomaticallyIndex() .AddField(_ => _.Term(Terms.taxonID)) .AddField(_ => _.Term(Terms.vernacularName)) .AddField(_ => _.Term(Terms.language)); var fileMetaData = CoreFileMetaDataBuilder.File("taxon.txt") .FieldsEnclosedBy("\"") .FieldsTerminatedBy(",") .LinesTerminatedBy("\\n") .IgnoreHeaderLines(1) .Encoding(Encoding.UTF8) .Index(0) .RowType(RowTypes.Taxon) .AddFields(fieldMetaDataBuilder); var fileBuider = FileBuilder.MetaData(fileMetaData) .UseExistingFile("./resources/whales/whales.txt"); ArchiveWriter.CoreFile(fileBuider, fileMetaData) .Build("whales.zip"); Assert.True(File.Exists("whales.zip")); using (var archive = new ArchiveReader("whales.zip")) { var whales = archive.CoreFile .DataRows .Select(n => n[Terms.vernacularName]); Assert.Equal(new[] { "sperm whale", "cachalot", "gray whale" }, whales); } }
public void LogWithoutStartWordShouldNotReturnAnyFiles() { // arrange var buffer = Encoding.UTF8.GetBytes(TestResources.LogWithoutStartWord); var stream = new MemoryStream(buffer); // act var task = FileBuilder.FromStream(stream); var result = task.Result; // assert result.Should().HaveCount(0); }
public void LogWithMultipleBlocksShouldReturnGivenInformation() { // arrange var buffer = Encoding.UTF8.GetBytes(TestResources.LogWithMultipleBlocksOfFiles); var stream = new MemoryStream(buffer); // act var task = FileBuilder.FromStream(stream); var result = task.Result; // assert var first = result.First(); result.Should().HaveCount(6); first.Item1.Should().Be("file1"); first.Item2.Should().Be(2.1f); }
public async Task ShouldBuildArchive() { var context = BuilderContext.Default; var occurrences = await fixture.GetOccurrencesAsync(); var occurrenceMetaDataBuilder = fixture.OccurrenceFieldsMetaDataBuilder; var coreFileMetaDataBuilder = CoreFileMetaDataBuilder.File("occurrence.txt") .IgnoreHeaderLines(1) .Encoding(Encoding.UTF8) .Index(0) .RowType(RowTypes.Occurrence) .AddFields(occurrenceMetaDataBuilder); var coreFileBuilder = FileBuilder.MetaData(coreFileMetaDataBuilder) .Context(context) .BuildRows(rowBuilder => BuildCoreRows(rowBuilder)); var multimedia = await fixture.GetMultimediaAsync(); var multimediaMetaDataBuilder = fixture.MultimediaMetaDataBuilder; var extensionFileMetaDataBuilder = ExtensionFileMetaDataBuilder.File("multimedia.txt") .IgnoreHeaderLines(1) .Encoding(Encoding.UTF8) .CoreIndex(0) .RowType(RowTypes.Occurrence) .AddFields(multimediaMetaDataBuilder); var extensionFileBuilder = FileBuilder.MetaData(extensionFileMetaDataBuilder) .Context(context) .BuildRows(rowBuilder => BuildExtensionRows(rowBuilder)); var archiveName = "archivexxx.zip"; ArchiveWriter.CoreFile(coreFileBuilder, coreFileMetaDataBuilder) .Context(context) .AddExtensionFile(extensionFileBuilder, extensionFileMetaDataBuilder) .AddExtraFile("resources/ExtraData.txt") .Build(archiveName); Assert.True(File.Exists(archiveName)); context.Cleanup(); }
public void ShouldBuildOccurrenceFile() { var fieldsMetaDataBuilder = fixture.OccurrenceFieldsMetaDataBuilder; var context = new BuilderContext("."); var occurrenceMetaDataBuilder = CoreFileMetaDataBuilder.File("occurrence.txt") .IgnoreHeaderLines(1) .Encoding(Encoding.UTF8) .Index(0) .RowType(RowTypes.Occurrence) .AddFields(fieldsMetaDataBuilder) .Build(); var coreFileMetaData = new CoreFileMetaData(occurrenceMetaDataBuilder); var fileBuilder = FileBuilder.MetaData(coreFileMetaData) .Context(context) .BuildRows(rowBuilder => BuildOccurrenceRows(rowBuilder)); var fileName = fileBuilder.Build(); Assert.True(File.Exists(fileName)); }