diff --git a/.travis.yml b/.travis.yml index 45257d7..3360899 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,20 +1,28 @@ # https://stackoverflow.com/questions/41509608/how-do-i-deploy-nuget-packages-in-travis-ci +# https://docs.travis-ci.com/user/languages/csharp/ + env: APPNAME=DNX.Helpers CONFIGURATION=Release NUGET_API_URL=https://www.nuget.org/api/v2/package + NUNIT_RUNNERS_VERSION=3.10.0 + language: csharp + solution: $APPNAME.sln + install: - nuget restore $APPNAME.sln - - nuget install NUnit.Runners -Version 3.8.0 -OutputDirectory testrunner -# - nuget install DNX.NuSpec.Updater -OutputDirectory nuspecupdater + - nuget install NUnit.Runners -Version $NUNIT_RUNNERS_VERSION -OutputDirectory testrunner + script: - - xbuild /p:Configuration=$CONFIGURATION $APPNAME.sln - - mono ./testrunner/NUnit.ConsoleRunner.3.8.0/tools/nunit3-console.exe ./Test.$APPNAME/bin/$CONFIGURATION/Test.$APPNAME.dll + # - xbuild /p:Configuration=$CONFIGURATION $APPNAME.sln + - msbuild /p:Configuration=$CONFIGURATION $APPNAME.sln + - mono ./testrunner/NUnit.ConsoleRunner.$NUNIT_RUNNERS_VERSION/tools/nunit3-console.exe ./Test.$APPNAME/bin/$CONFIGURATION/Test.$APPNAME.dll - ls -laR ./$APPNAME -# - nuget pack $APPNAME/$APPNAME.csproj -Verbosity detailed -BasePath $APPNAME -Properties Configuration=$CONFIGURATION - - nuget pack ./$APPNAME/$APPNAME.nuspec -Verbosity detailed + # https://stackoverflow.com/questions/14797525/differences-between-nuget-packing-a-csproj-vs-nuspec + - nuget pack ./$APPNAME/$APPNAME.csproj -Verbosity detailed + deploy: skip_cleanup: true provider: script diff --git a/DNX.Helpers.sln b/DNX.Helpers.sln index cde7741..e4e7080 100644 --- a/DNX.Helpers.sln +++ b/DNX.Helpers.sln @@ -25,6 +25,7 @@ EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".commands", ".commands", "{FB47A44B-A670-480D-8B11-6D02072596D4}" ProjectSection(SolutionItems) = preProject commands.json = commands.json + deploy.sh = deploy.sh GenerateMarkdown.cmd = GenerateMarkdown.cmd NuGet.Pack.cmd = NuGet.Pack.cmd NuGet.Push.cmd = NuGet.Push.cmd @@ -62,6 +63,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{BDB7BF EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Images", "Images", "{ED58C975-9E2F-4720-9634-62BE33EB58B3}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".images", ".images", "{E2FA5B06-E65B-4D0E-86EC-6E9F2EC82A5A}" + ProjectSection(SolutionItems) = preProject + images\favicon-32x32.png = images\favicon-32x32.png + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU diff --git a/DNX.Helpers/DNX.Helpers.nuspec b/DNX.Helpers/DNX.Helpers.nuspec index 17c557d..fb91600 100644 --- a/DNX.Helpers/DNX.Helpers.nuspec +++ b/DNX.Helpers/DNX.Helpers.nuspec @@ -1,22 +1,25 @@ + DNX.Helpers - 1.2.1.0 + 1.2.2 Martin Smith DNX Solutions Ltd - + https://raw.githubusercontent.com/martinsmith1968/DNX.Helpers/master/licence.txt https://github.com/martinsmith1968/DNX.Helpers - http://www.dnx-solutions.co.uk/favicon-32x32.png + https://raw.githubusercontent.com/martinsmith1968/DNX.Helpers/master/images/favicon-32x32.png false .NET Extensions and helpers for Core and Common .NET types - Initial release - Copyright 2016 DNX Solutions Ltd + + Interpolation to a working version and some preparation for moving to .NET Standard + + Copyright 2016 $owners$ DNX helpers extensions string array linq - + \ No newline at end of file diff --git a/DNX.Helpers/Properties/AssemblyInfo.cs b/DNX.Helpers/Properties/AssemblyInfo.cs index 4e85404..046702a 100644 --- a/DNX.Helpers/Properties/AssemblyInfo.cs +++ b/DNX.Helpers/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // 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.2.1.*")] -[assembly: AssemblyFileVersion("1.2.1.0")] +[assembly: AssemblyVersion("1.2.2.*")] +[assembly: AssemblyFileVersion("1.2.2.0")] diff --git a/NuGet.Pack.cmd b/NuGet.Pack.cmd index df76bc6..9e3035b 100644 --- a/NuGet.Pack.cmd +++ b/NuGet.Pack.cmd @@ -16,4 +16,6 @@ CALL SetNuGetServerAPIKey.cmd "%APPNAME%" IF EXIST *.nupkg DEL *.nupkg +@ECHO ON "%NUGETEXE%" pack "%SCRIPTPATH%\%APPNAME%\%APPNAME%.csproj" +@ECHO OFF diff --git a/NuGet.Push.cmd b/NuGet.Push.cmd index 461b68e..f6a7367 100644 --- a/NuGet.Push.cmd +++ b/NuGet.Push.cmd @@ -18,5 +18,7 @@ CALL SetNuGetServerAPIKey.cmd "%APPNAME%" FOR %%F IN (*.nupkg) DO ( ECHO.Pushing: %%~F + @ECHO ON %NUGETEXE% push "%%~F" -Source "%NUGETSERVERAPIURL%" -ApiKey "%NUGETSERVERAPIKEY%" + @ECHO OFF ) diff --git a/Test.DNX.Helpers/Assemblies/AssemblyDetailsTests.cs b/Test.DNX.Helpers/Assemblies/AssemblyDetailsTests.cs index 9f70c12..36841fa 100644 --- a/Test.DNX.Helpers/Assemblies/AssemblyDetailsTests.cs +++ b/Test.DNX.Helpers/Assemblies/AssemblyDetailsTests.cs @@ -35,6 +35,7 @@ public void AssemblyDetails_created_from_current_assembly() assemblyDetails.Version.ShouldBe(targetAssembly.GetName().Version); assemblyDetails.FileVersion.ShouldBe(targetAssembly.GetCustomAttributes().First().Version); assemblyDetails.InformationalVersion.ShouldBe(targetAssembly.GetCustomAttributes().First().InformationalVersion); + assemblyDetails.SimplifiedVersion.ShouldBe(assemblyDetails.Version.Simplify()); } [Test] @@ -63,6 +64,7 @@ public void AssemblyDetails_created_from_specific_assembly() assemblyDetails.Version.ShouldBe(targetAssembly.GetName().Version); assemblyDetails.FileVersion.ShouldBe(targetAssembly.GetCustomAttributes().First().Version); assemblyDetails.InformationalVersion.ShouldBeNull(); + assemblyDetails.SimplifiedVersion.ShouldBe(assemblyDetails.Version.Simplify()); } } } diff --git a/Test.DNX.Helpers/Assemblies/AssemblyExtensionsTests.cs b/Test.DNX.Helpers/Assemblies/AssemblyExtensionsTests.cs index 9aa9dab..da4fc90 100644 --- a/Test.DNX.Helpers/Assemblies/AssemblyExtensionsTests.cs +++ b/Test.DNX.Helpers/Assemblies/AssemblyExtensionsTests.cs @@ -1,6 +1,7 @@ using System.Linq; using System.Reflection; using DNX.Helpers.Assemblies; +using NUnit.Framework; using Shouldly; // ReSharper disable InconsistentNaming @@ -24,6 +25,7 @@ public class InstanceResolutionExtensionsTests { public class GetTypesThatImplementInterface_ITypeA { + [Test] public void FindTypesThatImplementType_should_find_all_that_implement_interface() { // Act @@ -31,7 +33,8 @@ public void FindTypesThatImplementType_should_find_all_that_implement_interface( // Assert result.ShouldNotBeNull(); - result.Count.ShouldBe(6); + result.Count.ShouldBe(7); + result.Count(x => x == typeof(ITypeA)).ShouldBe(1); result.Count(x => x == typeof(ITypeD)).ShouldBe(1); result.Count(x => x == typeof(CTypeA)).ShouldBe(1); result.Count(x => x == typeof(CTypeD)).ShouldBe(1); @@ -40,6 +43,7 @@ public void FindTypesThatImplementType_should_find_all_that_implement_interface( result.Count(x => x == typeof(CTypeCA)).ShouldBe(1); } + [Test] public void FindConcreteTypesThatImplementType_should_find_all_that_implement_interface() { // Act @@ -55,6 +59,7 @@ public void FindConcreteTypesThatImplementType_should_find_all_that_implement_in result.Count(x => x == typeof(CTypeCA)).ShouldBe(1); } + [Test] public void CreateInstancesOfClassesThatImplementInterface_should_create_instances_for_all_that_implement_interface() { // Act diff --git a/Test.DNX.Helpers/Assemblies/VersionExtensionsTests.cs b/Test.DNX.Helpers/Assemblies/VersionExtensionsTests.cs index 027b5f2..58de6c3 100644 --- a/Test.DNX.Helpers/Assemblies/VersionExtensionsTests.cs +++ b/Test.DNX.Helpers/Assemblies/VersionExtensionsTests.cs @@ -1,6 +1,7 @@ using System; using DNX.Helpers.Assemblies; using NUnit.Framework; +using Shouldly; namespace Test.DNX.Helpers.Assemblies { @@ -41,5 +42,18 @@ public bool Simplify_GuardException_Tests(int major, int minor, int build, int r return false; } } + + [Test] + public void Simplify_for_null_returns_expected() + { + // Arrange + Version version = null; + + // Act + var result = version.Simplify(); + + // Assert + result.ShouldBeNull(); + } } } diff --git a/Test.DNX.Helpers/Dates/DateTimeExtensionsTests.cs b/Test.DNX.Helpers/Dates/DateTimeExtensionsTests.cs index 94789f9..3ae6b46 100644 --- a/Test.DNX.Helpers/Dates/DateTimeExtensionsTests.cs +++ b/Test.DNX.Helpers/Dates/DateTimeExtensionsTests.cs @@ -19,19 +19,16 @@ public object GetFormat(Type formatType) public string Format(string format, object arg, IFormatProvider formatProvider) { - if (arg is DateTime) + if (arg is DateTime dt) { - var dt = (DateTime) arg; - // if user supplied own format use it return string.IsNullOrEmpty(format) ? dt.ToString(FormatString) - : ((DateTime)arg).ToString(format); + : dt.ToString(format); } // format everything else normally - var formattable = arg as IFormattable; - return formattable != null + return arg is IFormattable formattable ? formattable.ToString(format, formatProvider) : arg.ToString(); } diff --git a/Test.DNX.Helpers/Properties/AssemblyInfo.cs b/Test.DNX.Helpers/Properties/AssemblyInfo.cs index 35b29ac..58d1e2f 100644 --- a/Test.DNX.Helpers/Properties/AssemblyInfo.cs +++ b/Test.DNX.Helpers/Properties/AssemblyInfo.cs @@ -31,6 +31,6 @@ // 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.2.1")] -[assembly: AssemblyFileVersion("1.2.1.0")] -[assembly: AssemblyInformationalVersion("1.2.1.0")] +[assembly: AssemblyVersion("1.2.2")] +[assembly: AssemblyFileVersion("1.2.2.0")] +[assembly: AssemblyInformationalVersion("1.2.2.0")] diff --git a/Test.DNX.Helpers/Strings/Interpolation/StringInterpolatorTests.cs b/Test.DNX.Helpers/Strings/Interpolation/StringInterpolatorTests.cs index 3cb96f2..182c1a8 100644 --- a/Test.DNX.Helpers/Strings/Interpolation/StringInterpolatorTests.cs +++ b/Test.DNX.Helpers/Strings/Interpolation/StringInterpolatorTests.cs @@ -67,6 +67,32 @@ public void InterpolateWithAll_Environment_SpecialFolders() result.ShouldBe(string.Concat(Environment.GetFolderPath(Environment.SpecialFolder.System), "\\Shell32.dll")); } + [Test] + public void InterpolateWithAll_Environment_Folders() + { + // Arrange + var folderLocations = new Dictionary() + { + { nameof(Environment.SystemDirectory), Environment.SystemDirectory }, + { nameof(Environment.CurrentDirectory), Environment.CurrentDirectory }, + { $"{nameof(Environment.SpecialFolder)}.{nameof(Environment.SpecialFolder.Windows)}", Environment.GetFolderPath(Environment.SpecialFolder.Windows) }, + { $"{nameof(Environment.SpecialFolder)}.{nameof(Environment.SpecialFolder.Personal)}", Environment.GetFolderPath(Environment.SpecialFolder.Personal) } + }; + + var interpolationInstances = new[] + { + new NamedInstance(folderLocations, nameof(Environment)), + }; + + var text = "{Environment.SystemDirectory}\\Shell32.dll"; + + // Act + var result = text.InterpolateWithAll(interpolationInstances); + + // Assert + result.ShouldBe(string.Concat(Environment.SystemDirectory, "\\Shell32.dll")); + } + [TestCase("{One}{Two}{Three}{Four}{Five}", "12345")] public void InterpolateWithAll_Dictionary(string text, string expectedValue) { @@ -157,5 +183,39 @@ public void InterpolateWithAll_FileName_Test() result.ShouldNotBeNull(); result.ShouldBe(string.Concat(Environment.GetFolderPath(specialFolder), "\\", myFileName)); } + + [Test] + public void InterpolateWithAll_null_dictionary() + { + // Arrange + const string myFileName = "myFileName.txt"; + var specialFolder = Environment.SpecialFolder.CommonProgramFiles; + var fileName = $"{{Environment.{specialFolder}}}\\{myFileName}"; + + IDictionary dict = null; + + // Act + var result = fileName.InterpolateWithAll(dict); + + // Assert + result.ShouldBe(fileName); + } + + [Test] + public void InterpolateWithAll_empty_dictionary() + { + // Arrange + const string myFileName = "myFileName.txt"; + var specialFolder = Environment.SpecialFolder.CommonProgramFiles; + var fileName = $"{{Environment.{specialFolder}}}\\{myFileName}"; + + var dict = new Dictionary(); + + // Act + var result = fileName.InterpolateWithAll(dict); + + // Assert + result.ShouldBe(fileName); + } } } diff --git a/Test.DNX.Helpers/Strings/StringExtensionsTests.cs b/Test.DNX.Helpers/Strings/StringExtensionsTests.cs index 55685d8..709ccc9 100644 --- a/Test.DNX.Helpers/Strings/StringExtensionsTests.cs +++ b/Test.DNX.Helpers/Strings/StringExtensionsTests.cs @@ -337,10 +337,6 @@ public bool Test_IsValidNumber_default_culture(string text, string cultureInfoNa return result; } - catch (Exception e) - { - throw; - } finally { CultureInfo.DefaultThreadCurrentCulture = previousCulture; diff --git a/deploy.sh b/deploy.sh index 655777f..0188d59 100644 --- a/deploy.sh +++ b/deploy.sh @@ -4,4 +4,3 @@ NUGET_API_KEY=$3 echo nuget push $APPNAME.*.nupkg -Source $NUGET_API_URL -ApiKey secret nuget push $APPNAME.*.nupkg -Source $NUGET_API_URL -ApiKey $NUGET_API_KEY - \ No newline at end of file diff --git a/readme.md b/readme.md index 152b1ad..9728683 100644 --- a/readme.md +++ b/readme.md @@ -1,5 +1,7 @@ # DNX.Helpers +Built by [Travis CI](https://travis-ci.org/) ![Build Status](https://travis-ci.org/martinsmith1968/DNX.Helpers.svg?branch=master) + ![DNX Solutions Logo](images/favicon-32x32.png) [DNX.Helpers](http://github.com/martinsmith1968/DNX.Helpers) is a .NET package that contains the bits that I've found lacking or missing from the .NET standard library. It has minimal dependencies on other packages and so is designed to be included to your projects with little or no disruption. @@ -78,3 +80,19 @@ By Martin Smith, 2001 onwards | [DNX.Helpers.Console](http://github.com/martinsmith1968/DNX.Helpers.Console) | For working with console applications | | [DNX.Helpers.CommandLine](http://github.com/martinsmith1968/DNX.Helpers.CommandLine) | For working with Command Line parsing | | [DNX.Helpers.Log4Net](http://github.com/martinsmith1968/DNX.Helpers.Log4Net) | For working with Log4Net | + +### Acknowledgements + +With grateful thanks to all the people and organisations below, who've contributed something to either +make the development of this easier, or generally contributed to making [Visual Studio](https://visualstudio.microsoft.com/) an awesome environment: + +| Title | Description | +|---|----| +| [Resharper Ultimate](https://www.jetbrains.com/resharper) | The guys at [JetBrains](https://www.jetbrains.com) make awesome tools for whatever your development language of preference. Visual Studio would not be complete without Resharper Ultimate | +| [Travis CI](https://travis-ci.org) | A cloud Continuous Integration environment that's easy to integrate with and is still as feature rich as you could need. Your builds have caught my lack of cross-platform awareness more than once | +| [GhostDoc Pro](https://submain.com/download/ghostdoc/pro/) | Good intellisense is key to almost any library and GhostDoc generates sensible documentation at the touch of a button. A community edition is also available for free | +| [BuildVision](https://github.com/StefanKert/BuildVision) | For multi-project solutions, this is the __best__ build visualizer. Can't wait for a VS 2019 version | +| [VSColorOutput](https://github.com/mike-ward/VSColorOutput) | Bring colour to your output window. Don't forget to donate... | +| [Automatic Versions](https://www.precisioninfinity.com/software-development-productivity-improvement/business-software-tools/automatic-versions-extension-for-visual-studio/) | A recent addition to my toolset, this is awesome at controlling my versioning for releases | +| [Mads Kristensen](https://marketplace.visualstudio.com/publishers/MadsKristensen) | Last but by no means least, a huge thank you to Mads at Microsoft for some brilliant time saving tools that make Visual Studio just that little bit more brilliant (E.g. [Markdown Editor](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.MarkdownEditor), [Add New File](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.AddNewFile), [Task Runner Explorer](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.TaskRunnerExplorer) | +| [Microsoft DevLabs](https://marketplace.visualstudio.com/publishers/Microsoft%20DevLabs) | Not sure why some of these aren't part of Visual Studio from the start but kudos to Microsoft for releasing them. Some excellent productivity enhancers here (E.g. [Fix Mixed Tabs](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.FixMixedTabs), [Align Assignments](https://marketplace.visualstudio.com/items?itemName=VisualStudioPlatformTeam.AlignAssignments) |