Skip to content

Commit 1fed628

Browse files
committed
Update Solution to .NET 6
1 parent a6ab8e2 commit 1fed628

16 files changed

+64
-90
lines changed

.github/workflows/main.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: CI
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77
tags:
88
- 'v*.*.*'
99

@@ -13,11 +13,11 @@ jobs:
1313
runs-on: ubuntu-latest
1414

1515
steps:
16-
- uses: actions/checkout@v1
16+
- uses: actions/checkout@main
1717
- name: Setup .NET Core
18-
uses: actions/setup-dotnet@v1
18+
uses: actions/setup-dotnet@v2
1919
with:
20-
dotnet-version: 3.1.100
20+
dotnet-version: '6.0.x'
2121
- name: Generate coverage report
2222
run: |
2323
printenv

uiowa.DelimitedDataHelper.Tests/CsvFileTests.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.IO;
3-
using System.Linq;
41
using Microsoft.VisualStudio.TestTools.UnitTesting;
5-
using uiowa.DelimitedDataHelper.Csv;
62
using uiowa.DelimitedDataHelper.Tests.TestModels;
73

84
namespace uiowa.DelimitedDataHelper.Tests
@@ -46,10 +42,8 @@ public void ShouldReadAndWriteCsvCorrectly()
4642
[TestMethod]
4743
public void ShouldThrowExceptionWhenCsvHasExtraColumn()
4844
{
49-
Action action = () => _ = new CsvFile(_input2)
50-
.SkipNRows(1)
51-
.GetData<Contact>().ToList();
52-
var e = Assert.ThrowsException<IndexOutOfRangeException>(action);
45+
var e = Assert.ThrowsException<IndexOutOfRangeException>(() =>
46+
_ = new CsvFile(_input2).SkipNRows(1).GetData<Contact>().ToList());
5347
Assert.AreEqual("Index was outside the bounds of the array. DataRow: \"Johnson\",\"ABC\",\"johnson@abc.com\"", e.Message);
5448
}
5549

