Skip to content

Commit

Permalink
Merge pull request #82 from pjoiner/#80-TestingPlatform
Browse files Browse the repository at this point in the history
#80 testing platform
  • Loading branch information
pjoiner authored Jan 25, 2025
2 parents 1fbdd54 + b946e65 commit 5d8865b
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 91 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ jobs:
- name: Build
run: dotnet build -c Release --no-restore
- name: Test
run: dotnet test --verbosity normal -p:CollectCoverage=true
- name: Upload a Build Artifact
run: dotnet run --framework net9.0 --report-xunit-html --report-xunit-html-filename TestReport.html --project src/Tests/Tests.csproj
- name: Upload Build Artifact
uses: actions/upload-artifact@v4
with:
name: DwC-A_dotnet.nupkg
path: src/DWC_A/bin/Release/DwC-A_dotnet.*.nupkg
path: src/DWC_A/bin/Release/DwC-A_dotnet.*.nupkg
- name: Upload Test Report
uses: actions/upload-artifact@v4
with:
name: TestReport.html
path: src/Tests/bin/**/TestReport.html
48 changes: 21 additions & 27 deletions src/Tests/ArchiveReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,42 @@ public class ArchiveReaderTests
[Fact]
public void ShouldOpenCoreFile()
{
using (var archive = new ArchiveReader(archiveFileName))
using var archive = new ArchiveReader(archiveFileName);
foreach (var row in archive.CoreFile.Rows)
{
foreach(var row in archive.CoreFile.Rows)
{
Assert.NotNull(row[0]);
Assert.NotNull(row["id"]);
}
Assert.NotNull(row[0]);
Assert.NotNull(row["id"]);
}
}

[Fact]
public async Task ShouldOpenCoreFileAsync()
{
using(var archive = new ArchiveReader(archiveFileName))
using var archive = new ArchiveReader(archiveFileName);
await foreach (var row in archive
.GetAsyncCoreFile()
.GetDataRowsAsync(TestContext.Current.CancellationToken))
{
await foreach(var row in archive.GetAsyncCoreFile().GetDataRowsAsync())
{
Assert.NotNull(row[0]);
}
Assert.NotNull(row[0]);
}
}

[Fact]
public void ShouldReturnDescriptionExtensionFile()
{
using (var archive = new ArchiveReader(archiveFileName))
{
var descriptionFile = archive.Extensions.GetFileReaderByFileName("description.txt");
Assert.NotEmpty(descriptionFile.Rows);
}
using var archive = new ArchiveReader(archiveFileName);
var descriptionFile = archive.Extensions.GetFileReaderByFileName("description.txt");
Assert.NotEmpty(descriptionFile.Rows);
}

[Fact]
public async Task ShouldReturnDescriptionExtensionFileAsync()
{
using (var archive = new ArchiveReader(archiveFileName))
{
var descriptionFile = archive.Extensions.GetAsyncFileReaderByFileName("description.txt");
Assert.NotEmpty(await descriptionFile.GetDataRowsAsync().ToArrayAsync());
}
using var archive = new ArchiveReader(archiveFileName);
var descriptionFile = archive.Extensions.GetAsyncFileReaderByFileName("description.txt");
Assert.NotEmpty(await descriptionFile
.GetDataRowsAsync(TestContext.Current.CancellationToken)
.ToArrayAsync(TestContext.Current.CancellationToken));
}

[Fact]
Expand All @@ -75,12 +71,10 @@ public void ShouldNotThrowOnDispose()
[Fact]
public void ShouldOpenWhalesArchive()
{
using (var whales = new ArchiveReader(whalesArchiveFileName))
{
Assert.NotEmpty(whales.CoreFile.Rows);
Assert.Empty(whales.CoreFile.FileMetaData.Fields);
Assert.Equal(4, whales.CoreFile.DataRows.Count());
}
using var whales = new ArchiveReader(whalesArchiveFileName);
Assert.NotEmpty(whales.CoreFile.Rows);
Assert.Empty(whales.CoreFile.FileMetaData.Fields);
Assert.Equal(4, whales.CoreFile.DataRows.Count());
}

[Fact]
Expand Down
30 changes: 11 additions & 19 deletions src/Tests/ArchiveWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,13 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Tests
{
[Collection("ArchiveWriterCollection")]
public class ArchiveWriterTests
public class ArchiveWriterTests(ArchiveWriterFixture fixture)
{
private readonly ArchiveWriterFixture fixture;

public ArchiveWriterTests(ArchiveWriterFixture fixture)
{
this.fixture = fixture;
}
private readonly ArchiveWriterFixture fixture = fixture;

[Fact]
public void ShouldBuildArchiveFromExistingFile()
Expand All @@ -46,19 +40,17 @@ public void ShouldBuildArchiveFromExistingFile()

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);
}
using var archive = new ArchiveReader("whales.zip");
var whales = archive.CoreFile
.DataRows
.Select(n => n[Terms.vernacularName]);
Assert.Equal(["sperm whale", "cachalot", "gray whale"], whales);
}

