Skip to content

Commit

Permalink
update solution to .NET8
Browse files Browse the repository at this point in the history
  • Loading branch information
changhuixu committed Sep 1, 2024
1 parent 1fed628 commit f6e6bfc
Show file tree
Hide file tree
Showing 16 changed files with 572 additions and 611 deletions.
63 changes: 31 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,38 @@ on:
- 'v*.*.*'

jobs:

build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@main
- name: Setup .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.0.x'
- name: Generate coverage report
run: |
printenv
cd ./uiowa.DelimitedDataHelper.Tests/
dotnet test /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov
- name: Publish coverage report to coveralls.io
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./uiowa.DelimitedDataHelper.Tests/TestResults/coverage.info
- name: Build and deploy NuGet package
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
echo $GITHUB_REF
RELEASE_VERSION=${GITHUB_REF:10}
echo $RELEASE_VERSION
if [[ $RELEASE_VERSION == v* ]]; then
echo "Publishing NuGet package version:" $RELEASE_VERSION
cd ./uiowa.DelimitedDataHelper/
dotnet publish -c=Release /p:Version="${RELEASE_VERSION:1}"
ls ./bin/Release
dotnet nuget push ./bin/Release/*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json
else
echo "No valid version tag was found. Done for today."
fi
- uses: actions/checkout@main
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- name: Generate coverage report
run: |
printenv
cd ./uiowa.DelimitedDataHelper.Tests/
dotnet test /p:CollectCoverage=true /p:CoverletOutput=TestResults/ /p:CoverletOutputFormat=lcov
- name: Publish coverage report to coveralls.io
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./uiowa.DelimitedDataHelper.Tests/TestResults/coverage.info
- name: Build and deploy NuGet package
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
run: |
echo $GITHUB_REF
RELEASE_VERSION=${GITHUB_REF:10}
echo $RELEASE_VERSION
if [[ $RELEASE_VERSION == v* ]]; then
echo "Publishing NuGet package version:" $RELEASE_VERSION
cd ./uiowa.DelimitedDataHelper/
dotnet publish -c=Release /p:Version="${RELEASE_VERSION:1}"
ls ./bin/Release
dotnet nuget push ./bin/Release/*.nupkg -k $NUGET_API_KEY -s https://api.nuget.org/v3/index.json
else
echo "No valid version tag was found. Done for today."
fi
111 changes: 55 additions & 56 deletions uiowa.DelimitedDataHelper.Tests/CsvFileTests.cs
Original file line number Diff line number Diff line change
@@ -1,68 +1,67 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using uiowa.DelimitedDataHelper.Tests.TestModels;

namespace uiowa.DelimitedDataHelper.Tests
namespace uiowa.DelimitedDataHelper.Tests;

[TestClass]
public class CsvFileTests
{
[TestClass]
public class CsvFileTests
{
private static readonly string ProjDir = AppDomain.CurrentDomain.BaseDirectory;
private readonly string _input = Path.Combine(ProjDir, @"Data", @"Contacts.csv");
private readonly string _input2 = Path.Combine(ProjDir, @"Data", @"Contacts2.csv");
private readonly string _output = Path.Combine(ProjDir, @"Data", @"output1.csv");
private static readonly string ProjDir = AppDomain.CurrentDomain.BaseDirectory;
private readonly string _input = Path.Combine(ProjDir, "Data", "Contacts.csv");
private readonly string _input2 = Path.Combine(ProjDir, "Data", "Contacts2.csv");
private readonly string _output = Path.Combine(ProjDir, "Data", "output1.csv");

[TestInitialize]
public void Initialize()
{
Console.WriteLine("Delete potential output file");
File.Delete(_output);
}
[TestInitialize]
public void Initialize()
{
Console.WriteLine("Delete potential output file");
File.Delete(_output);
}

[TestMethod]
public void ShouldReadAndWriteCsvCorrectly()
{
var data = new CsvFile(_input)
.SkipNRows(1)
.GetData<Contact>();
data.WriteToCsvFile(_output);
var result1 = File.ReadAllLines(_input);
var result2 = File.ReadAllLines(_output);
CollectionAssert.AreEqual(result2, result1);
[TestMethod]
public void ShouldReadAndWriteCsvCorrectly()
{
var data = new CsvFile(_input)
.SkipNRows(1)
.GetData<Contact>();
data.WriteToCsvFile(_output);
var result1 = File.ReadAllLines(_input);
var result2 = File.ReadAllLines(_output);
CollectionAssert.AreEqual(result2, result1);


var data2 = new CsvFile(_input)
.SkipNRows(1)
.GetData<Contact>();
data2.WriteToCsvFile(_output, new CsvWriterConfig(writeHeader: false));
var result3 = File.ReadAllLines(_input).Skip(1).ToArray();
var result4 = File.ReadAllLines(_output);
CollectionAssert.AreEqual(result3, result4);
}
var data2 = new CsvFile(_input)
.SkipNRows(1)
.GetData<Contact>();
data2.WriteToCsvFile(_output, new CsvWriterConfig(writeHeader: false));
var result3 = File.ReadAllLines(_input).Skip(1).ToArray();
var result4 = File.ReadAllLines(_output);
CollectionAssert.AreEqual(result3, result4);
}

[TestMethod]
public void ShouldThrowExceptionWhenCsvHasExtraColumn()
{
var e = Assert.ThrowsException<IndexOutOfRangeException>(() =>
_ = new CsvFile(_input2).SkipNRows(1).GetData<Contact>().ToList());
Assert.AreEqual("Index was outside the bounds of the array. DataRow: \"Johnson\",\"ABC\",\"johnson@abc.com\"", e.Message);
}
[TestMethod]
public void ShouldThrowExceptionWhenCsvHasExtraColumn()
{
var e = Assert.ThrowsException<IndexOutOfRangeException>(() =>
_ = new CsvFile(_input2).SkipNRows(1).GetData<Contact>().ToList());
Assert.AreEqual("Index was outside the bounds of the array. DataRow: \"Johnson\",\"ABC\",\"johnson@abc.com\"", e.Message);
}

[TestMethod]
public void ShouldConvertToString()
{
var dataString = new CsvFile(_input)
.SkipNRows(1)
.GetData<Contact>().AsCsvString();
var result1 = File.ReadAllLines(_input).ToArray();
var result2 = dataString.Split(Environment.NewLine).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
CollectionAssert.AreEqual(result2, result1);
}
[TestMethod]
public void ShouldConvertToString()
{
var dataString = new CsvFile(_input)
.SkipNRows(1)
.GetData<Contact>().AsCsvString();
var result1 = File.ReadAllLines(_input).ToArray();
var result2 = dataString.Split(Environment.NewLine).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
CollectionAssert.AreEqual(result2, result1);
}

[TestCleanup]
public void Cleanup()
{
File.Delete(_output);
Console.WriteLine("Output file deleted");
}
[TestCleanup]
public void Cleanup()
{
File.Delete(_output);
Console.WriteLine("Output file deleted");
}
}
}
95 changes: 47 additions & 48 deletions uiowa.DelimitedDataHelper.Tests/PipeDelimitedFileTests.cs
Original file line number Diff line number Diff line change
@@ -1,58 +1,57 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using uiowa.DelimitedDataHelper.Tests.TestModels;

namespace uiowa.DelimitedDataHelper.Tests
namespace uiowa.DelimitedDataHelper.Tests;

[TestClass]
public class PipeDelimitedFileTests
{
[TestClass]
public class PipeDelimitedFileTests
{
private static readonly string ProjDir = AppDomain.CurrentDomain.BaseDirectory;
private readonly string _input = Path.Combine(ProjDir, @"Data", @"PipeDelimitedFile.txt");
private readonly string _input2 = Path.Combine(ProjDir, @"Data", @"PipeDelimitedFile2.txt");
private readonly string _output = Path.Combine(ProjDir, @"Data", @"output2.txt");
private static readonly string ProjDir = AppDomain.CurrentDomain.BaseDirectory;
private readonly string _input = Path.Combine(ProjDir, "Data", "PipeDelimitedFile.txt");
private readonly string _input2 = Path.Combine(ProjDir, "Data", "PipeDelimitedFile2.txt");
private readonly string _output = Path.Combine(ProjDir, "Data", "output2.txt");

[TestInitialize]
public void Initialize()
{
Console.WriteLine("Delete potential output file");
File.Delete(_output);
}
[TestInitialize]
public void Initialize()
{
Console.WriteLine("Delete potential output file");
File.Delete(_output);
}

[TestMethod]
public void ShouldReadAndWritePipeDelimitedFileCorrectly()
{
var data = new PipeDelimitedFile(_input)
.SkipNRows(1)
.GetData<Contact>();
data.WriteToPipeDelimitedFile(_output);
var result1 = File.ReadAllLines(_input);
var result2 = File.ReadAllLines(_output);
CollectionAssert.AreEqual(result2, result1);
}
[TestMethod]
public void ShouldReadAndWritePipeDelimitedFileCorrectly()
{
var data = new PipeDelimitedFile(_input)
.SkipNRows(1)
.GetData<Contact>();
data.WriteToPipeDelimitedFile(_output);
var result1 = File.ReadAllLines(_input);
var result2 = File.ReadAllLines(_output);
CollectionAssert.AreEqual(result2, result1);
}

[TestMethod]
public void ShouldThrowExceptionWhenWrongColumnNumber()
{
var e = Assert.ThrowsException<IndexOutOfRangeException>(() =>
_ = new PipeDelimitedFile(_input2).SkipNRows(1).GetData<Contact>().ToList());
Assert.AreEqual("Index was outside the bounds of the array. DataRow: Johnson|ABC|johnson@abc.com", e.Message);
}
[TestMethod]
public void ShouldThrowExceptionWhenWrongColumnNumber()
{
var e = Assert.ThrowsException<IndexOutOfRangeException>(() =>
_ = new PipeDelimitedFile(_input2).SkipNRows(1).GetData<Contact>().ToList());
Assert.AreEqual("Index was outside the bounds of the array. DataRow: Johnson|ABC|johnson@abc.com", e.Message);
}

[TestMethod]
public void ShouldConvertToString()
{
var dataString = new PipeDelimitedFile(_input)
.SkipNRows(1)
.GetData<Contact>().AsPipDelimitedString();
var result1 = File.ReadAllLines(_input).ToArray();
var result2 = dataString.Split(Environment.NewLine).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
CollectionAssert.AreEqual(result2, result1);
}
[TestMethod]
public void ShouldConvertToString()
{
var dataString = new PipeDelimitedFile(_input)
.SkipNRows(1)
.GetData<Contact>().AsPipDelimitedString();
var result1 = File.ReadAllLines(_input).ToArray();
var result2 = dataString.Split(Environment.NewLine).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
CollectionAssert.AreEqual(result2, result1);
}

[TestCleanup]
public void Cleanup()
{
File.Delete(_output);
}
[TestCleanup]
public void Cleanup()
{
File.Delete(_output);
}
}
}
79 changes: 39 additions & 40 deletions uiowa.DelimitedDataHelper.Tests/TabDelimitedFileTests.cs
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using uiowa.DelimitedDataHelper.Tests.TestModels;

namespace uiowa.DelimitedDataHelper.Tests
namespace uiowa.DelimitedDataHelper.Tests;

[TestClass]
public class TabDelimitedFileTests
{
[TestClass]
public class TabDelimitedFileTests
{
private static readonly string ProjDir = AppDomain.CurrentDomain.BaseDirectory;
private readonly string _input = Path.Combine(ProjDir, @"Data", @"TabDelimitedFile.txt");
private readonly string _output = Path.Combine(ProjDir, @"Data", @"output3.txt");
private static readonly string ProjDir = AppDomain.CurrentDomain.BaseDirectory;
private readonly string _input = Path.Combine(ProjDir, "Data", "TabDelimitedFile.txt");
private readonly string _output = Path.Combine(ProjDir, "Data", "output3.txt");

[TestInitialize]
public void Initialize()
{
Console.WriteLine("Delete potential output file");
File.Delete(_output);
}
[TestInitialize]
public void Initialize()
{
Console.WriteLine("Delete potential output file");
File.Delete(_output);
}

[TestMethod]
public void ShouldReadAndWriteTabDelimitedFileCorrectly()
{
var data = new TabDelimitedFile(_input)
.SkipNRows(1)
.GetData<Contact>();
data.WriteToTabDelimitedFile(_output);
var result1 = File.ReadAllLines(_input);
var result2 = File.ReadAllLines(_output);
CollectionAssert.AreEqual(result2, result1);
}
[TestMethod]
public void ShouldReadAndWriteTabDelimitedFileCorrectly()
{
var data = new TabDelimitedFile(_input)
.SkipNRows(1)
.GetData<Contact>();
data.WriteToTabDelimitedFile(_output);
var result1 = File.ReadAllLines(_input);
var result2 = File.ReadAllLines(_output);
CollectionAssert.AreEqual(result2, result1);
}

[TestMethod]
public void ShouldConvertToString()
{
var dataString = new TabDelimitedFile(_input)
.SkipNRows(1)
.GetData<Contact>().AsTabDelimitedString();
var result1 = File.ReadAllLines(_input).ToArray();
var result2 = dataString.Split(Environment.NewLine).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
CollectionAssert.AreEqual(result2, result1);
}
[TestMethod]
public void ShouldConvertToString()
{
var dataString = new TabDelimitedFile(_input)
.SkipNRows(1)
.GetData<Contact>().AsTabDelimitedString();
var result1 = File.ReadAllLines(_input).ToArray();
var result2 = dataString.Split(Environment.NewLine).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
CollectionAssert.AreEqual(result2, result1);
}

[TestCleanup]
public void Cleanup()
{
File.Delete(_output);
}
[TestCleanup]
public void Cleanup()
{
File.Delete(_output);
}
}
}
Loading

0 comments on commit f6e6bfc

Please sign in to comment.