From 03b00e8e996f56b9b5a114c8797d8f0ceb3bca2c Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 14 Jul 2017 12:55:33 +0300 Subject: [PATCH] Fixed MS Test Issue and add cross platform for new lines. -Fixed to handle cross platform new lines; -Addressed MSTest but which required setting the initial directory to be the location of the assembly (required due to bug - see See https://github.com/Microsoft/vstest/issues/311) --- src/Chapter14.Tests/Chapter14.Tests.csproj | Bin 1818 -> 1958 bytes ...WithSystem.Linq.Enumerable.Select.Tests.cs | 17 ++++++++++++++--- .../Listing14.16.ProjectionToTuple.Tests.cs | 9 ++++++--- ...17.ExecutingLinqQueriesInParallel.Tests.cs | 8 +++++--- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Chapter14.Tests/Chapter14.Tests.csproj b/src/Chapter14.Tests/Chapter14.Tests.csproj index 1ab5ba845f0c44bb4fbfe087af44393946e584c9..b69097c77bdcf3fb4f22a490d7b46aba4bb3ff41 100644 GIT binary patch delta 82 zcmbQmw~T*763gUM%vO%U43!MU3?&Sy47m(?3_(CTjUfj}CIiJX8S)wO7?c @@ -20,13 +30,14 @@ public void Listing14_15_Test() Program.ChapterMain(); }); - IEnumerable outputItems = output.Split('\n'); + IEnumerable outputItems = output.Split( + new string[] { Environment.NewLine }, StringSplitOptions.None); Assert.AreEqual( expectedItemCount, outputItems.Count()); foreach (string item in outputItems) { - Assert.IsTrue(item.IsLike(expectedPattern)); + Assert.IsTrue(item.IsLike(expectedPattern, '?')); } } } diff --git a/src/Chapter14.Tests/Listing14.16.ProjectionToTuple.Tests.cs b/src/Chapter14.Tests/Listing14.16.ProjectionToTuple.Tests.cs index 4005a02fe..bbcdf8d0e 100644 --- a/src/Chapter14.Tests/Listing14.16.ProjectionToTuple.Tests.cs +++ b/src/Chapter14.Tests/Listing14.16.ProjectionToTuple.Tests.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.IO; +using System; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_16.Tests { @@ -12,7 +13,7 @@ public class ProgramTests [TestMethod] public void ProjectionToAnAnonymousType() { - string expectedPattern = "FileName = *, Size = "; + string expectedPattern = "FileName = *, Size = *"; int expectedItemCount = Directory.EnumerateFiles( Directory.GetCurrentDirectory(), "*").Count(); @@ -21,12 +22,14 @@ public void ProjectionToAnAnonymousType() Program.ChapterMain(); }); - IEnumerable outputItems = output.Split('\n'); + IEnumerable outputItems = output.Split( + new string[] { Environment.NewLine }, StringSplitOptions.None); Assert.AreEqual(expectedItemCount, outputItems.Count()); foreach (string item in outputItems) { - Assert.IsTrue(item.IsLike(expectedPattern)); + Assert.IsTrue(item.IsLike(expectedPattern), + $"{item} is not like {expectedPattern}"); } } } diff --git a/src/Chapter14.Tests/Listing14.17.ExecutingLinqQueriesInParallel.Tests.cs b/src/Chapter14.Tests/Listing14.17.ExecutingLinqQueriesInParallel.Tests.cs index d55e3b0d3..5128f3d7c 100644 --- a/src/Chapter14.Tests/Listing14.17.ExecutingLinqQueriesInParallel.Tests.cs +++ b/src/Chapter14.Tests/Listing14.17.ExecutingLinqQueriesInParallel.Tests.cs @@ -13,7 +13,7 @@ public class ProgramTests [TestMethod] public void ProjectionWithLinqsSelect() { - string expectedPattern = "{ FileName = *, Size = "; + string expectedPattern = "{ FileName = *, Size = * }"; int expectedItemCount = Directory.EnumerateFiles( Directory.GetCurrentDirectory(), "*").Count(); string output = ConsoleAssert.Execute(null, () => @@ -21,12 +21,14 @@ public void ProjectionWithLinqsSelect() Program.ChapterMain(); }); - IEnumerable outputItems = output.Split('\n'); + IEnumerable outputItems = output.Split( + new string[] { Environment.NewLine }, StringSplitOptions.None); Assert.AreEqual(expectedItemCount, outputItems.Count()); foreach (string item in outputItems) { - Assert.IsTrue(item.IsLike(expectedPattern)); + Assert.IsTrue(item.IsLike(expectedPattern), + $"{item} is not like {expectedPattern}"); } } }