[Fact]
public async Task ShouldBuildArchive()
{
var context = BuilderContext.Default;
var context = new BuilderContext(Guid.NewGuid().ToString(), true);

var occurrences = await fixture.GetOccurrencesAsync();
var occurrenceMetaDataBuilder = fixture.OccurrenceFieldsMetaDataBuilder;
Expand Down Expand Up @@ -98,7 +90,7 @@ public async Task ShouldBuildArchive()
[Fact]
public async Task ShouldBuildCoreFile()
{
var context = BuilderContext.Default;
var context = new BuilderContext(Guid.NewGuid().ToString(), true);

var occurrences = await fixture.GetOccurrencesAsync();
var occurrenceMetaDataBuilder = fixture.OccurrenceFieldsMetaDataBuilder;
Expand All @@ -121,7 +113,7 @@ public async Task ShouldBuildCoreFile()
[Fact]
public async Task ShouldBuildCoreFileWithCustomHeader()
{
var context = BuilderContext.Default;
var context = new BuilderContext(Guid.NewGuid().ToString(), true);

var occurrences = await fixture.GetOccurrencesAsync();
var occurrenceMetaDataBuilder = fixture.OccurrenceFieldsMetaDataBuilder;
Expand All @@ -146,7 +138,7 @@ public async Task ShouldBuildCoreFileWithCustomHeader()
[Fact]
public async Task FileBuilderShouldThrowOnWrongNumberOfHeaderLines()
{
var context = BuilderContext.Default;
var context = new BuilderContext(Guid.NewGuid().ToString(), true);

var occurrences = await fixture.GetOccurrencesAsync();
var occurrenceMetaDataBuilder = fixture.OccurrenceFieldsMetaDataBuilder;
Expand Down
16 changes: 8 additions & 8 deletions src/Tests/FieldMetadataTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Tests
{
public class FieldMetadataTests
{
readonly ICollection<FieldType> fieldTypes = new List<FieldType>()
{
readonly ICollection<FieldType> fieldTypes =
[
new FieldType()
{
Index = 1,
Expand All @@ -29,9 +29,9 @@ public class FieldMetadataTests
Term = Terms.accessRights,
Default = "Default Value"
}
};
];

IFieldMetaData fieldMetaData;
FieldMetaData fieldMetaData;

[Fact]
public void ShouldReturnNegativeOneOnNotFound()
Expand All @@ -57,7 +57,7 @@ public void ShouldReturnCount3WithId()
IndexSpecified = true
};
fieldMetaData = new FieldMetaData( idField, fieldTypes);
Assert.Equal(4, fieldMetaData.Count());
Assert.Equal(4, fieldMetaData.Length);
}

[Fact]
Expand All @@ -70,7 +70,7 @@ public void ShouldNotCreateDuplicateIdFields()
IndexSpecified = true
};
fieldMetaData = new FieldMetaData(idField, fieldTypes);
Assert.Equal(3, fieldMetaData.Count());
Assert.Equal(3, fieldMetaData.Length);
}

[Fact]
Expand All @@ -96,7 +96,7 @@ public void ShouldReturnListOfDefaultFields()
IndexSpecified = true
};
fieldMetaData = new FieldMetaData(idField, fieldTypes);
Assert.NotEmpty(fieldMetaData.Where(n => !n.IndexSpecified));
Assert.Contains(Terms.accessRights, fieldMetaData.SingleOrDefault(n => !n.IndexSpecified).Term);
}

[Fact]
Expand All @@ -109,7 +109,7 @@ public void ShouldEnumerateAllFields()
IndexSpecified = true
};
fieldMetaData = new FieldMetaData(idField, fieldTypes);
Assert.Equal(4, fieldMetaData.Count());
Assert.Equal(4, fieldMetaData.Length);
}
}
}
27 changes: 19 additions & 8 deletions src/Tests/FileReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ namespace Tests
public class FileReaderTests
{
private const string fileName = "./resources/dwca-vascan-v37.5/taxon.txt";
private const string resourceRelationShipFileName = "./resources/dwca-vascan-v37.5/resourcerelationship.txt";
private readonly IRowFactory rowFactory;
private readonly ITokenizer tokenizer;
private readonly Mock<IFileMetaData> fileMetaDataMock = new Mock<IFileMetaData>();
private readonly Mock<IFileMetaData> fileMetaDataMock = new();

public FileReaderTests()
{
Expand Down Expand Up @@ -51,7 +50,9 @@ public async Task ShouldEnumerateFileAsync()
var fileReader = new FileReader(fileName,
rowFactory, tokenizer, fileMetaDataMock.Object,
new FileReaderConfiguration());
Assert.NotEmpty(await fileReader.GetDataRowsAsync().ToArrayAsync());
Assert.NotEmpty(await fileReader
.GetDataRowsAsync(TestContext.Current.CancellationToken)
.ToArrayAsync(TestContext.Current.CancellationToken));
}

[Fact]
Expand All @@ -71,7 +72,9 @@ public async Task ShouldReturnHeaderRowAsync()
var fileReader = new FileReader(fileName,
rowFactory, tokenizer, fileMetaDataMock.Object,
new FileReaderConfiguration());
Assert.Single(await fileReader.GetHeaderRowsAsync().ToArrayAsync());
Assert.Single(await fileReader
.GetHeaderRowsAsync(TestContext.Current.CancellationToken)
.ToArrayAsync(TestContext.Current.CancellationToken));
}