@@ -58,7 +52,7 @@ public void ShouldConvertToString()
5852
{
5953
var dataString = new CsvFile(_input)
6054
.SkipNRows(1)
61-
.GetData<Contact>().AsString();
55+
.GetData<Contact>().AsCsvString();
6256
var result1 = File.ReadAllLines(_input).ToArray();
6357
var result2 = dataString.Split(Environment.NewLine).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
6458
CollectionAssert.AreEqual(result2, result1);

uiowa.DelimitedDataHelper.Tests/PipeDelimitedFileTests.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.IO;
3-
using System.Linq;
4-
using Microsoft.VisualStudio.TestTools.UnitTesting;
5-
using uiowa.DelimitedDataHelper.Pipe;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
62
using uiowa.DelimitedDataHelper.Tests.TestModels;
73

84
namespace uiowa.DelimitedDataHelper.Tests
@@ -37,10 +33,8 @@ public void ShouldReadAndWritePipeDelimitedFileCorrectly()
3733
[TestMethod]
3834
public void ShouldThrowExceptionWhenWrongColumnNumber()
3935
{
40-
Action action = () => _ = new PipeDelimitedFile(_input2)
41-
.SkipNRows(1)
42-
.GetData<Contact>().ToList();
43-
var e = Assert.ThrowsException<IndexOutOfRangeException>(action);
36+
var e = Assert.ThrowsException<IndexOutOfRangeException>(() =>
37+
_ = new PipeDelimitedFile(_input2).SkipNRows(1).GetData<Contact>().ToList());
4438
Assert.AreEqual("Index was outside the bounds of the array. DataRow: Johnson|ABC|johnson@abc.com", e.Message);
4539
}
4640

@@ -49,7 +43,7 @@ public void ShouldConvertToString()
4943
{
5044
var dataString = new PipeDelimitedFile(_input)
5145
.SkipNRows(1)
52-
.GetData<Contact>().AsPipedString();
46+
.GetData<Contact>().AsPipDelimitedString();
5347
var result1 = File.ReadAllLines(_input).ToArray();
5448
var result2 = dataString.Split(Environment.NewLine).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
5549
CollectionAssert.AreEqual(result2, result1);

uiowa.DelimitedDataHelper.Tests/TabDelimitedFileTests.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
using System;
2-
using System.IO;
3-
using System.Linq;
4-
using Microsoft.VisualStudio.TestTools.UnitTesting;
5-
using uiowa.DelimitedDataHelper.Tab;
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
62
using uiowa.DelimitedDataHelper.Tests.TestModels;
73

84
namespace uiowa.DelimitedDataHelper.Tests
@@ -38,7 +34,7 @@ public void ShouldConvertToString()
3834
{
3935
var dataString = new TabDelimitedFile(_input)
4036
.SkipNRows(1)
41-
.GetData<Contact>().AsTabedString();
37+
.GetData<Contact>().AsTabDelimitedString();
4238
var result1 = File.ReadAllLines(_input).ToArray();
4339
var result2 = dataString.Split(Environment.NewLine).Where(x => !string.IsNullOrWhiteSpace(x)).ToArray();
4440
CollectionAssert.AreEqual(result2, result1);

uiowa.DelimitedDataHelper.Tests/TestModels/Contact.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
{
33
public class Contact
44
{
5-
public string Name { get; set; }
6-
public string Company { get; set; }
7-
public string Email { get; set; }
8-
public string Password { get; set; }
5+
public string Name { get; set; } = string.Empty;
6+
public string Company { get; set; } = string.Empty;
7+
public string Email { get; set; } = string.Empty;
8+
public string Password { get; set; } = string.Empty;
99
}
1010
}

uiowa.DelimitedDataHelper.Tests/uiowa.DelimitedDataHelper.Tests.csproj

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55

66
<IsPackable>false</IsPackable>
7+
8+
<Nullable>enable</Nullable>
9+
10+
<ImplicitUsings>enable</ImplicitUsings>
711
</PropertyGroup>
812

913
<ItemGroup>

uiowa.DelimitedDataHelper.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
3-
# Visual Studio Version 16
4-
VisualStudioVersion = 16.0.29318.209
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32825.248
55
MinimumVisualStudioVersion = 15.0.26124.0
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "uiowa.DelimitedDataHelper", "uiowa.DelimitedDataHelper\uiowa.DelimitedDataHelper.csproj", "{657BC75F-071A-423F-BF39-4678DE65604C}"
77
EndProject

uiowa.DelimitedDataHelper/Csv/CsvFile.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
4-
namespace uiowa.DelimitedDataHelper.Csv
1+
namespace uiowa.DelimitedDataHelper
52
{
63
/// <inheritdoc />
74
public class CsvFile : DelimitedDataFile
@@ -30,9 +27,9 @@ public CsvFile(string fileName) : base(fileName, ",")
3027
/// <typeparam name="T"></typeparam>
3128
/// <param name="config">Optional. By default, reader will trim starting/ending white spaces of each entry and reader will parse "" quoted entries.</param>
3229
/// <returns></returns>
33-
public IEnumerable<T> GetData<T>(CsvReaderConfig config = null) where T : new()
30+
public IEnumerable<T> GetData<T>(CsvReaderConfig? config = null) where T : new()
3431
{
35-
if (config == null) config = new CsvReaderConfig();
32+
config ??= new CsvReaderConfig();
3633
return config.IsQuoted ? ParseQuotedCsvData<T>(config) : base.GetData<T>(config);
3734
}
3835

@@ -43,7 +40,7 @@ public CsvFile(string fileName) : base(fileName, ",")
4340
{
4441
var result = new T();
4542
var items = x.Split(new[] { QuotedDelimiter }, StringSplitOptions.None);
46-
items[0] = items[0].Substring(1);
43+
items[0] = items[0][1..];
4744
try
4845
{
4946
items[objProperties.Length - 1] = TrimLastCharacter(items[objProperties.Length - 1]);
@@ -65,7 +62,7 @@ public CsvFile(string fileName) : base(fileName, ",")
6562

6663
private static string TrimLastCharacter(string s)
6764
{
68-
return s.Substring(0, s.Length - 1);
65+
return s[..^1];
6966
}
7067
}
7168
}

uiowa.DelimitedDataHelper/Csv/CsvFileIOConfigs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace uiowa.DelimitedDataHelper.Csv
1+
namespace uiowa.DelimitedDataHelper
22
{
33
/// <inheritdoc />
44
/// <summary>

uiowa.DelimitedDataHelper/Csv/CsvFileWriter.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System.Collections.Generic;
2-
3-
namespace uiowa.DelimitedDataHelper.Csv
1+
namespace uiowa.DelimitedDataHelper
42
{
53
internal class CsvFileWriter : DelimitedFileWriter
64
{
@@ -9,9 +7,9 @@ public CsvFileWriter() : base(",")
97

108
}
119

12-
protected override string Escape(object o)
10+
protected override string Escape(object? o)
1311
{
14-
return o == null ? "" : $"\"{o.ToString().Replace("\"", "\"\"")}\"";
12+
return o == null ? "" : $"\"{o.ToString()?.Replace("\"", "\"\"")}\"";
1513
}
1614
}
1715

@@ -29,7 +27,7 @@ public static class CsvFileExtensions
2927
/// <param name="data"></param>
3028
/// <param name="fileName">Full path for output file.</param>
3129
/// <param name="config">Optional. By default, null, which means will write header and will write "" quoted entries.</param>
32-
public static void WriteToCsvFile<T>(this IEnumerable<T> data, string fileName, CsvWriterConfig config = null)
30+
public static void WriteToCsvFile<T>(this IEnumerable<T> data, string fileName, CsvWriterConfig? config = null)
3331
{
3432
if (config == null) config = new CsvWriterConfig();
3533
if (config.IsQuoted)
@@ -47,9 +45,9 @@ public static void WriteToCsvFile<T>(this IEnumerable<T> data, string fileName,
4745
/// <param name="config"></param>
4846
/// <typeparam name="T"></typeparam>
4947
/// <returns></returns>
50-
public static string AsString<T>(this IEnumerable<T> data, CsvWriterConfig config = null)
48+
public static string AsCsvString<T>(this IEnumerable<T> data, CsvWriterConfig? config = null)
5149
{
52-
if (config == null) config = new CsvWriterConfig();
50+
config ??= new CsvWriterConfig();
5351
if (config.IsQuoted)
5452
{
5553
return new CsvFileWriter().ConvertToString(data, config);

0 commit comments

Comments
 (0)