-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fed628
commit f6e6bfc
Showing
16 changed files
with
572 additions
and
611 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
95
uiowa.DelimitedDataHelper.Tests/PipeDelimitedFileTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.