[Fact]
Expand All @@ -91,7 +94,9 @@ public async Task ShouldReturnDataRowsAsync()
var fileReader = new FileReader(fileName,
rowFactory, tokenizer, fileMetaDataMock.Object,
new FileReaderConfiguration());
Assert.NotEmpty(await fileReader.GetDataRowsAsync().ToArrayAsync());
Assert.NotEmpty(await fileReader
.GetDataRowsAsync(TestContext.Current.CancellationToken)
.ToArrayAsync(TestContext.Current.CancellationToken));
}

[Fact]
Expand All @@ -104,7 +109,9 @@ public async Task ShouldThrowOnCancellation()
var ct = new CancellationToken(true);
await Assert.ThrowsAsync<OperationCanceledException>(async () =>
{
await fileReader.GetDataRowsAsync(ct).ToArrayAsync();
await fileReader
.GetDataRowsAsync(ct)
.ToArrayAsync(TestContext.Current.CancellationToken);
});
}

Expand All @@ -126,8 +133,12 @@ public async Task ShouldSeekToBeginningForHeaderRowsAsync()
var fileReader = new FileReader(fileName,
rowFactory, tokenizer, fileMetaDataMock.Object,
new FileReaderConfiguration());
Assert.NotEmpty(await fileReader.GetDataRowsAsync().ToArrayAsync());
Assert.NotEmpty(await fileReader.GetHeaderRowsAsync().ToArrayAsync());
Assert.NotEmpty(await fileReader
.GetDataRowsAsync(TestContext.Current.CancellationToken)
.ToArrayAsync(TestContext.Current.CancellationToken));
Assert.NotEmpty(await fileReader
.GetHeaderRowsAsync(TestContext.Current.CancellationToken)
.ToArrayAsync(TestContext.Current.CancellationToken));
}
}
}
40 changes: 16 additions & 24 deletions src/Tests/StreamEnumeratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class StreamEnumeratorTests
private readonly IRowFactory rowFactory;
private readonly ITokenizer tokenizer;

Mock<IFileMetaData> fileMetaDataMock = new Mock<IFileMetaData>();
Mock<IFileAttributes> fileAttributesMock = new Mock<IFileAttributes>();
readonly Mock<IFileMetaData> fileMetaDataMock = new();
readonly Mock<IFileAttributes> fileAttributesMock = new();

public StreamEnumeratorTests()
{
Expand All @@ -38,36 +38,28 @@ public StreamEnumeratorTests()
tokenizer = new Tokenizer(fileMetaDataMock.Object);
}

ICollection<FieldType> fieldTypes = new FieldType[]
{


};

[Fact]
public void ShouldEnumerateFile()
{
using (Stream stream = new FileStream(fileName, FileMode.Open))
{
var streamEnumerator = new DwC_A.StreamReader(
rowFactory,
tokenizer,
fileMetaDataMock.Object);
Assert.NotEmpty(streamEnumerator.ReadRows(stream).ToArray());
}
using Stream stream = new FileStream(fileName, FileMode.Open);
var streamEnumerator = new DwC_A.StreamReader(
rowFactory,
tokenizer,
fileMetaDataMock.Object);
Assert.NotEmpty(streamEnumerator.ReadRows(stream).ToArray());
}

[Fact]
public async Task ShouldEnumerateFileAsync()
{
using (Stream stream = new FileStream(fileName, FileMode.Open))
{
var streamEnumerator = new DwC_A.StreamReader(
rowFactory,
tokenizer,
fileMetaDataMock.Object);
Assert.NotEmpty(await streamEnumerator.ReadRowsAsync(stream).ToArrayAsync());
}
using Stream stream = new FileStream(fileName, FileMode.Open);
var streamEnumerator = new DwC_A.StreamReader(
rowFactory,
tokenizer,
fileMetaDataMock.Object);
Assert.NotEmpty(await streamEnumerator
.ReadRowsAsync(stream, TestContext.Current.CancellationToken)
.ToArrayAsync(TestContext.Current.CancellationToken));
}

}
Expand Down
3 changes: 2 additions & 1 deletion src/Tests/StreamReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Moq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Tests
Expand Down Expand Up @@ -36,7 +37,7 @@ public void ShouldReadStreamWithQuotes()
}

[Fact]
public async void ShouldReadStreamWithQuotesAsync()
public async Task ShouldReadStreamWithQuotesAsync()
{
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(data)))
{
Expand Down
Loading

0 comments on commit 5d8865b

Please sign in to comment.