diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 412eeda..0000000 --- a/.gitattributes +++ /dev/null @@ -1,22 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto - -# Custom for Visual Studio -*.cs diff=csharp -*.sln merge=union -*.csproj merge=union -*.vbproj merge=union -*.fsproj merge=union -*.dbproj merge=union - -# Standard to msysgit -*.doc diff=astextplain -*.DOC diff=astextplain -*.docx diff=astextplain -*.DOCX diff=astextplain -*.dot diff=astextplain -*.DOT diff=astextplain -*.pdf diff=astextplain -*.PDF diff=astextplain -*.rtf diff=astextplain -*.RTF diff=astextplain diff --git a/.gitignore b/.gitignore index b9d6bd9..b42864b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,61 +1,62 @@ -################# -## Eclipse -################# - -*.pydevproject -.project -.metadata -bin/ -tmp/ -*.tmp -*.bak -*.swp -*~.nib -local.properties -.classpath -.settings/ -.loadpath - -# External tool builders -.externalToolBuilders/ - -# Locally stored "Eclipse launch configurations" -*.launch - -# CDT-specific -.cproject - -# PDT-specific -.buildpath - - -################# -## Visual Studio -################# +## Custom stuff ... +**/appsettings.*.json ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore # User-specific files *.suo *.user +*.userosscache *.sln.docstates +*.vcxproj.filters -# Build results +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs +# Build results [Dd]ebug/ +[Dd]ebugPublic/ [Rr]elease/ +[Rr]eleases/ x64/ -build/ +x86/ +bld/ [Bb]in/ [Oo]bj/ +[Ll]og/ +binaries/ + +# Visual Studio 2015 cache/options directory +.vs/ + +**/wwwroot/build/ +**/content/build/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ +# **/Properties/launchSettings.json + *_i.c *_p.c +*_i.h *.ilk *.meta *.obj @@ -75,21 +76,31 @@ build/ *.vssscc .builds *.pidb -*.log +*.svclog *.scc +# Chutzpah Test files +_Chutzpah* + # Visual C++ cache files ipch/ *.aps *.ncb +*.opendb *.opensdf *.sdf *.cachefile +*.VC.db +*.VC.VC.opendb # Visual Studio profiler *.psess *.vsp *.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ # Guidance Automation Toolkit *.gpState @@ -97,6 +108,10 @@ ipch/ # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode # TeamCity is a build add-in _TeamCity* @@ -104,9 +119,21 @@ _TeamCity* # DotCover is a Code Coverage Tool *.dotCover +# Visual Studio code coverage results +*.coverage +*.coveragexml + # NCrunch -*.ncrunch* +_NCrunch_* .*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ # Installshield output folder [Ee]xpress/ @@ -125,91 +152,129 @@ DocProject/Help/html publish/ # Publish Web Output -*.Publish.xml +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted *.pubxml - -# NuGet Packages Directory -## TODO: If you have NuGet Package Restore enabled, uncomment the next line -#packages/ - -# Windows Azure Build Output -csx +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ *.build.csdef -# Windows Store app package directory +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ # Others -sql/ -*.Cache ClientBin/ -[Ss]tyle[Cc]op.* ~$* *~ *.dbmdl -*.[Pp]ublish.xml -*.pfx +*.dbproj.schemaview +*.jfm +# *.pfx *.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ # RIA/Silverlight projects Generated_Code/ -# Backup & report files from converting an old project file to a newer -# Visual Studio version. Backup files are not needed, because we have git ;-) +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm # SQL Server files -App_Data/*.mdf -App_Data/*.ldf +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings -############# -## Windows detritus -############# +# Microsoft Fakes +FakesAssemblies/ -# Windows image file caches -Thumbs.db -ehthumbs.db +# GhostDoc plugin setting file +*.GhostDoc.xml -# Folder config file -Desktop.ini +# Node.js Tools for Visual Studio +.ntvs_analysis.dat -# Recycle Bin used on file shares -$RECYCLE.BIN/ +# Visual Studio 6 build log +*.plg -# Mac crap -.DS_Store +# Visual Studio 6 workspace options file +*.opt +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw -############# -## Python -############# +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions -*.py[co] +# Paket dependency manager +.paket/paket.exe +paket-files/ -# Packages -*.egg -*.egg-info -dist/ -build/ -eggs/ -parts/ -var/ -sdist/ -develop-eggs/ -.installed.cfg +# FAKE - F# Make +.fake/ -# Installer logs -pip-log.txt +# JetBrains Rider +.idea/ +*.sln.iml -# Unit test / coverage reports -.coverage -.tox +# CodeRush +.cr/ -#Translations -*.mo +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc -#Mr Developer -.mr.developer.cfg +# Cake - Uncomment if you are using it +tools/ diff --git a/.nuke/parameters.json b/.nuke/parameters.json new file mode 100644 index 0000000..281cf9e --- /dev/null +++ b/.nuke/parameters.json @@ -0,0 +1,4 @@ +{ + "$schema": "./build.schema.json", + "Solution": "Source/LINQtoCSV.sln" +} \ No newline at end of file diff --git a/Build/.editorconfig b/Build/.editorconfig new file mode 100644 index 0000000..31e43dc --- /dev/null +++ b/Build/.editorconfig @@ -0,0 +1,11 @@ +[*.cs] +dotnet_style_qualification_for_field = false:warning +dotnet_style_qualification_for_property = false:warning +dotnet_style_qualification_for_method = false:warning +dotnet_style_qualification_for_event = false:warning +dotnet_style_require_accessibility_modifiers = never:warning + +csharp_style_expression_bodied_methods = true:silent +csharp_style_expression_bodied_properties = true:warning +csharp_style_expression_bodied_indexers = true:warning +csharp_style_expression_bodied_accessors = true:warning diff --git a/Build/Build.cs b/Build/Build.cs new file mode 100644 index 0000000..be8c162 --- /dev/null +++ b/Build/Build.cs @@ -0,0 +1,18 @@ +using GlobalRoam.Build.Nuke; +using Nuke.Common; +using Nuke.Common.Execution; +using Nuke.Common.Tools.DotNet; +using Nuke.Common.Tools.GitVersion; +using System; +using System.Linq; +using static Nuke.Common.Tools.DotNet.DotNetTasks; + +[UnsetVisualStudioEnvironmentVariables] +class Build : NugetPackageBuild +{ + protected override bool IncludeSourceInPack => false; + protected override bool IncludeSymbolsInPack => false; + + public static int Main() => Execute(x => x.Test); + +} diff --git a/Build/_build.csproj b/Build/_build.csproj new file mode 100644 index 0000000..ed1c6a0 --- /dev/null +++ b/Build/_build.csproj @@ -0,0 +1,18 @@ + + + + net8.0 + Exe + + CS0649;CS0169 + .. + .. + + + + + + + + + diff --git a/GitVersion.yml b/GitVersion.yml new file mode 100644 index 0000000..c311488 --- /dev/null +++ b/GitVersion.yml @@ -0,0 +1 @@ +mode: Mainline \ No newline at end of file diff --git a/LINQtoCSV.Tests/CsvContextWriteTests.cs b/LINQtoCSV.Tests/CsvContextWriteTests.cs deleted file mode 100644 index aebc0a1..0000000 --- a/LINQtoCSV.Tests/CsvContextWriteTests.cs +++ /dev/null @@ -1,45 +0,0 @@ -using LINQtoCSV; -using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; -using System.IO; -using System.Collections.Generic; -using System.Text; - -namespace LINQtoCSV.Tests -{ - [TestClass()] - public class CsvContextWriteTests : Test - { - [TestMethod()] - public void GoodFileCommaDelimitedNamesInFirstLineNLnl() - { - // Arrange - - List dataRows_Test = new List(); - dataRows_Test.Add(new ProductData { retailPrice = 4.59M, name = "Wooden toy", startDate = new DateTime(2008, 2, 1), nbrAvailable = 67 }); - dataRows_Test.Add(new ProductData { onsale = true, weight = 4.03, shopsAvailable = "Ashfield", description = "" }); - dataRows_Test.Add(new ProductData { name = "Metal box", launchTime = new DateTime(2009, 11, 5, 4, 50, 0), description = "Great\nproduct" }); - - CsvFileDescription fileDescription_namesNl2 = new CsvFileDescription - { - SeparatorChar = ',', - FirstLineHasColumnNames = true, - EnforceCsvColumnAttribute = false, - TextEncoding = Encoding.Unicode, - FileCultureName = "nl-Nl" // default is the current culture - }; - - string expected = -@"name,startDate,launchTime,weight,shopsAvailable,code,price,onsale,description,nbrAvailable,unusedField -Wooden toy,1-2-2008,01 jan 00:00:00,""000,000"",,0,""€ 4,59"",False,,67, -,1-1-0001,01 jan 00:00:00,""004,030"",Ashfield,0,""€ 0,00"",True,"""",0, -Metal box,1-1-0001,05 nov 04:50:00,""000,000"",,0,""€ 0,00"",False,""Great -product"",0, -"; - - // Act and Assert - - AssertWrite(dataRows_Test, fileDescription_namesNl2, expected); - } - } -} diff --git a/LINQtoCSV.Tests/LINQtoCSV.Tests.csproj b/LINQtoCSV.Tests/LINQtoCSV.Tests.csproj deleted file mode 100644 index 38d8f6b..0000000 --- a/LINQtoCSV.Tests/LINQtoCSV.Tests.csproj +++ /dev/null @@ -1,79 +0,0 @@ - - - - Debug - AnyCPU - - - 2.0 - {04EE17CD-E7B3-4D58-BF84-E553F5332A14} - Library - Properties - LINQtoCSV.Tests - LINQtoCSV.Tests - v4.0 - 512 - {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - - - - - - 3.5 - - - - - - - - - False - - - - - - - - - - - - - - - - - - - {07058BF9-6F86-40FF-AE33-2A4F89B5758A} - LINQtoCSV - - - - - \ No newline at end of file diff --git a/LINQtoCSV.Tests/Properties/AssemblyInfo.cs b/LINQtoCSV.Tests/Properties/AssemblyInfo.cs deleted file mode 100644 index e84ce13..0000000 --- a/LINQtoCSV.Tests/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("LINQtoCSV.Tests")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Microsoft")] -[assembly: AssemblyProduct("LINQtoCSV.Tests")] -[assembly: AssemblyCopyright("Copyright © Microsoft 2013")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("45424f0f-359a-4e5c-b6d4-53f66dada32f")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/LINQtoCSV.vsmdi b/LINQtoCSV.vsmdi deleted file mode 100644 index 2eec931..0000000 --- a/LINQtoCSV.vsmdi +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/LINQtoCSV/LINQtoCSV.csproj b/LINQtoCSV/LINQtoCSV.csproj deleted file mode 100644 index 17323b9..0000000 --- a/LINQtoCSV/LINQtoCSV.csproj +++ /dev/null @@ -1,114 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {07058BF9-6F86-40FF-AE33-2A4F89B5758A} - Library - Properties - LINQtoCSV - LINQtoCSV - v3.5 - 512 - - - - - 3.5 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - - - - - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - AllRules.ruleset - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - AllRules.ruleset - - - - - 3.5 - - - 3.5 - - - 3.5 - - - - - - - - - - - - - - - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - \ No newline at end of file diff --git a/LINQtoCSV/LINQtoCSV.nuspec b/LINQtoCSV/LINQtoCSV.nuspec deleted file mode 100644 index 0d70c1a..0000000 --- a/LINQtoCSV/LINQtoCSV.nuspec +++ /dev/null @@ -1,21 +0,0 @@ - - - - $id$ - $version$ - $title$ - $author$ - $author$ - http://www.codeproject.com/Articles/25133/LINQ-to-CSV-library - http://nuget.org/Media/Default/Packages/LinqToCsv/1.0.0.0/logo.jpg - false - - Serialise/Deserialize your classes to/from CSV and tab delimited files. Very flexible. Supports international date and number formats. - - $description$ - Copyright 2014 - CSV LINQ tab delimited - - - - \ No newline at end of file diff --git a/LINQtoCSV/Properties/AssemblyInfo.cs b/LINQtoCSV/Properties/AssemblyInfo.cs deleted file mode 100644 index 0605278..0000000 --- a/LINQtoCSV/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("LINQtoCSV")] -[assembly: AssemblyDescription("Popular, easy to use library to read and write CSV and tab delimited files. Supports data fields containing commas and line breaks. Supports different character encodings, separator characters and date and number formats. Robust error handling lets you quickly fix problems in large input files.")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Matt Perdeck")] -[assembly: AssemblyProduct("LINQtoCSV")] -[assembly: AssemblyCopyright("Copyright © 2014")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("734dd618-3346-49b5-879d-25c2a4cccd63")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.0.0")] -[assembly: AssemblyFileVersion("1.5.0.0")] diff --git a/Local.testsettings b/Local.testsettings deleted file mode 100644 index c1c276d..0000000 --- a/Local.testsettings +++ /dev/null @@ -1,10 +0,0 @@ - - - These are default test settings for a local test run. - - - - - - - \ No newline at end of file diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..59a8a8f --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/NuGet/GeneratedPackages/LINQtoCSV.1.3.0.0.nupkg b/NuGet/GeneratedPackages/LINQtoCSV.1.3.0.0.nupkg deleted file mode 100644 index b4deba3..0000000 Binary files a/NuGet/GeneratedPackages/LINQtoCSV.1.3.0.0.nupkg and /dev/null differ diff --git a/NuGet/GeneratedPackages/LINQtoCSV.1.4.0.0.nupkg b/NuGet/GeneratedPackages/LINQtoCSV.1.4.0.0.nupkg deleted file mode 100644 index 662ad37..0000000 Binary files a/NuGet/GeneratedPackages/LINQtoCSV.1.4.0.0.nupkg and /dev/null differ diff --git a/NuGet/GeneratedPackages/LINQtoCSV.1.5.0.0.nupkg b/NuGet/GeneratedPackages/LINQtoCSV.1.5.0.0.nupkg deleted file mode 100644 index 1a47a70..0000000 Binary files a/NuGet/GeneratedPackages/LINQtoCSV.1.5.0.0.nupkg and /dev/null differ diff --git a/NuGet/Tools/BuildNuGetPackage.bat b/NuGet/Tools/BuildNuGetPackage.bat deleted file mode 100644 index 08099ce..0000000 --- a/NuGet/Tools/BuildNuGetPackage.bat +++ /dev/null @@ -1,3 +0,0 @@ -rem Builds the project and creates NuGet package. - -nuget pack ..\..\LINQtoCSV\LINQtoCSV.csproj -Prop Configuration=Release -Build -OutputDirectory ..\GeneratedPackages diff --git a/SampleCode/Properties/AssemblyInfo.cs b/SampleCode/Properties/AssemblyInfo.cs deleted file mode 100644 index f484095..0000000 --- a/SampleCode/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("SampleCode")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("SampleCode")] -[assembly: AssemblyCopyright("Copyright © 2008")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("9a35945b-22c5-45af-8c4b-82e39aefac04")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/SampleCode/SampleCode.csproj b/SampleCode/SampleCode.csproj deleted file mode 100644 index 08ae132..0000000 --- a/SampleCode/SampleCode.csproj +++ /dev/null @@ -1,118 +0,0 @@ - - - - Debug - AnyCPU - 9.0.21022 - 2.0 - {EEFD875B-5D48-41F4-80FD-5FAE3725ED83} - Exe - Properties - SampleCode - SampleCode - v3.5 - 512 - - - - - 3.5 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - - - - - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - AllRules.ruleset - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - AllRules.ruleset - - - - - 3.5 - - - - - 3.5 - - - 3.5 - - - - - - - - - - - - - - - {07058BF9-6F86-40FF-AE33-2A4F89B5758A} - LINQtoCSV - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - \ No newline at end of file diff --git a/LINQtoCSV.Tests/CsvContextReadTests.cs b/Source/LINQtoCSV.Tests/CsvContextReadTests.cs similarity index 92% rename from LINQtoCSV.Tests/CsvContextReadTests.cs rename to Source/LINQtoCSV.Tests/CsvContextReadTests.cs index b8f57d8..2af7202 100644 --- a/LINQtoCSV.Tests/CsvContextReadTests.cs +++ b/Source/LINQtoCSV.Tests/CsvContextReadTests.cs @@ -1,15 +1,14 @@ using LINQtoCSV; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using System; using System.IO; using System.Collections.Generic; namespace LINQtoCSV.Tests { - [TestClass()] public class CsvContextReadTests : Test { - [TestMethod()] + [Fact] public void GoodFileUsingOutputFormatForParsingDatesCharUSEnglish() { // Arrange @@ -18,7 +17,7 @@ public void GoodFileUsingOutputFormatForParsingDatesCharUSEnglish() { SeparatorChar = ';', FirstLineHasColumnNames = false, - UseOutputFormatForParsingCsvValue = true, + UseOutputFormatForParsingCsvValue = true, EnforceCsvColumnAttribute = true, // default is false FileCultureName = "en-US" // default is the current culture }; @@ -33,7 +32,7 @@ public void GoodFileUsingOutputFormatForParsingDatesCharUSEnglish() name = "AAAAAAAA", startDate = new DateTime(2008, 5, 23), }, new ProductDataParsingOutputFormat { - name = "BBBBBBBB", startDate = new DateTime(2012, 5, 12), + name = "BBBBBBBB", startDate = new DateTime(2012, 5, 12), }, new ProductDataParsingOutputFormat { name = "CCCCCCCC", startDate = new DateTime(2008, 12, 23), @@ -45,7 +44,7 @@ public void GoodFileUsingOutputFormatForParsingDatesCharUSEnglish() AssertRead(testInput, fileDescription_namesUs, expected); } - [TestMethod()] + [Fact] public void GoodFileNoSeparatorCharUseOutputFormatForParsingUSEnglish() { // Arrange @@ -59,17 +58,14 @@ public void GoodFileNoSeparatorCharUseOutputFormatForParsingUSEnglish() FileCultureName = "en-US" // default is the current culture }; - string testInput = -@"AAAAAAAA34.18405/23/08\n -BBBBBBBB10.31105/12/12\n -CCCCCCCC12.00012/23/08"; + string testInput = "AAAAAAAA34.18405/23/08\r\nBBBBBBBB10.31105/12/12\r\nCCCCCCCC12.00012/23/08"; var expected = new[] { new ProductDataCharLength() { name = "AAAAAAAA", weight = 34.184, startDate = new DateTime(2008, 5, 23), }, new ProductDataCharLength { - name = "BBBBBBBB", weight = 10.311, startDate = new DateTime(2012, 5, 12), + name = "BBBBBBBB", weight = 10.311, startDate = new DateTime(2012, 5, 12), }, new ProductDataCharLength { name = "CCCCCCCC", weight = 12.000, startDate = new DateTime(2008, 12, 23), @@ -81,7 +77,7 @@ public void GoodFileNoSeparatorCharUseOutputFormatForParsingUSEnglish() AssertRead(testInput, fileDescription_namesUs, expected); } - [TestMethod()] + [Fact] public void GoodFileNoSeparatorCharUSEnglish() { // Arrange @@ -95,17 +91,14 @@ public void GoodFileNoSeparatorCharUSEnglish() FileCultureName = "en-US" // default is the current culture }; - string testInput = -@"AAAAAAAA34.18405/23/08\n -BBBBBBBB10.31105/12/12\n -CCCCCCCC12.00012/23/08"; + string testInput = "AAAAAAAA34.18405/23/08\r\nBBBBBBBB10.31105/12/12\r\nCCCCCCCC12.00012/23/08"; var expected = new[] { new ProductDataCharLength() { name = "AAAAAAAA", weight = 34.184, startDate = new DateTime(2008, 5, 23), }, new ProductDataCharLength { - name = "BBBBBBBB", weight = 10.311, startDate = new DateTime(2012, 5, 12), + name = "BBBBBBBB", weight = 10.311, startDate = new DateTime(2012, 5, 12), }, new ProductDataCharLength { name = "CCCCCCCC", weight = 12.000, startDate = new DateTime(2008, 12, 23), @@ -117,7 +110,7 @@ public void GoodFileNoSeparatorCharUSEnglish() AssertRead(testInput, fileDescription_namesUs, expected); } - [TestMethod()] + [Fact] public void GoodFileCommaDelimitedUseFieldIndexForReadingDataCharUSEnglish() { // Arrange @@ -142,7 +135,7 @@ public void GoodFileCommaDelimitedUseFieldIndexForReadingDataCharUSEnglish() name = "AAAAAAAA", weight = 34.184, startDate = new DateTime(2008, 5, 23), }, new ProductDataSpecificFieldIndex { - name = "BBBBBBBB", weight = 10.311, startDate = new DateTime(2012, 5, 12), + name = "BBBBBBBB", weight = 10.311, startDate = new DateTime(2012, 5, 12), }, new ProductDataSpecificFieldIndex { name = "CCCCCCCC", weight = 12.000, startDate = new DateTime(2008, 12, 23), @@ -154,7 +147,7 @@ public void GoodFileCommaDelimitedUseFieldIndexForReadingDataCharUSEnglish() AssertRead(testInput, fileDescription_namesUs, expected); } - [TestMethod()] + [Fact] public void GoodFileCommaDelimitedUseFieldIndexForReadingDataCharUseOutputFormatForParsingUSEnglish() { // Arrange @@ -181,7 +174,7 @@ public void GoodFileCommaDelimitedUseFieldIndexForReadingDataCharUseOutputFormat name = "AAAAAAAA", weight = 34.184, startDate = new DateTime(2008, 5, 23), }, new ProductDataSpecificFieldIndex { - name = "BBBBBBBB", weight = 10.311, startDate = new DateTime(2012, 5, 12), + name = "BBBBBBBB", weight = 10.311, startDate = new DateTime(2012, 5, 12), }, new ProductDataSpecificFieldIndex { name = "CCCCCCCC", weight = 12.000, startDate = new DateTime(2008, 12, 23), @@ -194,7 +187,7 @@ public void GoodFileCommaDelimitedUseFieldIndexForReadingDataCharUseOutputFormat } - [TestMethod()] + [Fact] public void GoodFileCommaDelimitedNamesInFirstLineUSEnglish() { // Arrange @@ -216,7 +209,7 @@ two newlines and a quoted """"string"""""" dog house, ""45,230,990"",29 Feb 2004, , -56, True,"""", FF10, ""12,008"""; - var expected = new [] { + var expected = new[] { new ProductData { name = "moonbuggy", weight = 34.184, startDate = new DateTime(2008, 5, 23), launchTime = new DateTime(2009, 5, 5, 16, 11, 0), nbrAvailable = 1205, onsale = true, shopsAvailable = "Paris, New York", hexProductCode = 31, retailPrice = 540.12M, @@ -242,7 +235,7 @@ and a quoted ""string""" AssertRead(testInput, fileDescription_namesUs, expected); } - [TestMethod()] + [Fact] public void GoodFileTabDelimitedNoNamesInFirstLineNLnl() { // Arrange @@ -265,11 +258,8 @@ public void GoodFileTabDelimitedNoNamesInFirstLineNLnl() }, new ProductData { name = "mouse trap", weight = 45E-5, startDate = new DateTime(1985, 1, 2), launchTime = new DateTime(1988, 8, 7, 0, 0, 0), - nbrAvailable = 0, onsale = false, shopsAvailable = @"This field has -a newline", hexProductCode = 256, retailPrice = 78300M, - description = @"This field has quotes(""), and -two newlines -and a quoted ""string""" + nbrAvailable = 0, onsale = false, shopsAvailable = "This field has\r\na newline", hexProductCode = 256, retailPrice = 78300M, + description = "This field has quotes(\"), and\r\ntwo newlines\r\nand a quoted \"string\"" }, new ProductData { name = "dog house", weight = 45230990, startDate = new DateTime(2004, 2, 29), launchTime = default(DateTime), @@ -283,7 +273,7 @@ and a quoted ""string""" AssertRead(testInput, fileDescription_nonamesNl, expected); } - [TestMethod()] + [Fact] public void GoodFileCommaDelimitedWithTrailingSeparatorChars() { // Arrange @@ -332,17 +322,18 @@ and a quoted ""string""" AssertRead(testInput, fileDescription_namesUs, expected); } - [TestMethod()] - public void FileWithUnknownColumns_ShouldDiscardColumns() { + [Fact] + public void FileWithUnknownColumns_ShouldDiscardColumns() + { var description = new CsvFileDescription - { - SeparatorChar = ',', - FirstLineHasColumnNames = true, - IgnoreUnknownColumns = true, - }; - + { + SeparatorChar = ',', + FirstLineHasColumnNames = true, + IgnoreUnknownColumns = true, + }; + //The following input has 5 columns: Id | Name | Last Name | Age | City. Only the Name, Last Name and Age will be read. - + string input = @"Id,Name,Last Name,Age,City 1,John,Doe,15,Washington diff --git a/Source/LINQtoCSV.Tests/CsvContextWriteTests.cs b/Source/LINQtoCSV.Tests/CsvContextWriteTests.cs new file mode 100644 index 0000000..cf1ac31 --- /dev/null +++ b/Source/LINQtoCSV.Tests/CsvContextWriteTests.cs @@ -0,0 +1,44 @@ +using LINQtoCSV; +using Xunit; +using System; +using System.IO; +using System.Collections.Generic; +using System.Text; + +namespace LINQtoCSV.Tests +{ + public class CsvContextWriteTests : Test + { + [Fact] + public void OnlyIncludeFieldsSpecifiedInFieldsToIncludeInOutput() + { + // Arrange + + List dataRows_Test = new List(); + dataRows_Test.Add(new ProductData { name = "normal", weight = 7.5, hexProductCode = 0x456, retailPrice = 349.99m }); + dataRows_Test.Add(new ProductData { name = "extra", weight = 6.5, hexProductCode = 0x457, retailPrice = 249.99m, description = "should not appear" }); + dataRows_Test.Add(new ProductData { name = "free", weight = 5.5, hexProductCode = 0x458 }); + + CsvFileDescription fileDescription_namesNl2 = new CsvFileDescription + { + SeparatorChar = ',', + FirstLineHasColumnNames = true, + EnforceCsvColumnAttribute = false, + TextEncoding = Encoding.Unicode, + FileCultureName = "nl-Nl", // default is the current culture + FieldsToIncludeInOutput = new[] { "name", "weight", "code", "price" } + }; + + string expected = +@"name,weight,code,price +normal,""007,500"",1110,""€ 349,99"" +extra,""006,500"",1111,""€ 249,99"" +free,""005,500"",1112,""€ 0,00"" +"; + + // Act and Assert + + AssertWrite(dataRows_Test, fileDescription_namesNl2, expected); + } + } +} diff --git a/LINQtoCSV.Tests/IAssertable.cs b/Source/LINQtoCSV.Tests/IAssertable.cs similarity index 100% rename from LINQtoCSV.Tests/IAssertable.cs rename to Source/LINQtoCSV.Tests/IAssertable.cs diff --git a/Source/LINQtoCSV.Tests/LINQtoCSV.Tests.csproj b/Source/LINQtoCSV.Tests/LINQtoCSV.Tests.csproj new file mode 100644 index 0000000..41632d3 --- /dev/null +++ b/Source/LINQtoCSV.Tests/LINQtoCSV.Tests.csproj @@ -0,0 +1,21 @@ + + + net8.0 + 7.3 + true + true + embedded + true + false + + + true + true + + + + + + + + \ No newline at end of file diff --git a/LINQtoCSV.Tests/Person.cs b/Source/LINQtoCSV.Tests/Person.cs similarity index 70% rename from LINQtoCSV.Tests/Person.cs rename to Source/LINQtoCSV.Tests/Person.cs index 7ef109d..6829cab 100644 --- a/LINQtoCSV.Tests/Person.cs +++ b/Source/LINQtoCSV.Tests/Person.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; namespace LINQtoCSV.Tests { @@ -15,9 +15,9 @@ public class Person : IAssertable { public int Age { get; set; } public void AssertEqual(Person other) { - Assert.AreEqual(other.Name, Name); - Assert.AreEqual(other.LastName, LastName); - Assert.AreEqual(other.Age, Age); + Assert.Equal(other.Name, Name); + Assert.Equal(other.LastName, LastName); + Assert.Equal(other.Age, Age); } } } diff --git a/LINQtoCSV.Tests/ProductData.cs b/Source/LINQtoCSV.Tests/ProductData.cs similarity index 74% rename from LINQtoCSV.Tests/ProductData.cs rename to Source/LINQtoCSV.Tests/ProductData.cs index f9103a4..4b5f744 100644 --- a/LINQtoCSV.Tests/ProductData.cs +++ b/Source/LINQtoCSV.Tests/ProductData.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using System.Globalization; using LINQtoCSV; @@ -62,18 +62,18 @@ internal class ProductData : IAssertable public void AssertEqual(ProductData other) { - Assert.AreNotEqual(other, null); + Assert.NotNull(other); - Assert.AreEqual(other.name, name, "name"); - Assert.AreEqual(other.startDate, startDate, "startDate"); - Assert.AreEqual(other.launchTime, launchTime, "launchTime"); - Assert.AreEqual(other.weight, weight, "weight"); - Assert.AreEqual(other.nbrAvailable, nbrAvailable, "nbrAvailable"); - Assert.AreEqual(other.shopsAvailable, shopsAvailable, "shopsAvailable"); - Assert.AreEqual(other.hexProductCode, hexProductCode, "hexProductCode"); - Assert.AreEqual(other.onsale, onsale, "onsale"); - Assert.AreEqual(other.retailPrice, retailPrice, "retailPrice"); - Assert.AreEqual(Utils.NormalizeString(other.description), Utils.NormalizeString(description), "description"); + Assert.Equal(other.name, name); + Assert.Equal(other.startDate, startDate); + Assert.Equal(other.launchTime, launchTime); + Assert.Equal(other.weight, weight); + Assert.Equal(other.nbrAvailable, nbrAvailable); + Assert.Equal(other.shopsAvailable, shopsAvailable); + Assert.Equal(other.hexProductCode, hexProductCode); + Assert.Equal(other.onsale, onsale); + Assert.Equal(other.retailPrice, retailPrice); + Assert.Equal(Utils.NormalizeString(other.description), Utils.NormalizeString(description)); } } } diff --git a/LINQtoCSV.Tests/ProductDataSpecificFieldIndex.cs b/Source/LINQtoCSV.Tests/ProductDataSpecificFieldIndex.cs similarity index 75% rename from LINQtoCSV.Tests/ProductDataSpecificFieldIndex.cs rename to Source/LINQtoCSV.Tests/ProductDataSpecificFieldIndex.cs index f213421..f7420cf 100644 --- a/LINQtoCSV.Tests/ProductDataSpecificFieldIndex.cs +++ b/Source/LINQtoCSV.Tests/ProductDataSpecificFieldIndex.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Xunit; using System.Globalization; using LINQtoCSV; @@ -29,11 +29,11 @@ internal class ProductDataSpecificFieldIndex : IAssertable public void AssertEqual(ProductDataCharLength other) { - Assert.AreNotEqual(other, null); + Assert.NotNull(other); - Assert.AreEqual(other.name, name, "name"); - Assert.AreEqual(other.startDate, startDate, "startDate"); - Assert.AreEqual(other.weight, weight, "weight"); + Assert.Equal(other.name, name); + Assert.Equal(other.startDate, startDate); + Assert.Equal(other.weight, weight); } } @@ -75,10 +75,10 @@ internal class ProductDataParsingOutputFormat : IAssertable /// /// - protected StreamReader StreamReaderFromString(string s) + protected static StreamReader StreamReaderFromString(string s) { byte[] stringAsByteArray = System.Text.Encoding.UTF8.GetBytes(s); Stream stream = new MemoryStream(stringAsByteArray); @@ -23,12 +23,12 @@ protected StreamReader StreamReaderFromString(string s) return streamReader; } - protected void AssertCollectionsEqual(IEnumerable actual, IEnumerable expected) where T : IAssertable + protected static void AssertCollectionsEqual(IEnumerable actual, IEnumerable expected) where T : IAssertable { int count = actual.Count(); - Assert.AreEqual(count, expected.Count(), "counts"); + Assert.Equal(count, expected.Count()); - for(int i = 0; i < count; i++) + for (int i = 0; i < count; i++) { actual.ElementAt(i).AssertEqual(expected.ElementAt(i)); } @@ -50,7 +50,7 @@ protected void AssertCollectionsEqual(IEnumerable actual, IEnumerable e /// /// Output of Read. /// - public IEnumerable TestRead(string testInput, CsvFileDescription fileDescription) where T : class, new() + public static IEnumerable TestRead(string testInput, CsvFileDescription fileDescription) where T : class, new() { CsvContext cc = new CsvContext(); return cc.Read(StreamReaderFromString(testInput), fileDescription); @@ -72,11 +72,11 @@ protected void AssertCollectionsEqual(IEnumerable actual, IEnumerable e /// /// Expected output. /// - public void AssertRead(string testInput, CsvFileDescription fileDescription, IEnumerable expected) + public static void AssertRead(string testInput, CsvFileDescription fileDescription, IEnumerable expected) where T : class, IAssertable, new() { IEnumerable actual = TestRead(testInput, fileDescription); - AssertCollectionsEqual(actual, expected); + AssertCollectionsEqual(actual, expected); } /// @@ -94,9 +94,9 @@ public void AssertRead(string testInput, CsvFileDescription fileDescription, /// /// Returns a string with the content that the Write method writes to a file or TextWriter. /// - public string TestWrite(IEnumerable values, CsvFileDescription fileDescription) where T : class + public static string TestWrite(IEnumerable values, CsvFileDescription fileDescription) where T : class { - TextWriter stream = new StringWriter(); + var stream = new StringWriter(); CsvContext cc = new CsvContext(); cc.Write(values, stream, fileDescription); return stream.ToString(); @@ -117,10 +117,10 @@ public string TestWrite(IEnumerable values, CsvFileDescription fileDescrip /// /// Expected output. /// - public void AssertWrite(IEnumerable values, CsvFileDescription fileDescription, string expected) where T : class + public static void AssertWrite(IEnumerable values, CsvFileDescription fileDescription, string expected) where T : class { - string actual = TestWrite(values, fileDescription); - Assert.AreEqual(Utils.NormalizeString(actual), Utils.NormalizeString(expected)); + string actual = TestWrite(values, fileDescription); + Assert.Equal(Utils.NormalizeString(expected), Utils.NormalizeString(actual)); } } } diff --git a/LINQtoCSV.Tests/TestDataRow.cs b/Source/LINQtoCSV.Tests/TestDataRow.cs similarity index 100% rename from LINQtoCSV.Tests/TestDataRow.cs rename to Source/LINQtoCSV.Tests/TestDataRow.cs diff --git a/LINQtoCSV.Tests/Utils.cs b/Source/LINQtoCSV.Tests/Utils.cs similarity index 100% rename from LINQtoCSV.Tests/Utils.cs rename to Source/LINQtoCSV.Tests/Utils.cs diff --git a/LINQtoCSV.sln b/Source/LINQtoCSV.sln similarity index 72% rename from LINQtoCSV.sln rename to Source/LINQtoCSV.sln index 62bbb72..7d30b78 100644 --- a/LINQtoCSV.sln +++ b/Source/LINQtoCSV.sln @@ -1,25 +1,19 @@  -Microsoft Visual Studio Solution File, Format Version 11.00 -# Visual Studio 2010 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestConsoleApplication", "TestConsoleApplication\TestConsoleApplication.csproj", "{C3FE8ACB-688B-47E4-9E62-0EE09B0435E1}" +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30320.27 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestConsoleApplication", "TestConsoleApplication\TestConsoleApplication.csproj", "{C3FE8ACB-688B-47E4-9E62-0EE09B0435E1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINQtoCSV", "LINQtoCSV\LINQtoCSV.csproj", "{07058BF9-6F86-40FF-AE33-2A4F89B5758A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINQtoCSV", "LINQtoCSV\LINQtoCSV.csproj", "{07058BF9-6F86-40FF-AE33-2A4F89B5758A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleCode", "SampleCode\SampleCode.csproj", "{EEFD875B-5D48-41F4-80FD-5FAE3725ED83}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleCode", "SampleCode\SampleCode.csproj", "{EEFD875B-5D48-41F4-80FD-5FAE3725ED83}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LINQtoCSV.Tests", "LINQtoCSV.Tests\LINQtoCSV.Tests.csproj", "{04EE17CD-E7B3-4D58-BF84-E553F5332A14}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LINQtoCSV.Tests", "LINQtoCSV.Tests\LINQtoCSV.Tests.csproj", "{04EE17CD-E7B3-4D58-BF84-E553F5332A14}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{23664B5F-ED48-4718-94B7-C1A65CDA45EE}" - ProjectSection(SolutionItems) = preProject - LINQtoCSV.vsmdi = LINQtoCSV.vsmdi - Local.testsettings = Local.testsettings - TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings - EndProjectSection +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "_build", "..\Build\_build.csproj", "{7644DF60-1C4C-4534-9C9C-8F8D23584CFA}" EndProject Global - GlobalSection(TestCaseManagementSettings) = postSolution - CategoryFile = LINQtoCSV.vsmdi - EndGlobalSection GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Release|Any CPU = Release|Any CPU @@ -41,8 +35,16 @@ Global {04EE17CD-E7B3-4D58-BF84-E553F5332A14}.Debug|Any CPU.Build.0 = Debug|Any CPU {04EE17CD-E7B3-4D58-BF84-E553F5332A14}.Release|Any CPU.ActiveCfg = Release|Any CPU {04EE17CD-E7B3-4D58-BF84-E553F5332A14}.Release|Any CPU.Build.0 = Release|Any CPU + {7644DF60-1C4C-4534-9C9C-8F8D23584CFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7644DF60-1C4C-4534-9C9C-8F8D23584CFA}.Release|Any CPU.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {6B7AB3E2-3B13-489A-901D-B424B7AFEEFE} + EndGlobalSection + GlobalSection(TestCaseManagementSettings) = postSolution + CategoryFile = LINQtoCSV.vsmdi + EndGlobalSection EndGlobal diff --git a/LINQtoCSV/CsvColumnAttribute.cs b/Source/LINQtoCSV/CsvColumnAttribute.cs similarity index 100% rename from LINQtoCSV/CsvColumnAttribute.cs rename to Source/LINQtoCSV/CsvColumnAttribute.cs diff --git a/LINQtoCSV/CsvContext.cs b/Source/LINQtoCSV/CsvContext.cs similarity index 96% rename from LINQtoCSV/CsvContext.cs rename to Source/LINQtoCSV/CsvContext.cs index 62d799c..25eccf8 100644 --- a/LINQtoCSV/CsvContext.cs +++ b/Source/LINQtoCSV/CsvContext.cs @@ -133,7 +133,7 @@ private IEnumerable ReadData( // If we're reading raw data rows, instantiate a T so we return objects // of the type specified by the caller. // Otherwise, instantiate a DataRow, which also implements IDataRow. - IDataRow row = null; + IDataRow row; if (readingRawDataRows) { row = new T() as IDataRow; @@ -173,7 +173,7 @@ private IEnumerable ReadData( } else { - T obj = default(T); + T obj = default; try { if (readingRawDataRows) @@ -185,12 +185,12 @@ private IEnumerable ReadData( obj = fm.ReadObject(row, ae); } } - catch (AggregatedException ae2) + catch (AggregatedException) { // Seeing that the AggregatedException was thrown, maximum number of exceptions // must have been reached, so rethrow. // Catch here, so you don't add an AggregatedException to an AggregatedException - throw ae2; + throw; } catch (Exception e) { @@ -266,13 +266,13 @@ private void WriteData( { FieldMapper fm = new FieldMapper(fileDescription, fileName, true); CsvStream cs = new CsvStream(null, stream, fileDescription.SeparatorChar, fileDescription.IgnoreTrailingSeparatorChar); - + HashSet fieldsToInclude = fileDescription.FieldsToIncludeInOutput != null ? new HashSet(fileDescription.FieldsToIncludeInOutput) : null; List row = new List(); // If first line has to carry the field names, write the field names now. if (fileDescription.FirstLineHasColumnNames) { - fm.WriteNames(row); + fm.WriteNames(row, fieldsToInclude); cs.WriteRow(row, fileDescription.QuoteAllFields); } @@ -281,7 +281,7 @@ private void WriteData( foreach (T obj in values) { // Convert obj to row - fm.WriteObject(obj, row); + fm.WriteObject(obj, row, fieldsToInclude); cs.WriteRow(row, fileDescription.QuoteAllFields); } } diff --git a/LINQtoCSV/CsvFileDescription.cs b/Source/LINQtoCSV/CsvFileDescription.cs similarity index 95% rename from LINQtoCSV/CsvFileDescription.cs rename to Source/LINQtoCSV/CsvFileDescription.cs index b983ca8..a4c5031 100644 --- a/LINQtoCSV/CsvFileDescription.cs +++ b/Source/LINQtoCSV/CsvFileDescription.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Globalization; using System.Text; @@ -96,6 +97,11 @@ public int MaximumNbrExceptions /// public bool IgnoreUnknownColumns { get; set; } + /// + /// If not null, will only write fields included in the list + /// + public string[] FieldsToIncludeInOutput { get; set; } + // --------------- public CsvFileDescription() diff --git a/LINQtoCSV/CsvInputFormatAttribute.cs b/Source/LINQtoCSV/CsvInputFormatAttribute.cs similarity index 100% rename from LINQtoCSV/CsvInputFormatAttribute.cs rename to Source/LINQtoCSV/CsvInputFormatAttribute.cs diff --git a/LINQtoCSV/CsvOutputFormatAttribute.cs b/Source/LINQtoCSV/CsvOutputFormatAttribute.cs similarity index 100% rename from LINQtoCSV/CsvOutputFormatAttribute.cs rename to Source/LINQtoCSV/CsvOutputFormatAttribute.cs diff --git a/LINQtoCSV/CsvStream.cs b/Source/LINQtoCSV/CsvStream.cs similarity index 100% rename from LINQtoCSV/CsvStream.cs rename to Source/LINQtoCSV/CsvStream.cs diff --git a/LINQtoCSV/DataRow.cs b/Source/LINQtoCSV/DataRow.cs similarity index 100% rename from LINQtoCSV/DataRow.cs rename to Source/LINQtoCSV/DataRow.cs diff --git a/LINQtoCSV/DataRowItem.cs b/Source/LINQtoCSV/DataRowItem.cs similarity index 100% rename from LINQtoCSV/DataRowItem.cs rename to Source/LINQtoCSV/DataRowItem.cs diff --git a/LINQtoCSV/Exceptions.cs b/Source/LINQtoCSV/Exceptions.cs similarity index 100% rename from LINQtoCSV/Exceptions.cs rename to Source/LINQtoCSV/Exceptions.cs diff --git a/LINQtoCSV/FieldMapper.cs b/Source/LINQtoCSV/FieldMapper.cs similarity index 97% rename from LINQtoCSV/FieldMapper.cs rename to Source/LINQtoCSV/FieldMapper.cs index 9ef9dfc..6334c03 100644 --- a/LINQtoCSV/FieldMapper.cs +++ b/Source/LINQtoCSV/FieldMapper.cs @@ -282,7 +282,7 @@ public FieldMapper(CsvFileDescription fileDescription, string fileName, bool wri /// Writes the field names given in T to row. /// /// - public void WriteNames(List row) + public void WriteNames(List row, HashSet fieldsToInclude) { row.Clear(); @@ -296,9 +296,10 @@ public void WriteNames(List row) continue; } - // ---- - - row.Add(tfi.name); + if (fieldsToInclude == null || fieldsToInclude.Contains(tfi.name)) + { + row.Add(tfi.name); + } } } @@ -306,7 +307,7 @@ public void WriteNames(List row) /// /////////////////////////////////////////////////////////////////////// /// WriteObject /// - public void WriteObject(T obj, List row) + public void WriteObject(T obj, List row, HashSet fieldsToInclude) { row.Clear(); @@ -320,6 +321,8 @@ public void WriteObject(T obj, List row) continue; } + + // ---- Object objValue = null; @@ -355,7 +358,10 @@ public void WriteObject(T obj, List row) // ----- - row.Add(resultString); + if (fieldsToInclude == null || fieldsToInclude.Contains(tfi.name)) + { + row.Add(resultString); + } } } } diff --git a/LINQtoCSV/IDataRow.cs b/Source/LINQtoCSV/IDataRow.cs similarity index 100% rename from LINQtoCSV/IDataRow.cs rename to Source/LINQtoCSV/IDataRow.cs diff --git a/Source/LINQtoCSV/LINQtoCSV.csproj b/Source/LINQtoCSV/LINQtoCSV.csproj new file mode 100644 index 0000000..8e25a76 --- /dev/null +++ b/Source/LINQtoCSV/LINQtoCSV.csproj @@ -0,0 +1,13 @@ + + + net8.0 + 7.3 + true + true + embedded + true + GlobalRoam.LINQtoCSV + Global-Roam + Global-Roam fork of apparently abandoned https://github.com/mperdeck/LINQtoCSV project + + \ No newline at end of file diff --git a/SampleCode/Product.cs b/Source/SampleCode/Product.cs similarity index 100% rename from SampleCode/Product.cs rename to Source/SampleCode/Product.cs diff --git a/SampleCode/Program.cs b/Source/SampleCode/Program.cs similarity index 100% rename from SampleCode/Program.cs rename to Source/SampleCode/Program.cs diff --git a/Source/SampleCode/SampleCode.csproj b/Source/SampleCode/SampleCode.csproj new file mode 100644 index 0000000..f81e158 --- /dev/null +++ b/Source/SampleCode/SampleCode.csproj @@ -0,0 +1,14 @@ + + + net8.0 + 7.3 + true + true + embedded + true + false + + + + + \ No newline at end of file diff --git a/SampleCode/TestFiles/products.csv b/Source/SampleCode/TestFiles/products.csv similarity index 100% rename from SampleCode/TestFiles/products.csv rename to Source/SampleCode/TestFiles/products.csv diff --git a/TestConsoleApplication/ProductData.cs b/Source/TestConsoleApplication/ProductData.cs similarity index 100% rename from TestConsoleApplication/ProductData.cs rename to Source/TestConsoleApplication/ProductData.cs diff --git a/TestConsoleApplication/ProductData_DuplicateIndices.cs b/Source/TestConsoleApplication/ProductData_DuplicateIndices.cs similarity index 100% rename from TestConsoleApplication/ProductData_DuplicateIndices.cs rename to Source/TestConsoleApplication/ProductData_DuplicateIndices.cs diff --git a/TestConsoleApplication/ProductData_MissingFieldIndex.cs b/Source/TestConsoleApplication/ProductData_MissingFieldIndex.cs similarity index 100% rename from TestConsoleApplication/ProductData_MissingFieldIndex.cs rename to Source/TestConsoleApplication/ProductData_MissingFieldIndex.cs diff --git a/TestConsoleApplication/Program.cs b/Source/TestConsoleApplication/Program.cs similarity index 100% rename from TestConsoleApplication/Program.cs rename to Source/TestConsoleApplication/Program.cs diff --git a/Source/TestConsoleApplication/TestConsoleApplication.csproj b/Source/TestConsoleApplication/TestConsoleApplication.csproj new file mode 100644 index 0000000..2f065de --- /dev/null +++ b/Source/TestConsoleApplication/TestConsoleApplication.csproj @@ -0,0 +1,11 @@ + + + Exe + net8.0 + AnyCPU + false + + + + + \ No newline at end of file diff --git a/TestConsoleApplication/TestDataRow.cs b/Source/TestConsoleApplication/TestDataRow.cs similarity index 100% rename from TestConsoleApplication/TestDataRow.cs rename to Source/TestConsoleApplication/TestDataRow.cs diff --git a/TestConsoleApplication/TestFiles/badfile_unknownname.csv b/Source/TestConsoleApplication/TestFiles/badfile_unknownname.csv similarity index 100% rename from TestConsoleApplication/TestFiles/badfile_unknownname.csv rename to Source/TestConsoleApplication/TestFiles/badfile_unknownname.csv diff --git a/TestConsoleApplication/TestFiles/badfile_us_dataerrors.csv b/Source/TestConsoleApplication/TestFiles/badfile_us_dataerrors.csv similarity index 100% rename from TestConsoleApplication/TestFiles/badfile_us_dataerrors.csv rename to Source/TestConsoleApplication/TestFiles/badfile_us_dataerrors.csv diff --git a/TestConsoleApplication/TestFiles/goodfile_nl.csv b/Source/TestConsoleApplication/TestFiles/goodfile_nl.csv similarity index 100% rename from TestConsoleApplication/TestFiles/goodfile_nl.csv rename to Source/TestConsoleApplication/TestFiles/goodfile_nl.csv diff --git a/TestConsoleApplication/TestFiles/goodfile_us.csv b/Source/TestConsoleApplication/TestFiles/goodfile_us.csv similarity index 100% rename from TestConsoleApplication/TestFiles/goodfile_us.csv rename to Source/TestConsoleApplication/TestFiles/goodfile_us.csv diff --git a/TestConsoleApplication/TestFiles/output_anon.csv b/Source/TestConsoleApplication/TestFiles/output_anon.csv similarity index 100% rename from TestConsoleApplication/TestFiles/output_anon.csv rename to Source/TestConsoleApplication/TestFiles/output_anon.csv diff --git a/TestConsoleApplication/TestFiles/output_bad.csv b/Source/TestConsoleApplication/TestFiles/output_bad.csv similarity index 100% rename from TestConsoleApplication/TestFiles/output_bad.csv rename to Source/TestConsoleApplication/TestFiles/output_bad.csv diff --git a/TestConsoleApplication/TestFiles/output_names_nl.csv b/Source/TestConsoleApplication/TestFiles/output_names_nl.csv similarity index 100% rename from TestConsoleApplication/TestFiles/output_names_nl.csv rename to Source/TestConsoleApplication/TestFiles/output_names_nl.csv diff --git a/TestConsoleApplication/TestFiles/output_newdata_names_nl.csv b/Source/TestConsoleApplication/TestFiles/output_newdata_names_nl.csv similarity index 100% rename from TestConsoleApplication/TestFiles/output_newdata_names_nl.csv rename to Source/TestConsoleApplication/TestFiles/output_newdata_names_nl.csv diff --git a/TestConsoleApplication/TestFiles/output_nonames_us.csv b/Source/TestConsoleApplication/TestFiles/output_nonames_us.csv similarity index 100% rename from TestConsoleApplication/TestFiles/output_nonames_us.csv rename to Source/TestConsoleApplication/TestFiles/output_nonames_us.csv diff --git a/TestConsoleApplication/Utils.cs b/Source/TestConsoleApplication/Utils.cs similarity index 100% rename from TestConsoleApplication/Utils.cs rename to Source/TestConsoleApplication/Utils.cs diff --git a/TestConsoleApplication/Properties/AssemblyInfo.cs b/TestConsoleApplication/Properties/AssemblyInfo.cs deleted file mode 100644 index e211159..0000000 --- a/TestConsoleApplication/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("TestConsoleApplication")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("TestConsoleApplication")] -[assembly: AssemblyCopyright("Copyright © 2008")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("cdd04580-d61d-41e7-a853-a770b66f818f")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/TestConsoleApplication/TestConsoleApplication.csproj b/TestConsoleApplication/TestConsoleApplication.csproj deleted file mode 100644 index a735f28..0000000 --- a/TestConsoleApplication/TestConsoleApplication.csproj +++ /dev/null @@ -1,125 +0,0 @@ - - - - Debug - AnyCPU - 9.0.30729 - 2.0 - {C3FE8ACB-688B-47E4-9E62-0EE09B0435E1} - Exe - Properties - TestConsoleApplication - TestConsoleApplication - v3.5 - 512 - - - - - 3.5 - publish\ - true - Disk - false - Foreground - 7 - Days - false - false - true - 0 - 1.0.0.%2a - false - false - true - - - - - - - - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - AllRules.ruleset - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 - AllRules.ruleset - - - - - 3.5 - - - - - 3.5 - - - 3.5 - - - - - - - - - - - - - - - - - - - - - - {07058BF9-6F86-40FF-AE33-2A4F89B5758A} - LINQtoCSV - - - - - False - .NET Framework 3.5 SP1 Client Profile - false - - - False - .NET Framework 3.5 SP1 - true - - - False - Windows Installer 3.1 - true - - - - - \ No newline at end of file diff --git a/TraceAndTestImpact.testsettings b/TraceAndTestImpact.testsettings deleted file mode 100644 index bed660c..0000000 --- a/TraceAndTestImpact.testsettings +++ /dev/null @@ -1,21 +0,0 @@ - - - These are test settings for Trace and Test Impact. - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/azure-pipelines.yml b/azure-pipelines.yml new file mode 100644 index 0000000..7cffb73 --- /dev/null +++ b/azure-pipelines.yml @@ -0,0 +1,50 @@ +trigger: + batch: true + branches: + include: + - master + +pr: + branches: + include: + - master + +variables: + DOTNET_SDK_VERSION: '8.x' + +pool: + name: Global Roam Office Build-03 + +resources: + repositories: + - repository: templates + type: github + name: global-roam/devops-pipelines + endpoint: global-roam + +steps: + - checkout: self + clean: true + + - template: authentication/steps/package-managers-windows.yml@templates + - template: pipeline/steps/pr-workaround-before.yml@templates + + - task: UseDotNet@2 + displayName: 'Use .NET Core SDK $(DOTNET_SDK_VERSION)' + inputs: + version: '$(DOTNET_SDK_VERSION)' + + - template: pipeline/steps/build-and-push-nuke-package.yml@templates + + - task: PublishTestResults@2 + displayName: Publish test results + inputs: + testResultsFormat: VSTest + testResultsFiles: '**/*.trx' + searchFolder: $(Common.TestResultsDirectory) + mergeTestResults: true + condition: and(always(), not(canceled())) + continueOnError: true + + - template: pipeline/steps/pr-workaround-after.yml@templates + diff --git a/build.cmd b/build.cmd new file mode 100755 index 0000000..b08cc59 --- /dev/null +++ b/build.cmd @@ -0,0 +1,7 @@ +:; set -eo pipefail +:; SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) +:; ${SCRIPT_DIR}/build.sh "$@" +:; exit $? + +@ECHO OFF +powershell -ExecutionPolicy ByPass -NoProfile -File "%~dp0build.ps1" %* diff --git a/build.ps1 b/build.ps1 new file mode 100644 index 0000000..580c737 --- /dev/null +++ b/build.ps1 @@ -0,0 +1,69 @@ +[CmdletBinding()] +Param( + [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] + [string[]]$BuildArguments +) + +Write-Output "PowerShell $($PSVersionTable.PSEdition) version $($PSVersionTable.PSVersion)" + +Set-StrictMode -Version 2.0; $ErrorActionPreference = "Stop"; $ConfirmPreference = "None"; trap { Write-Error $_ -ErrorAction Continue; exit 1 } +$PSScriptRoot = Split-Path $MyInvocation.MyCommand.Path -Parent + +########################################################################### +# CONFIGURATION +########################################################################### + +$BuildProjectFile = "$PSScriptRoot\Build\_build.csproj" +$TempDirectory = "$PSScriptRoot\\.nuke\temp" + +$DotNetGlobalFile = "$PSScriptRoot\\global.json" +$DotNetInstallUrl = "https://dot.net/v1/dotnet-install.ps1" +$DotNetChannel = "Current" + +$env:DOTNET_SKIP_FIRST_TIME_EXPERIENCE = 1 +$env:DOTNET_CLI_TELEMETRY_OPTOUT = 1 +$env:DOTNET_MULTILEVEL_LOOKUP = 0 + +########################################################################### +# EXECUTION +########################################################################### + +function ExecSafe([scriptblock] $cmd) { + & $cmd + if ($LASTEXITCODE) { exit $LASTEXITCODE } +} + +# If dotnet CLI is installed globally and it matches requested version, use for execution +if ($null -ne (Get-Command "dotnet" -ErrorAction SilentlyContinue) -and ` + $(dotnet --version) -and $LASTEXITCODE -eq 0) { + $env:DOTNET_EXE = (Get-Command "dotnet").Path +} +else { + # Download install script + $DotNetInstallFile = "$TempDirectory\dotnet-install.ps1" + New-Item -ItemType Directory -Path $TempDirectory -Force | Out-Null + [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 + (New-Object System.Net.WebClient).DownloadFile($DotNetInstallUrl, $DotNetInstallFile) + + # If global.json exists, load expected version + if (Test-Path $DotNetGlobalFile) { + $DotNetGlobal = $(Get-Content $DotNetGlobalFile | Out-String | ConvertFrom-Json) + if ($DotNetGlobal.PSObject.Properties["sdk"] -and $DotNetGlobal.sdk.PSObject.Properties["version"]) { + $DotNetVersion = $DotNetGlobal.sdk.version + } + } + + # Install by channel or version + $DotNetDirectory = "$TempDirectory\dotnet-win" + if (!(Test-Path variable:DotNetVersion)) { + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Channel $DotNetChannel -NoPath } + } else { + ExecSafe { & powershell $DotNetInstallFile -InstallDir $DotNetDirectory -Version $DotNetVersion -NoPath } + } + $env:DOTNET_EXE = "$DotNetDirectory\dotnet.exe" +} + +Write-Output "Microsoft (R) .NET SDK version $(& $env:DOTNET_EXE --version)" + +ExecSafe { & $env:DOTNET_EXE build $BuildProjectFile /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet } +ExecSafe { & $env:DOTNET_EXE run --project $BuildProjectFile --no-build -- $BuildArguments } diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..0270868 --- /dev/null +++ b/build.sh @@ -0,0 +1,62 @@ +#!/usr/bin/env bash + +bash --version 2>&1 | head -n 1 + +set -eo pipefail +SCRIPT_DIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd) + +########################################################################### +# CONFIGURATION +########################################################################### + +BUILD_PROJECT_FILE="$SCRIPT_DIR/Build/_build.csproj" +TEMP_DIRECTORY="$SCRIPT_DIR//.nuke/temp" + +DOTNET_GLOBAL_FILE="$SCRIPT_DIR//global.json" +DOTNET_INSTALL_URL="https://dot.net/v1/dotnet-install.sh" +DOTNET_CHANNEL="Current" + +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +export DOTNET_MULTILEVEL_LOOKUP=0 + +########################################################################### +# EXECUTION +########################################################################### + +function FirstJsonValue { + perl -nle 'print $1 if m{"'"$1"'": "([^"]+)",?}' <<< "${@:2}" +} + +# If dotnet CLI is installed globally and it matches requested version, use for execution +if [ -x "$(command -v dotnet)" ] && dotnet --version &>/dev/null; then + export DOTNET_EXE="$(command -v dotnet)" +else + # Download install script + DOTNET_INSTALL_FILE="$TEMP_DIRECTORY/dotnet-install.sh" + mkdir -p "$TEMP_DIRECTORY" + curl -Lsfo "$DOTNET_INSTALL_FILE" "$DOTNET_INSTALL_URL" + chmod +x "$DOTNET_INSTALL_FILE" + + # If global.json exists, load expected version + if [[ -f "$DOTNET_GLOBAL_FILE" ]]; then + DOTNET_VERSION=$(FirstJsonValue "version" "$(cat "$DOTNET_GLOBAL_FILE")") + if [[ "$DOTNET_VERSION" == "" ]]; then + unset DOTNET_VERSION + fi + fi + + # Install by channel or version + DOTNET_DIRECTORY="$TEMP_DIRECTORY/dotnet-unix" + if [[ -z ${DOTNET_VERSION+x} ]]; then + "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --channel "$DOTNET_CHANNEL" --no-path + else + "$DOTNET_INSTALL_FILE" --install-dir "$DOTNET_DIRECTORY" --version "$DOTNET_VERSION" --no-path + fi + export DOTNET_EXE="$DOTNET_DIRECTORY/dotnet" +fi + +echo "Microsoft (R) .NET SDK version $("$DOTNET_EXE" --version)" + +"$DOTNET_EXE" build "$BUILD_PROJECT_FILE" /nodeReuse:false /p:UseSharedCompilation=false -nologo -clp:NoSummary --verbosity quiet +"$DOTNET_EXE" run --project "$BUILD_PROJECT_FILE" --no-build -- "$@"