From 1a42f47b00f079993f1a77039b5b955426b912d4 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Wed, 7 Sep 2022 00:54:17 -0700 Subject: [PATCH 01/56] Added some test generated directories that should be ignored. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 492ad5450..b378e23b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,7 @@ # Files specific to this project: *.encrypt # Generated by one of the projects and left around on occasion. +src/Chapter10/ProcessExitTestProgram/ +HelloWorld/ # Don't ignore DLLs in the src/Shared/Lib folder (which are frequently ignored by default in the .gitignore_global file) !src/Shared/Lib/* From 888737805b201cca01ade5109902f992440f57a4 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 9 Sep 2022 15:28:55 -0700 Subject: [PATCH 02/56] Added top level statement and refactored PowerShellTestsUtilities --- src/Chapter01.Tests/Listing01.01.Tests.cs | 2 +- src/Chapter01/Listing01.01.HelloWorldInC#.ps1 | 3 +- src/Chapter01/Listing01.01A.HelloWorldInC#.cs | 5 ++ ...nC#.cs => Listing01.01B.HelloWorldInC#.cs} | 2 +- ...ngTypesAvailableOutsideAnAssembly.Tests.cs | 19 ++---- ...isteringAFinalizerWithProcessExit.Tests.cs | 14 ++--- .../PowerShellTestsUtilities.cs | 59 +++++++++++++------ src/Chapter10/Chapter10.csproj | 5 ++ 8 files changed, 63 insertions(+), 46 deletions(-) create mode 100644 src/Chapter01/Listing01.01A.HelloWorldInC#.cs rename src/Chapter01/{Listing01.01.HelloWorldInC#.cs => Listing01.01B.HelloWorldInC#.cs} (96%) diff --git a/src/Chapter01.Tests/Listing01.01.Tests.cs b/src/Chapter01.Tests/Listing01.01.Tests.cs index 36c4583b7..24a9d8368 100644 --- a/src/Chapter01.Tests/Listing01.01.Tests.cs +++ b/src/Chapter01.Tests/Listing01.01.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01.Tests +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01B.Tests { [TestClass] public class HelloWorldTests diff --git a/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 b/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 index 9a394df2a..fc2ec8d94 100644 --- a/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 +++ b/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 @@ -22,14 +22,13 @@ try { Set-Location ./HelloWorld/ dotnet new console Get-Content Program.cs - dotnet run $codeListing = @" class HelloWorld { static void Main() { - System.Console.WriteLine("Hello. My name is Inigo Montoya."); + Console.WriteLine("Hello. My name is Inigo Montoya."); } } "@ diff --git a/src/Chapter01/Listing01.01A.HelloWorldInC#.cs b/src/Chapter01/Listing01.01A.HelloWorldInC#.cs new file mode 100644 index 000000000..a500fba10 --- /dev/null +++ b/src/Chapter01/Listing01.01A.HelloWorldInC#.cs @@ -0,0 +1,5 @@ + +#region INCLUDE +System.Console.WriteLine("Hello. My name is Inigo Montoya."); +#endregion INCLUDE + diff --git a/src/Chapter01/Listing01.01.HelloWorldInC#.cs b/src/Chapter01/Listing01.01B.HelloWorldInC#.cs similarity index 96% rename from src/Chapter01/Listing01.01.HelloWorldInC#.cs rename to src/Chapter01/Listing01.01B.HelloWorldInC#.cs index a7328ede9..11b529695 100644 --- a/src/Chapter01/Listing01.01.HelloWorldInC#.cs +++ b/src/Chapter01/Listing01.01B.HelloWorldInC#.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01B { #region INCLUDE public class HelloWorld diff --git a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs index 4d635a222..38b4c89b8 100644 --- a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs +++ b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs @@ -14,26 +14,15 @@ public class TypeTests [TestMethod] public void MakingTypesAvailableExternallyPS1_ExitCodeIs0() { - if (PowerShellTestsUtilities.PowerShellNotInstalled()) Assert.Inconclusive("Powershell not installed"); + if (PowerShellTestsUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); //EssentialCSharp\\src\\Chapter10.Tests\\bin\\Debug\\netcoreapp3.0 string ps1Path = Path.GetFullPath("../../../../Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1", Environment.CurrentDirectory); string traceValue = "0"; - string nameOfPowershellTool; - if (PowerShellTestsUtilities.WindowsEnvironment()) nameOfPowershellTool = "powershell"; - else nameOfPowershellTool = "pwsh"; - - System.Diagnostics.Process powerShell = System.Diagnostics.Process.Start(nameOfPowershellTool, $"-noprofile -command \"{ps1Path} {traceValue}\""); - powerShell.WaitForExit(); - - Assert.AreEqual(0, powerShell.ExitCode); - } - - private static bool NotWindows() - { - return !RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + int exitCode = PowerShellTestsUtilities.RunPowerShellScript(ps1Path, traceValue); + + Assert.AreEqual(0, exitCode); } - } } diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index db0cb5754..19d785ae4 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -8,12 +8,11 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_23.Tests { [TestClass] - public class DisposeTests { static string Ps1Path { get; } = Path.GetFullPath("../../../../Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); - static bool PowerShellNotAvailable = PowerShellTestsUtilities.PowerShellNotInstalled(); + static bool PowerShellNotAvailable = PowerShellTestsUtilities.PowerShellNotInstalled; static string PowershellEnvironmentVariableName { get; set; } = "powershell"; [ClassInitialize] @@ -49,15 +48,10 @@ public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrde string traceValue = "0"; string testStatus = "run"; - var powershell = new Process(); - powershell.StartInfo.RedirectStandardOutput = true; - powershell.StartInfo.FileName = PowershellEnvironmentVariableName; - powershell.StartInfo.Arguments = $"-noprofile -command \"{Ps1Path} {traceValue} {finalizerOrderOption} {testStatus}\""; - powershell.Start(); - string psOutput = powershell.StandardOutput.ReadToEnd(); - powershell.WaitForExit(); + int exitCode = PowerShellTestsUtilities.RunPowerShellScript( + Ps1Path, $"{traceValue} {finalizerOrderOption} {testStatus}", out string psOutput); - Assert.AreEqual(0, powershell.ExitCode); + Assert.AreEqual(0, exitCode); Assert.AreEqual(RemoveWhiteSpace(expectedOutput), RemoveWhiteSpace(psOutput)); } diff --git a/src/Chapter10.Tests/PowerShellTestsUtilities.cs b/src/Chapter10.Tests/PowerShellTestsUtilities.cs index c03aee279..618d95bd5 100644 --- a/src/Chapter10.Tests/PowerShellTestsUtilities.cs +++ b/src/Chapter10.Tests/PowerShellTestsUtilities.cs @@ -1,6 +1,8 @@ using System; using System.Runtime.InteropServices; using System.Diagnostics; +using System.Linq; +using System.Collections.Generic; namespace Chapter10.Tests.PowerShellTestsUtilities { @@ -11,37 +13,60 @@ public static bool WindowsEnvironment() return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); } - public static bool PowerShellNotInstalled() + + public static Lazy _PowerShellCommand = new Lazy(() => { - var environmentVariables = Environment.GetEnvironmentVariables().Values; - bool result = true; - foreach (string? value in environmentVariables) + string? powershellCommand = WindowsEnvironment() ? "powershell" : null; + + IEnumerable? environmentVariables = Environment.GetEnvironmentVariables().Values.Cast(); + + if(environmentVariables.Any(item => item.ToLowerInvariant().Contains("pwsh"))) { - if (!string.IsNullOrEmpty(value) && (value.ToLowerInvariant().Contains("powershell") || value.ToLowerInvariant().Contains("pwsh"))) - { - result = false; - } + powershellCommand = "pwsh"; } - if (result == true) + + if (powershellCommand is not null) { - string PowershellEnvironmentVariableName = "powershell"; - if (!PowerShellTestsUtilities.WindowsEnvironment()) PowershellEnvironmentVariableName = "pwsh"; + // Verify that the PowerShell command executes successfully. try { - Process powershell = Process.Start(PowershellEnvironmentVariableName, "--version"); + Process powershell = Process.Start(powershellCommand, "-h"); powershell.WaitForExit(); var exitCode = powershell.ExitCode; - if(exitCode == 0) + if (exitCode != 0) { - result = false; + powershellCommand = null; } } - catch(System.ComponentModel.Win32Exception) + catch (System.ComponentModel.Win32Exception) { - result = true; + powershellCommand = null; } } - return result; + return powershellCommand; + }); + public static int RunPowerShellScript(string scriptPath, string arguments) => + RunPowerShellScript(scriptPath, arguments, out string psOutput); + + public static int RunPowerShellScript(string scriptPath, string arguments, out string psOutput) + { + if(PowerShellCommand is null) + { + throw new InvalidOperationException("PowerShell is not installed"); + } + + using var powerShell = new Process(); + powerShell.StartInfo.RedirectStandardOutput = true; + powerShell.StartInfo.FileName = PowerShellCommand; + powerShell.StartInfo.Arguments = $"-noprofile -command \"{scriptPath} {arguments}\""; + powerShell.Start(); + psOutput = powerShell.StandardOutput.ReadToEnd(); + powerShell.WaitForExit(); + + return powerShell.ExitCode; } + + public static string? PowerShellCommand => _PowerShellCommand!.Value; + public static bool PowerShellNotInstalled =>_PowerShellCommand.Value == null; } } diff --git a/src/Chapter10/Chapter10.csproj b/src/Chapter10/Chapter10.csproj index 63d041d66..094398787 100644 --- a/src/Chapter10/Chapter10.csproj +++ b/src/Chapter10/Chapter10.csproj @@ -9,6 +9,11 @@ $(IgnoredWarnings) + + + + + Program.cs From 6599558f04ab45918e8691090b9af682f6dc3028 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sun, 25 Sep 2022 21:43:31 -0700 Subject: [PATCH 03/56] Refactored PowerShellTestsUtilities into a solution shared file. --- EssentialCSharp.sln | 8 +++++ src/Chapter10.Tests/Chapter10.Tests.csproj | 3 ++ ...ngTypesAvailableOutsideAnAssembly.Tests.cs | 3 +- ...isteringAFinalizerWithProcessExit.Tests.cs | 30 ++----------------- .../Tests}/PowerShellTestsUtilities.cs | 9 ++++-- 5 files changed, 21 insertions(+), 32 deletions(-) rename src/{Chapter10.Tests => Shared/Tests}/PowerShellTestsUtilities.cs (89%) diff --git a/EssentialCSharp.sln b/EssentialCSharp.sln index 6f6d5c30e..d5b850043 100644 --- a/EssentialCSharp.sln +++ b/EssentialCSharp.sln @@ -119,6 +119,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chapter23", "src\Chapter23\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chapter23.Tests", "src\Chapter23.Tests\Chapter23.Tests.csproj", "{21342ABB-E09B-459F-8405-33743DC90EF6}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{22D1D24E-29B7-478D-ADBA-0F4836D3857A}" + ProjectSection(SolutionItems) = preProject + src\Shared\Tests\PowerShellTestsUtilities.cs = src\Shared\Tests\PowerShellTestsUtilities.cs + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -685,6 +690,9 @@ Global GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {22D1D24E-29B7-478D-ADBA-0F4836D3857A} = {91698F73-19EB-4531-980C-5B8B76DC28C9} + EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {712ED6C0-5F52-4F27-B3D2-B0273E92F5F0} EndGlobalSection diff --git a/src/Chapter10.Tests/Chapter10.Tests.csproj b/src/Chapter10.Tests/Chapter10.Tests.csproj index ef4aa5d81..f04422391 100644 --- a/src/Chapter10.Tests/Chapter10.Tests.csproj +++ b/src/Chapter10.Tests/Chapter10.Tests.csproj @@ -3,6 +3,9 @@ Chapter10.Tests + + + diff --git a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs index 38b4c89b8..2968b1116 100644 --- a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs +++ b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs @@ -1,5 +1,4 @@ -using Chapter10.Tests.CustomTestAttributes; -using Chapter10.Tests.PowerShellTestsUtilities; +using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.IO; diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 19d785ae4..0fc8e1bfc 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -2,7 +2,8 @@ using System; using System.Diagnostics; using System.IO; -using Chapter10.Tests.PowerShellTestsUtilities; +using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; + using System.Text.RegularExpressions; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_23.Tests @@ -10,32 +11,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_23.Tests [TestClass] public class DisposeTests { - static string Ps1Path { get; } = Path.GetFullPath("../../../../Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); - static bool PowerShellNotAvailable = PowerShellTestsUtilities.PowerShellNotInstalled; - static string PowershellEnvironmentVariableName { get; set; } = "powershell"; - - [ClassInitialize] - public static void ClassInitialize(TestContext testContext) - { - if (PowerShellNotAvailable) { Assert.Inconclusive("Powershell not installed"); return; } - - if (PowerShellTestsUtilities.WindowsEnvironment()) PowershellEnvironmentVariableName = "powershell"; - else PowershellEnvironmentVariableName = "pwsh"; - - string testStatus = "create"; - Process powershell = Process.Start(PowershellEnvironmentVariableName, $"-noprofile -command \"{Ps1Path} 0 null {testStatus}\""); - powershell.WaitForExit(); - } - - [ClassCleanup] - public static void RemoveProcessExitProj() - { - if (PowerShellNotAvailable) { return; } - string testStatus = "cleanup"; - Process powershell = Process.Start(PowershellEnvironmentVariableName, $"-noprofile -command \"{Ps1Path} 0 null {testStatus}\""); - powershell.WaitForExit(); - } [DataTestMethod] [DataRow("processExit", FinalizerRegisteredWithProcessExit, DisplayName = "Finalizer Registered With ProcessExit")] @@ -43,8 +19,6 @@ public static void RemoveProcessExitProj() [DataRow("gc", GCCalled, DisplayName = "Garbage Collected called")] public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrderOption, string expectedOutput) { - if (PowerShellNotAvailable) { Assert.Inconclusive("Powershell not installed"); return; } - string traceValue = "0"; string testStatus = "run"; diff --git a/src/Chapter10.Tests/PowerShellTestsUtilities.cs b/src/Shared/Tests/PowerShellTestsUtilities.cs similarity index 89% rename from src/Chapter10.Tests/PowerShellTestsUtilities.cs rename to src/Shared/Tests/PowerShellTestsUtilities.cs index 618d95bd5..af3159eac 100644 --- a/src/Chapter10.Tests/PowerShellTestsUtilities.cs +++ b/src/Shared/Tests/PowerShellTestsUtilities.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Collections.Generic; -namespace Chapter10.Tests.PowerShellTestsUtilities +namespace AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests { - class PowerShellTestsUtilities + public class PowerShellTestsUtilities { public static bool WindowsEnvironment() { @@ -55,6 +55,11 @@ public static int RunPowerShellScript(string scriptPath, string arguments, out s throw new InvalidOperationException("PowerShell is not installed"); } + if(!System.IO.File.Exists(scriptPath)) + { + throw new InvalidOperationException($"scriptPath, '{scriptPath}', not found."); + } + using var powerShell = new Process(); powerShell.StartInfo.RedirectStandardOutput = true; powerShell.StartInfo.FileName = PowerShellCommand; From ce65ab1699ad4a08e8fcd525b28ca3654a1e970c Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sun, 25 Sep 2022 21:52:20 -0700 Subject: [PATCH 04/56] Minor rename of PowerShellTestUtilities --- EssentialCSharp.sln | 2 +- src/Chapter10.Tests/Chapter10.Tests.csproj | 2 +- ...isting10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs | 4 ++-- ...Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 2 +- ...PowerShellTestsUtilities.cs => PowerShellTestUtilities.cs} | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) rename src/Shared/Tests/{PowerShellTestsUtilities.cs => PowerShellTestUtilities.cs} (98%) diff --git a/EssentialCSharp.sln b/EssentialCSharp.sln index d5b850043..e8c41d8f5 100644 --- a/EssentialCSharp.sln +++ b/EssentialCSharp.sln @@ -121,7 +121,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chapter23.Tests", "src\Chap EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{22D1D24E-29B7-478D-ADBA-0F4836D3857A}" ProjectSection(SolutionItems) = preProject - src\Shared\Tests\PowerShellTestsUtilities.cs = src\Shared\Tests\PowerShellTestsUtilities.cs + src\Shared\Tests\PowerShellTestUtilities.cs = src\Shared\Tests\PowerShellTestUtilities.cs EndProjectSection EndProject Global diff --git a/src/Chapter10.Tests/Chapter10.Tests.csproj b/src/Chapter10.Tests/Chapter10.Tests.csproj index f04422391..12a7dbcd3 100644 --- a/src/Chapter10.Tests/Chapter10.Tests.csproj +++ b/src/Chapter10.Tests/Chapter10.Tests.csproj @@ -4,7 +4,7 @@ - + diff --git a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs index 2968b1116..864c0fa7c 100644 --- a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs +++ b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs @@ -13,12 +13,12 @@ public class TypeTests [TestMethod] public void MakingTypesAvailableExternallyPS1_ExitCodeIs0() { - if (PowerShellTestsUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); + if (PowerShellTestUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); //EssentialCSharp\\src\\Chapter10.Tests\\bin\\Debug\\netcoreapp3.0 string ps1Path = Path.GetFullPath("../../../../Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1", Environment.CurrentDirectory); string traceValue = "0"; - int exitCode = PowerShellTestsUtilities.RunPowerShellScript(ps1Path, traceValue); + int exitCode = PowerShellTestUtilities.RunPowerShellScript(ps1Path, traceValue); Assert.AreEqual(0, exitCode); } diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 0fc8e1bfc..adb9270d8 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -22,7 +22,7 @@ public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrde string traceValue = "0"; string testStatus = "run"; - int exitCode = PowerShellTestsUtilities.RunPowerShellScript( + int exitCode = PowerShellTestUtilities.RunPowerShellScript( Ps1Path, $"{traceValue} {finalizerOrderOption} {testStatus}", out string psOutput); Assert.AreEqual(0, exitCode); diff --git a/src/Shared/Tests/PowerShellTestsUtilities.cs b/src/Shared/Tests/PowerShellTestUtilities.cs similarity index 98% rename from src/Shared/Tests/PowerShellTestsUtilities.cs rename to src/Shared/Tests/PowerShellTestUtilities.cs index af3159eac..c67cc96ae 100644 --- a/src/Shared/Tests/PowerShellTestsUtilities.cs +++ b/src/Shared/Tests/PowerShellTestUtilities.cs @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests { - public class PowerShellTestsUtilities + public class PowerShellTestUtilities { public static bool WindowsEnvironment() { From bbcde0bd7e0483832d2d96136720677baf4f4832 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 26 Sep 2022 13:16:32 -0700 Subject: [PATCH 05/56] Excluded "HelloWorld" files Also removed top level statement (which wasn't needed in this branch) --- src/Chapter01/Chapter01.csproj | 3 +++ src/Chapter01/Listing01.01A.HelloWorldInC#.cs | 5 ----- 2 files changed, 3 insertions(+), 5 deletions(-) delete mode 100644 src/Chapter01/Listing01.01A.HelloWorldInC#.cs diff --git a/src/Chapter01/Chapter01.csproj b/src/Chapter01/Chapter01.csproj index 2f419867e..3339908c9 100644 --- a/src/Chapter01/Chapter01.csproj +++ b/src/Chapter01/Chapter01.csproj @@ -11,6 +11,8 @@ + + @@ -21,6 +23,7 @@ + diff --git a/src/Chapter01/Listing01.01A.HelloWorldInC#.cs b/src/Chapter01/Listing01.01A.HelloWorldInC#.cs deleted file mode 100644 index a500fba10..000000000 --- a/src/Chapter01/Listing01.01A.HelloWorldInC#.cs +++ /dev/null @@ -1,5 +0,0 @@ - -#region INCLUDE -System.Console.WriteLine("Hello. My name is Inigo Montoya."); -#endregion INCLUDE - From 71540fb83279f276d27f751dca88b2515013142b Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Tue, 27 Sep 2022 10:45:36 -0700 Subject: [PATCH 06/56] PowerShell Core by Default Switched to use PowerShell core by default and to test for PowerShell by executing the PowerShell comment. --- src/Shared/Tests/PowerShellTestUtilities.cs | 23 +++++++-------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/Shared/Tests/PowerShellTestUtilities.cs b/src/Shared/Tests/PowerShellTestUtilities.cs index c67cc96ae..55ea65bcc 100644 --- a/src/Shared/Tests/PowerShellTestUtilities.cs +++ b/src/Shared/Tests/PowerShellTestUtilities.cs @@ -16,26 +16,19 @@ public static bool WindowsEnvironment() public static Lazy _PowerShellCommand = new Lazy(() => { - string? powershellCommand = WindowsEnvironment() ? "powershell" : null; - - IEnumerable? environmentVariables = Environment.GetEnvironmentVariables().Values.Cast(); - - if(environmentVariables.Any(item => item.ToLowerInvariant().Contains("pwsh"))) - { - powershellCommand = "pwsh"; - } - - if (powershellCommand is not null) + string? powershellCommand = null; + // Verify that the PowerShell command executes successfully. + foreach(string command in + new string[]{ "pwsh", WindowsEnvironment() ? "powershell" : null!}.Where(item=> item is not null)) { - // Verify that the PowerShell command executes successfully. try { - Process powershell = Process.Start(powershellCommand, "-h"); + Process powershell = Process.Start(command, "-h"); powershell.WaitForExit(); - var exitCode = powershell.ExitCode; - if (exitCode != 0) + if (powershell.ExitCode == 0) { - powershellCommand = null; + powershellCommand = command; + break; } } catch (System.ComponentModel.Win32Exception) From af4720613b08f66d6b0b0f735f2b21eb1cfc4e5e Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Thu, 29 Sep 2022 18:01:40 -0700 Subject: [PATCH 07/56] Fixed failing tests (from inattention to detail refactoring) --- ...isteringAFinalizerWithProcessExit.Tests.cs | 27 +++++- ...3.RegisteringAFinalizerWithProcessExit.ps1 | 89 ++++++++++--------- 2 files changed, 72 insertions(+), 44 deletions(-) diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index adb9270d8..1fa164f73 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -11,8 +11,28 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_23.Tests [TestClass] public class DisposeTests { + public TestContext TestContext { get; set; } = null!; // Auto-initialized by MSTest. + static string Ps1Path { get; } = Path.GetFullPath("../../../../Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); + [ClassInitialize] + public static void ClassInitialize(TestContext testContext) + { + string testStatus = "create"; + Assert.AreEqual(0, PowerShellTestUtilities.RunPowerShellScript( + Ps1Path, $"0 test {testStatus}", out string psOutput)); + testContext.WriteLine(psOutput); + Assert.IsTrue(File.Exists(@"C:\Git\EssentialCSharp\SCC\src\Chapter10\ProcessExitTestProgram\ProcessExitTestProgram.csproj")); + } + + [ClassCleanup] + public static void RemoveProcessExitProj() + { + string testStatus = "cleanup"; + Assert.AreEqual(0, PowerShellTestUtilities.RunPowerShellScript( + Ps1Path, $"0 test {testStatus}", out string _)); + } + [DataTestMethod] [DataRow("processExit", FinalizerRegisteredWithProcessExit, DisplayName = "Finalizer Registered With ProcessExit")] [DataRow("dispose", DisposeManuallyCalledExpectedOutput, DisplayName = "Dispose called before ProcessExit does finalizer")] @@ -22,12 +42,15 @@ public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrde string traceValue = "0"; string testStatus = "run"; + TestContext.WriteLine($"Ps1Path = '{Path.GetFullPath(Ps1Path)}'"); + int exitCode = PowerShellTestUtilities.RunPowerShellScript( Ps1Path, $"{traceValue} {finalizerOrderOption} {testStatus}", out string psOutput); - Assert.AreEqual(0, exitCode); + Assert.AreEqual(0, exitCode, $"PowerShell Output: {psOutput}"); - Assert.AreEqual(RemoveWhiteSpace(expectedOutput), RemoveWhiteSpace(psOutput)); + Assert.AreEqual(RemoveWhiteSpace(expectedOutput), RemoveWhiteSpace(psOutput), + $"Unexpected output from '{Ps1Path} {traceValue} {finalizerOrderOption} {testStatus}:{Environment.NewLine}{psOutput}"); } public const string DisposeManuallyCalledExpectedOutput = diff --git a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 index 287d84cf8..c4745d056 100644 --- a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 +++ b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 @@ -11,57 +11,62 @@ if('traceLevel' -notin $PSBoundParameters.Keys) { - 0: Turn script tracing off. - 1: Trace script lines as they run. - 2: Trace script lines, variable assignments, function calls, and scripts. - "@ } #$LibraryProjectName = 'ProcessExit' $ConsoleProgramProjectName = 'ProcessExitTestProgram' -if($testStatus -eq "create"){ -try { - Get-Item "$PSScriptRoot/$ConsoleProgramProjectName" -ErrorAction Ignore | Remove-Item -Recurse - Set-PSDebug -Trace $traceLevel - dotnet new Console --output "$PSScriptRoot/$ConsoleProgramProjectName" - Set-Content $PSScriptRoot/$ConsoleProgramProjectName/Directory.Build.props 'enable' - - $SutCSFile = split-path -leaf $MyInvocation.MyCommand.Definition - $SutCSFile = "$PSScriptRoot/$([IO.Path]::GetFileNameWithoutExtension($SutCSFile)).cs" - if(-not (Test-Path $SutCSFile)) { throw "Unable to find the file with the type to export ('$SutCSFile')"} - - $codeListing = @('namespace ProcessExitTestProgram') + ( - Get-Content $SutCSFile | Where-Object { $_ -notlike 'namespace *'}) - $codeListing > "$PSScriptRoot/$ConsoleProgramProjectName/Program.cs" - Get-Content "$PSScriptRoot/$ConsoleProgramProjectName/Program.cs" # Display the listing +[string]$projectDirectory = (Join-Path $PSScriptRoot $ConsoleProgramProjectName) -}catch{ - Write-Error "Unable to create project" -} - -} +switch ($testStatus) { + "create" { + try { + Write-Host "`$projectDirectory: $projectDirectory" + Get-Item $projectDirectory -ErrorAction Ignore | Remove-Item -Recurse + Set-PSDebug -Trace $traceLevel + dotnet new Console --output $projectDirectory + Set-Content (Join-Path $projectDirectory 'Directory.Build.props') 'enable' -if($testStatus -eq "cleanup"){ - Get-Item "$PSScriptRoot/$ConsoleProgramProjectName" -ErrorAction Ignore | Remove-Item -Recurse -} + $SutCSFile = split-path -leaf $MyInvocation.MyCommand.Definition + $SutCSFile = Join-Path $PSScriptRoot "$([IO.Path]::GetFileNameWithoutExtension($SutCSFile)).cs" + if(-not (Test-Path $SutCSFile)) { throw "Unable to find the file with the type to export ('$SutCSFile')"} + + $codeListing = @('namespace ProcessExitTestProgram') + ( + Get-Content $SutCSFile | Where-Object { $_ -notlike 'namespace *'}) + $codeListing > (Join-Path $projectDirectory 'Program.cs') + Get-Content (Join-Path $projectDirectory 'Program.cs') # Display the listing -if($testStatus -eq "run"){ - try{ - if($finalizerOption -eq 'dispose'){ - dotnet run --project "$PSScriptRoot/$ConsoleProgramProjectName/$ConsoleProgramProjectName.csproj" -- -dispose - } - elseif($finalizerOption -eq 'gc'){ - dotnet run --project "$PSScriptRoot/$ConsoleProgramProjectName/$ConsoleProgramProjectName.csproj" -- -gc + }catch{ + throw "Unable to create project" + } } - elseif($finalizerOption -eq 'processExit'){ - dotnet run --project "$PSScriptRoot/$ConsoleProgramProjectName/$ConsoleProgramProjectName.csproj" - } - else{ - Write-Error "finalizerOption: $finalizerOption not valid with the testStatus: run" + "cleanup" { + Get-Item $projectDirectory -ErrorAction Ignore | Remove-Item -Recurse } + "run" { + try{ + [string]$projectFile= Join-Path $projectDirectory "$ConsoleProgramProjectName.csproj" -} -finally { - Set-PSDebug -Off - -} -} + if(!(Test-Path $projectFile)) { + Write-Error "Unable to find project file ($projectFile)" + } + + if($finalizerOption -eq 'dispose'){ + dotnet run --project $projectFile -- -dispose + } + elseif($finalizerOption -eq 'gc'){ + dotnet run --project $projectFile -- -gc + } + elseif($finalizerOption -eq 'processExit'){ + dotnet run --project $projectFile + } + else{ + Write-Error "finalizerOption: $finalizerOption not valid with the testStatus: run" + } + } + finally { + Set-PSDebug -Off + } + } +} \ No newline at end of file From f3c8045ccd6f35027982cb5ef66c6868bb99b82d Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 30 Sep 2022 09:19:02 -0700 Subject: [PATCH 08/56] Minor refactoring --- ...3.RegisteringAFinalizerWithProcessExit.ps1 | 31 +++++++++++-------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 index c4745d056..7eae35d2b 100644 --- a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 +++ b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 @@ -23,7 +23,7 @@ switch ($testStatus) { "create" { try { Write-Host "`$projectDirectory: $projectDirectory" - Get-Item $projectDirectory -ErrorAction Ignore | Remove-Item -Recurse + Get-Item $projectDirectory -ErrorAction Ignore | Remove-Item -Recurse -Force Set-PSDebug -Trace $traceLevel dotnet new Console --output $projectDirectory Set-Content (Join-Path $projectDirectory 'Directory.Build.props') 'enable' @@ -42,7 +42,7 @@ switch ($testStatus) { } } "cleanup" { - Get-Item $projectDirectory -ErrorAction Ignore | Remove-Item -Recurse + Get-Item $projectDirectory -ErrorAction Ignore | Remove-Item -Recurse -Force } "run" { try{ @@ -52,21 +52,26 @@ switch ($testStatus) { Write-Error "Unable to find project file ($projectFile)" } - if($finalizerOption -eq 'dispose'){ - dotnet run --project $projectFile -- -dispose - } - elseif($finalizerOption -eq 'gc'){ - dotnet run --project $projectFile -- -gc - } - elseif($finalizerOption -eq 'processExit'){ - dotnet run --project $projectFile - } - else{ - Write-Error "finalizerOption: $finalizerOption not valid with the testStatus: run" + switch($finalizerOption) { + 'dispose' { + dotnet run --project $projectFile -- -dispose + } + 'gc' { + dotnet run --project $projectFile -- -gc + } + 'processExit' { + dotnet run --project $projectFile + } + default { + Write-Error "finalizerOption: $finalizerOption not valid with the testStatus: run" + } } } finally { Set-PSDebug -Off } } + default { + Write-Error "testStatus ('$testStatus') is not valid." + } } \ No newline at end of file From 6c07a441b285b5505f51d6955573a542210a932b Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 30 Sep 2022 09:37:17 -0700 Subject: [PATCH 09/56] Replaced left over debugging line with non-hard-coded path. --- ...10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 1fa164f73..2baa54547 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -13,7 +13,9 @@ public class DisposeTests { public TestContext TestContext { get; set; } = null!; // Auto-initialized by MSTest. - static string Ps1Path { get; } = Path.GetFullPath("../../../../Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); + static string Ps1DirectoryPath { get; } = + Path.GetFullPath(Path.Join("..","..", "..", "..", "Chapter10"), Environment.CurrentDirectory); + static string Ps1Path { get; } = Path.GetFullPath($"{Ps1DirectoryPath}/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); [ClassInitialize] public static void ClassInitialize(TestContext testContext) @@ -21,8 +23,10 @@ public static void ClassInitialize(TestContext testContext) string testStatus = "create"; Assert.AreEqual(0, PowerShellTestUtilities.RunPowerShellScript( Ps1Path, $"0 test {testStatus}", out string psOutput)); - testContext.WriteLine(psOutput); - Assert.IsTrue(File.Exists(@"C:\Git\EssentialCSharp\SCC\src\Chapter10\ProcessExitTestProgram\ProcessExitTestProgram.csproj")); + string projectFilePath = + Path.Join(Ps1DirectoryPath, "ProcessExitTestProgram", "ProcessExitTestProgram.csproj"); + Assert.IsTrue(File.Exists(projectFilePath), + $"The expected project file, '{projectFilePath}', was not created."); } [ClassCleanup] From 870fe0b82d5375b3165bb17bb0895d2e88eaacaa Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 30 Sep 2022 16:17:05 -0700 Subject: [PATCH 10/56] Powershell refactoring --- ...isteringAFinalizerWithProcessExit.Tests.cs | 22 ++++++++++++------- ...3.RegisteringAFinalizerWithProcessExit.ps1 | 22 +++++++++---------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 2baa54547..a14f38373 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -20,15 +20,21 @@ public class DisposeTests [ClassInitialize] public static void ClassInitialize(TestContext testContext) { - string testStatus = "create"; - Assert.AreEqual(0, PowerShellTestUtilities.RunPowerShellScript( - Ps1Path, $"0 test {testStatus}", out string psOutput)); - string projectFilePath = + string testStage = "create"; + Assert.AreEqual(0, RunPowerShellScript(testStage, out string psOutput), + $"Script failed with $testStage='{testStage}'. psOutput:\n{psOutput}"); + string projectFilePath = Path.Join(Ps1DirectoryPath, "ProcessExitTestProgram", "ProcessExitTestProgram.csproj"); Assert.IsTrue(File.Exists(projectFilePath), $"The expected project file, '{projectFilePath}', was not created."); } + private static int RunPowerShellScript(string testStage, out string psOutput) => + RunPowerShellScript(testStage, null, 0, out psOutput); + private static int RunPowerShellScript( + string testStage, string? finalizerOrderOption, int traceLevel, out string psOutput) => PowerShellTestUtilities.RunPowerShellScript( + Ps1Path, $"-TestStage {testStage} -FinalizerOption {finalizerOrderOption??"ignore"} {traceLevel}", out psOutput); + [ClassCleanup] public static void RemoveProcessExitProj() { @@ -43,13 +49,13 @@ public static void RemoveProcessExitProj() [DataRow("gc", GCCalled, DisplayName = "Garbage Collected called")] public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrderOption, string expectedOutput) { - string traceValue = "0"; + int traceValue = 0; string testStatus = "run"; TestContext.WriteLine($"Ps1Path = '{Path.GetFullPath(Ps1Path)}'"); - - int exitCode = PowerShellTestUtilities.RunPowerShellScript( - Ps1Path, $"{traceValue} {finalizerOrderOption} {testStatus}", out string psOutput); + string psOutput; + int exitCode = RunPowerShellScript( + testStatus, finalizerOrderOption, traceValue, out psOutput); Assert.AreEqual(0, exitCode, $"PowerShell Output: {psOutput}"); diff --git a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 index 7eae35d2b..d41c7462b 100644 --- a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 +++ b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 @@ -1,12 +1,12 @@ [CmdletBinding()] param( - [int]$traceLevel, - [string]$finalizerOption, - [string]$testStatus - + [string]$TestStage, + [string]$FinalizerOption, + [int]$TraceLevel=$null ) -if('traceLevel' -notin $PSBoundParameters.Keys) { - $traceLevel = Read-Host -Prompt @" + +if(($TraceLevel == null) -and 'TraceLevel' -notin $PSBoundParameters.Keys) { + $TraceLevel = Read-Host -Prompt @" Specifiy the trace level: - 0: Turn script tracing off. - 1: Trace script lines as they run. @@ -19,12 +19,12 @@ $ConsoleProgramProjectName = 'ProcessExitTestProgram' [string]$projectDirectory = (Join-Path $PSScriptRoot $ConsoleProgramProjectName) -switch ($testStatus) { +switch ($TestStage) { "create" { try { Write-Host "`$projectDirectory: $projectDirectory" Get-Item $projectDirectory -ErrorAction Ignore | Remove-Item -Recurse -Force - Set-PSDebug -Trace $traceLevel + Set-PSDebug -Trace $TraceLevel dotnet new Console --output $projectDirectory Set-Content (Join-Path $projectDirectory 'Directory.Build.props') 'enable' @@ -52,7 +52,7 @@ switch ($testStatus) { Write-Error "Unable to find project file ($projectFile)" } - switch($finalizerOption) { + switch($FinalizerOption) { 'dispose' { dotnet run --project $projectFile -- -dispose } @@ -63,7 +63,7 @@ switch ($testStatus) { dotnet run --project $projectFile } default { - Write-Error "finalizerOption: $finalizerOption not valid with the testStatus: run" + Write-Error "finalizerOption: $FinalizerOption not valid with the testStatus: run" } } } @@ -72,6 +72,6 @@ switch ($testStatus) { } } default { - Write-Error "testStatus ('$testStatus') is not valid." + Write-Error "testStatus ('$TestStage') is not valid." } } \ No newline at end of file From 19f7498f60968aa520418df9428e29e9d6875b64 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 1 Oct 2022 04:08:11 -0700 Subject: [PATCH 11/56] Updated ClassCleanup to use refactored method. --- ...egisteringAFinalizerWithProcessExit.Tests.cs | 17 ++++++++--------- src/Shared/Tests/PowerShellTestUtilities.cs | 1 - 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index a14f38373..594c740e0 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -29,18 +29,11 @@ public static void ClassInitialize(TestContext testContext) $"The expected project file, '{projectFilePath}', was not created."); } - private static int RunPowerShellScript(string testStage, out string psOutput) => - RunPowerShellScript(testStage, null, 0, out psOutput); - private static int RunPowerShellScript( - string testStage, string? finalizerOrderOption, int traceLevel, out string psOutput) => PowerShellTestUtilities.RunPowerShellScript( - Ps1Path, $"-TestStage {testStage} -FinalizerOption {finalizerOrderOption??"ignore"} {traceLevel}", out psOutput); - [ClassCleanup] public static void RemoveProcessExitProj() { - string testStatus = "cleanup"; - Assert.AreEqual(0, PowerShellTestUtilities.RunPowerShellScript( - Ps1Path, $"0 test {testStatus}", out string _)); + Assert.AreEqual(0, RunPowerShellScript( + "cleanup", out string _)); } [DataTestMethod] @@ -63,6 +56,12 @@ public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrde $"Unexpected output from '{Ps1Path} {traceValue} {finalizerOrderOption} {testStatus}:{Environment.NewLine}{psOutput}"); } + private static int RunPowerShellScript(string testStage, out string psOutput) => + RunPowerShellScript(testStage, null, 0, out psOutput); + private static int RunPowerShellScript( + string testStage, string? finalizerOrderOption, int traceLevel, out string psOutput) => PowerShellTestUtilities.RunPowerShellScript( + Ps1Path, $"-TestStage {testStage} -FinalizerOption {finalizerOrderOption??"ignore"} {traceLevel}", out psOutput); + public const string DisposeManuallyCalledExpectedOutput = @"Main: Starting... DoStuff: Starting... diff --git a/src/Shared/Tests/PowerShellTestUtilities.cs b/src/Shared/Tests/PowerShellTestUtilities.cs index 55ea65bcc..38a33039e 100644 --- a/src/Shared/Tests/PowerShellTestUtilities.cs +++ b/src/Shared/Tests/PowerShellTestUtilities.cs @@ -2,7 +2,6 @@ using System.Runtime.InteropServices; using System.Diagnostics; using System.Linq; -using System.Collections.Generic; namespace AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests { From 908c83d3a83822711a995148888974621613d4e9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Oct 2022 08:49:56 -0700 Subject: [PATCH 12/56] Bump Microsoft.CodeAnalysis.CSharp.Scripting from 4.3.0 to 4.3.1 (#367) Bumps [Microsoft.CodeAnalysis.CSharp.Scripting](https://github.com/dotnet/roslyn) from 4.3.0 to 4.3.1.
Release notes

Sourced from Microsoft.CodeAnalysis.CSharp.Scripting's releases.

.NET 6.0.1

Release

.NET 5.0.4

Release

.NET 5.0.2

Release Notes Install Instructions

Repos

Commits

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=Microsoft.CodeAnalysis.CSharp.Scripting&package-manager=nuget&previous-version=4.3.0&new-version=4.3.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- src/Chapter03.Tests/Chapter03.Tests.csproj | 2 +- src/Chapter09.Tests/Chapter09.Tests.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Chapter03.Tests/Chapter03.Tests.csproj b/src/Chapter03.Tests/Chapter03.Tests.csproj index 718e9799f..85ffdb574 100644 --- a/src/Chapter03.Tests/Chapter03.Tests.csproj +++ b/src/Chapter03.Tests/Chapter03.Tests.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/Chapter09.Tests/Chapter09.Tests.csproj b/src/Chapter09.Tests/Chapter09.Tests.csproj index 1867b4080..7c84e1a1b 100644 --- a/src/Chapter09.Tests/Chapter09.Tests.csproj +++ b/src/Chapter09.Tests/Chapter09.Tests.csproj @@ -7,7 +7,7 @@ - + From f53cd42bd8eef20530a1302189cd2ebb7e59ed3d Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 9 Sep 2022 15:28:55 -0700 Subject: [PATCH 13/56] Added top level statement and refactored PowerShellTestsUtilities --- src/Chapter01/Listing01.01A.HelloWorldInC#.cs | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 src/Chapter01/Listing01.01A.HelloWorldInC#.cs diff --git a/src/Chapter01/Listing01.01A.HelloWorldInC#.cs b/src/Chapter01/Listing01.01A.HelloWorldInC#.cs new file mode 100644 index 000000000..a500fba10 --- /dev/null +++ b/src/Chapter01/Listing01.01A.HelloWorldInC#.cs @@ -0,0 +1,5 @@ + +#region INCLUDE +System.Console.WriteLine("Hello. My name is Inigo Montoya."); +#endregion INCLUDE + From 4c0e9107f440d2bb8a93a174f77b8d4a879f442e Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sun, 25 Sep 2022 21:43:31 -0700 Subject: [PATCH 14/56] Refactored PowerShellTestsUtilities into a solution shared file. --- src/Shared/Tests/PowerShellTestsUtilities.cs | 77 ++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 src/Shared/Tests/PowerShellTestsUtilities.cs diff --git a/src/Shared/Tests/PowerShellTestsUtilities.cs b/src/Shared/Tests/PowerShellTestsUtilities.cs new file mode 100644 index 000000000..af3159eac --- /dev/null +++ b/src/Shared/Tests/PowerShellTestsUtilities.cs @@ -0,0 +1,77 @@ +using System; +using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Linq; +using System.Collections.Generic; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests +{ + public class PowerShellTestsUtilities + { + public static bool WindowsEnvironment() + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + } + + + public static Lazy _PowerShellCommand = new Lazy(() => + { + string? powershellCommand = WindowsEnvironment() ? "powershell" : null; + + IEnumerable? environmentVariables = Environment.GetEnvironmentVariables().Values.Cast(); + + if(environmentVariables.Any(item => item.ToLowerInvariant().Contains("pwsh"))) + { + powershellCommand = "pwsh"; + } + + if (powershellCommand is not null) + { + // Verify that the PowerShell command executes successfully. + try + { + Process powershell = Process.Start(powershellCommand, "-h"); + powershell.WaitForExit(); + var exitCode = powershell.ExitCode; + if (exitCode != 0) + { + powershellCommand = null; + } + } + catch (System.ComponentModel.Win32Exception) + { + powershellCommand = null; + } + } + return powershellCommand; + }); + public static int RunPowerShellScript(string scriptPath, string arguments) => + RunPowerShellScript(scriptPath, arguments, out string psOutput); + + public static int RunPowerShellScript(string scriptPath, string arguments, out string psOutput) + { + if(PowerShellCommand is null) + { + throw new InvalidOperationException("PowerShell is not installed"); + } + + if(!System.IO.File.Exists(scriptPath)) + { + throw new InvalidOperationException($"scriptPath, '{scriptPath}', not found."); + } + + using var powerShell = new Process(); + powerShell.StartInfo.RedirectStandardOutput = true; + powerShell.StartInfo.FileName = PowerShellCommand; + powerShell.StartInfo.Arguments = $"-noprofile -command \"{scriptPath} {arguments}\""; + powerShell.Start(); + psOutput = powerShell.StandardOutput.ReadToEnd(); + powerShell.WaitForExit(); + + return powerShell.ExitCode; + } + + public static string? PowerShellCommand => _PowerShellCommand!.Value; + public static bool PowerShellNotInstalled =>_PowerShellCommand.Value == null; + } +} From f5bf5e1565d4fbf96c284b03e36b377e36cc293a Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 26 Sep 2022 13:16:32 -0700 Subject: [PATCH 15/56] Excluded "HelloWorld" files Also removed top level statement (which wasn't needed in this branch) --- src/Chapter01/Listing01.01A.HelloWorldInC#.cs | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/Chapter01/Listing01.01A.HelloWorldInC#.cs diff --git a/src/Chapter01/Listing01.01A.HelloWorldInC#.cs b/src/Chapter01/Listing01.01A.HelloWorldInC#.cs deleted file mode 100644 index a500fba10..000000000 --- a/src/Chapter01/Listing01.01A.HelloWorldInC#.cs +++ /dev/null @@ -1,5 +0,0 @@ - -#region INCLUDE -System.Console.WriteLine("Hello. My name is Inigo Montoya."); -#endregion INCLUDE - From 0d4f0886dffda1c6bf89f43f72fd0bbea4eee06b Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 30 Sep 2022 16:17:05 -0700 Subject: [PATCH 16/56] Powershell refactoring --- ...sting10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 594c740e0..1dbeb4909 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -29,6 +29,12 @@ public static void ClassInitialize(TestContext testContext) $"The expected project file, '{projectFilePath}', was not created."); } + private static int RunPowerShellScript(string testStage, out string psOutput) => + RunPowerShellScript(testStage, null, 0, out psOutput); + private static int RunPowerShellScript( + string testStage, string? finalizerOrderOption, int traceLevel, out string psOutput) => PowerShellTestUtilities.RunPowerShellScript( + Ps1Path, $"-TestStage {testStage} -FinalizerOption {finalizerOrderOption??"ignore"} {traceLevel}", out psOutput); + [ClassCleanup] public static void RemoveProcessExitProj() { From 347c53a520ee03dc37ec9fdf587e5ca7d2332c01 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 1 Oct 2022 04:08:11 -0700 Subject: [PATCH 17/56] Updated ClassCleanup to use refactored method. --- ...sting10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 1dbeb4909..594c740e0 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -29,12 +29,6 @@ public static void ClassInitialize(TestContext testContext) $"The expected project file, '{projectFilePath}', was not created."); } - private static int RunPowerShellScript(string testStage, out string psOutput) => - RunPowerShellScript(testStage, null, 0, out psOutput); - private static int RunPowerShellScript( - string testStage, string? finalizerOrderOption, int traceLevel, out string psOutput) => PowerShellTestUtilities.RunPowerShellScript( - Ps1Path, $"-TestStage {testStage} -FinalizerOption {finalizerOrderOption??"ignore"} {traceLevel}", out psOutput); - [ClassCleanup] public static void RemoveProcessExitProj() { From 0c2c805d2651a807d77ff40d9ea6dc8c6e94703e Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 9 Sep 2022 15:28:55 -0700 Subject: [PATCH 18/56] Added top level statement and refactored PowerShellTestsUtilities --- src/Chapter01/Listing01.01A.HelloWorldInC#.cs | 5 ++ ...ngTypesAvailableOutsideAnAssembly.Tests.cs | 8 +++ ...isteringAFinalizerWithProcessExit.Tests.cs | 13 ++++ .../PowerShellTestsUtilities.cs | 72 +++++++++++++++++++ 4 files changed, 98 insertions(+) create mode 100644 src/Chapter01/Listing01.01A.HelloWorldInC#.cs create mode 100644 src/Chapter10.Tests/PowerShellTestsUtilities.cs diff --git a/src/Chapter01/Listing01.01A.HelloWorldInC#.cs b/src/Chapter01/Listing01.01A.HelloWorldInC#.cs new file mode 100644 index 000000000..a500fba10 --- /dev/null +++ b/src/Chapter01/Listing01.01A.HelloWorldInC#.cs @@ -0,0 +1,5 @@ + +#region INCLUDE +System.Console.WriteLine("Hello. My name is Inigo Montoya."); +#endregion INCLUDE + diff --git a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs index 864c0fa7c..bf3cf3b8f 100644 --- a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs +++ b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs @@ -13,12 +13,20 @@ public class TypeTests [TestMethod] public void MakingTypesAvailableExternallyPS1_ExitCodeIs0() { +<<<<<<< RefactorPowerShellTestUtilities if (PowerShellTestUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); +======= + if (PowerShellTestsUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); +>>>>>>> Added top level statement and refactored PowerShellTestsUtilities //EssentialCSharp\\src\\Chapter10.Tests\\bin\\Debug\\netcoreapp3.0 string ps1Path = Path.GetFullPath("../../../../Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1", Environment.CurrentDirectory); string traceValue = "0"; +<<<<<<< RefactorPowerShellTestUtilities int exitCode = PowerShellTestUtilities.RunPowerShellScript(ps1Path, traceValue); +======= + int exitCode = PowerShellTestsUtilities.RunPowerShellScript(ps1Path, traceValue); +>>>>>>> Added top level statement and refactored PowerShellTestsUtilities Assert.AreEqual(0, exitCode); } diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 594c740e0..6c2a4e498 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -13,9 +13,15 @@ public class DisposeTests { public TestContext TestContext { get; set; } = null!; // Auto-initialized by MSTest. +<<<<<<< RefactorPowerShellTestUtilities static string Ps1DirectoryPath { get; } = Path.GetFullPath(Path.Join("..","..", "..", "..", "Chapter10"), Environment.CurrentDirectory); static string Ps1Path { get; } = Path.GetFullPath($"{Ps1DirectoryPath}/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); +======= + static string Ps1Path { get; } = Path.GetFullPath("../../../../Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); + static bool PowerShellNotAvailable = PowerShellTestsUtilities.PowerShellNotInstalled; + static string PowershellEnvironmentVariableName { get; set; } = "powershell"; +>>>>>>> Added top level statement and refactored PowerShellTestsUtilities [ClassInitialize] public static void ClassInitialize(TestContext testContext) @@ -45,12 +51,19 @@ public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrde int traceValue = 0; string testStatus = "run"; +<<<<<<< RefactorPowerShellTestUtilities TestContext.WriteLine($"Ps1Path = '{Path.GetFullPath(Ps1Path)}'"); string psOutput; int exitCode = RunPowerShellScript( testStatus, finalizerOrderOption, traceValue, out psOutput); Assert.AreEqual(0, exitCode, $"PowerShell Output: {psOutput}"); +======= + int exitCode = PowerShellTestsUtilities.RunPowerShellScript( + Ps1Path, $"{traceValue} {finalizerOrderOption} {testStatus}", out string psOutput); + + Assert.AreEqual(0, exitCode); +>>>>>>> Added top level statement and refactored PowerShellTestsUtilities Assert.AreEqual(RemoveWhiteSpace(expectedOutput), RemoveWhiteSpace(psOutput), $"Unexpected output from '{Ps1Path} {traceValue} {finalizerOrderOption} {testStatus}:{Environment.NewLine}{psOutput}"); diff --git a/src/Chapter10.Tests/PowerShellTestsUtilities.cs b/src/Chapter10.Tests/PowerShellTestsUtilities.cs new file mode 100644 index 000000000..618d95bd5 --- /dev/null +++ b/src/Chapter10.Tests/PowerShellTestsUtilities.cs @@ -0,0 +1,72 @@ +using System; +using System.Runtime.InteropServices; +using System.Diagnostics; +using System.Linq; +using System.Collections.Generic; + +namespace Chapter10.Tests.PowerShellTestsUtilities +{ + class PowerShellTestsUtilities + { + public static bool WindowsEnvironment() + { + return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); + } + + + public static Lazy _PowerShellCommand = new Lazy(() => + { + string? powershellCommand = WindowsEnvironment() ? "powershell" : null; + + IEnumerable? environmentVariables = Environment.GetEnvironmentVariables().Values.Cast(); + + if(environmentVariables.Any(item => item.ToLowerInvariant().Contains("pwsh"))) + { + powershellCommand = "pwsh"; + } + + if (powershellCommand is not null) + { + // Verify that the PowerShell command executes successfully. + try + { + Process powershell = Process.Start(powershellCommand, "-h"); + powershell.WaitForExit(); + var exitCode = powershell.ExitCode; + if (exitCode != 0) + { + powershellCommand = null; + } + } + catch (System.ComponentModel.Win32Exception) + { + powershellCommand = null; + } + } + return powershellCommand; + }); + public static int RunPowerShellScript(string scriptPath, string arguments) => + RunPowerShellScript(scriptPath, arguments, out string psOutput); + + public static int RunPowerShellScript(string scriptPath, string arguments, out string psOutput) + { + if(PowerShellCommand is null) + { + throw new InvalidOperationException("PowerShell is not installed"); + } + + using var powerShell = new Process(); + powerShell.StartInfo.RedirectStandardOutput = true; + powerShell.StartInfo.FileName = PowerShellCommand; + powerShell.StartInfo.Arguments = $"-noprofile -command \"{scriptPath} {arguments}\""; + powerShell.Start(); + psOutput = powerShell.StandardOutput.ReadToEnd(); + powerShell.WaitForExit(); + + return powerShell.ExitCode; + } + + public static string? PowerShellCommand => _PowerShellCommand!.Value; + public static bool PowerShellNotInstalled =>_PowerShellCommand.Value == null; + } +} From f68803db7cf5988aa8c80f42add4b89a51360f49 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sun, 25 Sep 2022 21:43:31 -0700 Subject: [PATCH 19/56] Refactored PowerShellTestsUtilities into a solution shared file. --- EssentialCSharp.sln | 4 ++ src/Chapter10.Tests/Chapter10.Tests.csproj | 4 ++ ...isteringAFinalizerWithProcessExit.Tests.cs | 8 +++ .../PowerShellTestsUtilities.cs | 72 ------------------- 4 files changed, 16 insertions(+), 72 deletions(-) delete mode 100644 src/Chapter10.Tests/PowerShellTestsUtilities.cs diff --git a/EssentialCSharp.sln b/EssentialCSharp.sln index e8c41d8f5..ea3b6e914 100644 --- a/EssentialCSharp.sln +++ b/EssentialCSharp.sln @@ -121,7 +121,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chapter23.Tests", "src\Chap EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{22D1D24E-29B7-478D-ADBA-0F4836D3857A}" ProjectSection(SolutionItems) = preProject +<<<<<<< RefactorPowerShellTestUtilities src\Shared\Tests\PowerShellTestUtilities.cs = src\Shared\Tests\PowerShellTestUtilities.cs +======= + src\Shared\Tests\PowerShellTestsUtilities.cs = src\Shared\Tests\PowerShellTestsUtilities.cs +>>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. EndProjectSection EndProject Global diff --git a/src/Chapter10.Tests/Chapter10.Tests.csproj b/src/Chapter10.Tests/Chapter10.Tests.csproj index 12a7dbcd3..a3388613b 100644 --- a/src/Chapter10.Tests/Chapter10.Tests.csproj +++ b/src/Chapter10.Tests/Chapter10.Tests.csproj @@ -4,7 +4,11 @@ +<<<<<<< RefactorPowerShellTestUtilities +======= + +>>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 6c2a4e498..8c39caeab 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -11,6 +11,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_23.Tests [TestClass] public class DisposeTests { +<<<<<<< RefactorPowerShellTestUtilities public TestContext TestContext { get; set; } = null!; // Auto-initialized by MSTest. <<<<<<< RefactorPowerShellTestUtilities @@ -41,6 +42,9 @@ public static void RemoveProcessExitProj() Assert.AreEqual(0, RunPowerShellScript( "cleanup", out string _)); } +======= + static string Ps1Path { get; } = Path.GetFullPath("../../../../Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); +>>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. [DataTestMethod] [DataRow("processExit", FinalizerRegisteredWithProcessExit, DisplayName = "Finalizer Registered With ProcessExit")] @@ -48,7 +52,11 @@ public static void RemoveProcessExitProj() [DataRow("gc", GCCalled, DisplayName = "Garbage Collected called")] public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrderOption, string expectedOutput) { +<<<<<<< RefactorPowerShellTestUtilities int traceValue = 0; +======= + string traceValue = "0"; +>>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. string testStatus = "run"; <<<<<<< RefactorPowerShellTestUtilities diff --git a/src/Chapter10.Tests/PowerShellTestsUtilities.cs b/src/Chapter10.Tests/PowerShellTestsUtilities.cs deleted file mode 100644 index 618d95bd5..000000000 --- a/src/Chapter10.Tests/PowerShellTestsUtilities.cs +++ /dev/null @@ -1,72 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Diagnostics; -using System.Linq; -using System.Collections.Generic; - -namespace Chapter10.Tests.PowerShellTestsUtilities -{ - class PowerShellTestsUtilities - { - public static bool WindowsEnvironment() - { - return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - } - - - public static Lazy _PowerShellCommand = new Lazy(() => - { - string? powershellCommand = WindowsEnvironment() ? "powershell" : null; - - IEnumerable? environmentVariables = Environment.GetEnvironmentVariables().Values.Cast(); - - if(environmentVariables.Any(item => item.ToLowerInvariant().Contains("pwsh"))) - { - powershellCommand = "pwsh"; - } - - if (powershellCommand is not null) - { - // Verify that the PowerShell command executes successfully. - try - { - Process powershell = Process.Start(powershellCommand, "-h"); - powershell.WaitForExit(); - var exitCode = powershell.ExitCode; - if (exitCode != 0) - { - powershellCommand = null; - } - } - catch (System.ComponentModel.Win32Exception) - { - powershellCommand = null; - } - } - return powershellCommand; - }); - public static int RunPowerShellScript(string scriptPath, string arguments) => - RunPowerShellScript(scriptPath, arguments, out string psOutput); - - public static int RunPowerShellScript(string scriptPath, string arguments, out string psOutput) - { - if(PowerShellCommand is null) - { - throw new InvalidOperationException("PowerShell is not installed"); - } - - using var powerShell = new Process(); - powerShell.StartInfo.RedirectStandardOutput = true; - powerShell.StartInfo.FileName = PowerShellCommand; - powerShell.StartInfo.Arguments = $"-noprofile -command \"{scriptPath} {arguments}\""; - powerShell.Start(); - psOutput = powerShell.StandardOutput.ReadToEnd(); - powerShell.WaitForExit(); - - return powerShell.ExitCode; - } - - public static string? PowerShellCommand => _PowerShellCommand!.Value; - public static bool PowerShellNotInstalled =>_PowerShellCommand.Value == null; - } -} From c73469c02e2484a0ebc989cb2740c3c41660d4c0 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sun, 25 Sep 2022 21:52:20 -0700 Subject: [PATCH 20/56] Minor rename of PowerShellTestUtilities --- EssentialCSharp.sln | 4 ++++ src/Chapter10.Tests/Chapter10.Tests.csproj | 4 ++++ ...ng10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs | 8 ++++++++ ...ing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 4 ++++ ...tUtilities.cs~Minor rename of PowerShellTestUtilities} | 2 +- ...ShellTestUtilities.cs~RefactorPowerShellTestUtilities} | 0 6 files changed, 21 insertions(+), 1 deletion(-) rename src/Shared/Tests/{PowerShellTestsUtilities.cs => PowerShellTestUtilities.cs~Minor rename of PowerShellTestUtilities} (98%) rename src/Shared/Tests/{PowerShellTestUtilities.cs => PowerShellTestUtilities.cs~RefactorPowerShellTestUtilities} (100%) diff --git a/EssentialCSharp.sln b/EssentialCSharp.sln index ea3b6e914..ae313b7e9 100644 --- a/EssentialCSharp.sln +++ b/EssentialCSharp.sln @@ -121,11 +121,15 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chapter23.Tests", "src\Chap EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{22D1D24E-29B7-478D-ADBA-0F4836D3857A}" ProjectSection(SolutionItems) = preProject +<<<<<<< RefactorPowerShellTestUtilities <<<<<<< RefactorPowerShellTestUtilities src\Shared\Tests\PowerShellTestUtilities.cs = src\Shared\Tests\PowerShellTestUtilities.cs ======= src\Shared\Tests\PowerShellTestsUtilities.cs = src\Shared\Tests\PowerShellTestsUtilities.cs >>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. +======= + src\Shared\Tests\PowerShellTestUtilities.cs = src\Shared\Tests\PowerShellTestUtilities.cs +>>>>>>> Minor rename of PowerShellTestUtilities EndProjectSection EndProject Global diff --git a/src/Chapter10.Tests/Chapter10.Tests.csproj b/src/Chapter10.Tests/Chapter10.Tests.csproj index a3388613b..f94ae6856 100644 --- a/src/Chapter10.Tests/Chapter10.Tests.csproj +++ b/src/Chapter10.Tests/Chapter10.Tests.csproj @@ -4,11 +4,15 @@ +<<<<<<< RefactorPowerShellTestUtilities <<<<<<< RefactorPowerShellTestUtilities ======= >>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. +======= + +>>>>>>> Minor rename of PowerShellTestUtilities diff --git a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs index bf3cf3b8f..d623af9e4 100644 --- a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs +++ b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs @@ -13,20 +13,28 @@ public class TypeTests [TestMethod] public void MakingTypesAvailableExternallyPS1_ExitCodeIs0() { +<<<<<<< RefactorPowerShellTestUtilities <<<<<<< RefactorPowerShellTestUtilities if (PowerShellTestUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); ======= if (PowerShellTestsUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); >>>>>>> Added top level statement and refactored PowerShellTestsUtilities +======= + if (PowerShellTestUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); +>>>>>>> Minor rename of PowerShellTestUtilities //EssentialCSharp\\src\\Chapter10.Tests\\bin\\Debug\\netcoreapp3.0 string ps1Path = Path.GetFullPath("../../../../Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1", Environment.CurrentDirectory); string traceValue = "0"; +<<<<<<< RefactorPowerShellTestUtilities <<<<<<< RefactorPowerShellTestUtilities int exitCode = PowerShellTestUtilities.RunPowerShellScript(ps1Path, traceValue); ======= int exitCode = PowerShellTestsUtilities.RunPowerShellScript(ps1Path, traceValue); >>>>>>> Added top level statement and refactored PowerShellTestsUtilities +======= + int exitCode = PowerShellTestUtilities.RunPowerShellScript(ps1Path, traceValue); +>>>>>>> Minor rename of PowerShellTestUtilities Assert.AreEqual(0, exitCode); } diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 8c39caeab..0490736bf 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -59,6 +59,7 @@ public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrde >>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. string testStatus = "run"; +<<<<<<< RefactorPowerShellTestUtilities <<<<<<< RefactorPowerShellTestUtilities TestContext.WriteLine($"Ps1Path = '{Path.GetFullPath(Ps1Path)}'"); string psOutput; @@ -68,6 +69,9 @@ public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrde Assert.AreEqual(0, exitCode, $"PowerShell Output: {psOutput}"); ======= int exitCode = PowerShellTestsUtilities.RunPowerShellScript( +======= + int exitCode = PowerShellTestUtilities.RunPowerShellScript( +>>>>>>> Minor rename of PowerShellTestUtilities Ps1Path, $"{traceValue} {finalizerOrderOption} {testStatus}", out string psOutput); Assert.AreEqual(0, exitCode); diff --git a/src/Shared/Tests/PowerShellTestsUtilities.cs b/src/Shared/Tests/PowerShellTestUtilities.cs~Minor rename of PowerShellTestUtilities similarity index 98% rename from src/Shared/Tests/PowerShellTestsUtilities.cs rename to src/Shared/Tests/PowerShellTestUtilities.cs~Minor rename of PowerShellTestUtilities index af3159eac..c67cc96ae 100644 --- a/src/Shared/Tests/PowerShellTestsUtilities.cs +++ b/src/Shared/Tests/PowerShellTestUtilities.cs~Minor rename of PowerShellTestUtilities @@ -6,7 +6,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests { - public class PowerShellTestsUtilities + public class PowerShellTestUtilities { public static bool WindowsEnvironment() { diff --git a/src/Shared/Tests/PowerShellTestUtilities.cs b/src/Shared/Tests/PowerShellTestUtilities.cs~RefactorPowerShellTestUtilities similarity index 100% rename from src/Shared/Tests/PowerShellTestUtilities.cs rename to src/Shared/Tests/PowerShellTestUtilities.cs~RefactorPowerShellTestUtilities From ab90c13d1fb07cd38a798d803d9601b1e9c03836 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 26 Sep 2022 13:16:32 -0700 Subject: [PATCH 21/56] Excluded "HelloWorld" files Also removed top level statement (which wasn't needed in this branch) --- src/Chapter01/Listing01.01A.HelloWorldInC#.cs | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 src/Chapter01/Listing01.01A.HelloWorldInC#.cs diff --git a/src/Chapter01/Listing01.01A.HelloWorldInC#.cs b/src/Chapter01/Listing01.01A.HelloWorldInC#.cs deleted file mode 100644 index a500fba10..000000000 --- a/src/Chapter01/Listing01.01A.HelloWorldInC#.cs +++ /dev/null @@ -1,5 +0,0 @@ - -#region INCLUDE -System.Console.WriteLine("Hello. My name is Inigo Montoya."); -#endregion INCLUDE - From 933212d7067f342e0227578389dc4d8372b2dddb Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sun, 25 Sep 2022 22:04:50 -0700 Subject: [PATCH 22/56] Added a Listing 01.01A as a top level statement. --- src/Chapter01.Tests/Chapter01.Tests.csproj | 3 ++ src/Chapter01.Tests/Listing01.01A.Tests.cs | 43 +++++++++++++++++++ ...g01.01.Tests.cs => Listing01.01B.Tests.cs} | 0 src/Chapter01/Chapter01.csproj | 1 + src/Chapter01/Listing01.01.HelloWorldInC#.ps1 | 9 +++- src/Shared/Program.cs | 9 ++++ 6 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 src/Chapter01.Tests/Listing01.01A.Tests.cs rename src/Chapter01.Tests/{Listing01.01.Tests.cs => Listing01.01B.Tests.cs} (100%) diff --git a/src/Chapter01.Tests/Chapter01.Tests.csproj b/src/Chapter01.Tests/Chapter01.Tests.csproj index 3a3d00c02..61d02c65a 100644 --- a/src/Chapter01.Tests/Chapter01.Tests.csproj +++ b/src/Chapter01.Tests/Chapter01.Tests.csproj @@ -3,6 +3,9 @@ 01 + + + diff --git a/src/Chapter01.Tests/Listing01.01A.Tests.cs b/src/Chapter01.Tests/Listing01.01A.Tests.cs new file mode 100644 index 000000000..60afc56d1 --- /dev/null +++ b/src/Chapter01.Tests/Listing01.01A.Tests.cs @@ -0,0 +1,43 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; +using System.Diagnostics; +using System.IO; +using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; + +using System.Text.RegularExpressions; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01A.Tests +{ + [TestClass] + public class HelloWorldTests + { + static string Ps1Path { get; } = Path.GetFullPath("../../../../Chapter01/Listing01.01.HelloWorldInC#.ps1", Environment.CurrentDirectory); + + [TestMethod] + public void CreateAndRunNewConsoleProject() + { + string traceLevel = "0"; + + int exitCode = PowerShellTestUtilities.RunPowerShellScript( + Ps1Path, $"{traceLevel}", out string psOutput); + + Assert.AreEqual(0, exitCode); + + // Test that the program successfully produced the expected output. + string[] expectedText = { + "The template \"Console App\" was created successfully.", + "Build succeeded.", + "0 Error(s)", + "0 Warning(s)", + "Hello. My name is Inigo Montoya." + }; + + foreach (string text in expectedText) + { + Assert.IsTrue(psOutput.Contains(text), + $"Unexpectedly, '{text}' did not appear in the console output: \n {psOutput}"); + } + } + + } +} diff --git a/src/Chapter01.Tests/Listing01.01.Tests.cs b/src/Chapter01.Tests/Listing01.01B.Tests.cs similarity index 100% rename from src/Chapter01.Tests/Listing01.01.Tests.cs rename to src/Chapter01.Tests/Listing01.01B.Tests.cs diff --git a/src/Chapter01/Chapter01.csproj b/src/Chapter01/Chapter01.csproj index 3339908c9..c029bb629 100644 --- a/src/Chapter01/Chapter01.csproj +++ b/src/Chapter01/Chapter01.csproj @@ -8,6 +8,7 @@ $(IgnoredWarnings),CS8600,CA1052,IDE0059,IDE0060 + AddisonWesley.Michaelis.EssentialCSharp.Shared.Program diff --git a/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 b/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 index fc2ec8d94..def6f6470 100644 --- a/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 +++ b/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 @@ -2,7 +2,8 @@ param( [int]$traceLevel ) -if($traceLevel -notin $PSBoundParameters.Keys) { + +if('traceLevel' -notin $PSBoundParameters.Keys) { $traceLevel = Read-Host -Prompt @" Specifiy the trace level: - 0: Turn script tracing off. @@ -35,7 +36,11 @@ class HelloWorld $codeListing > Program.cs Get-Content Program.cs - dotnet run + + Write-Warning "Remove dotnet build step once we upgrade to version 10" + # Build with version 10 because dotnet version 6 defaults to an ImplicitUsings element in the project file. + dotnet build /property:LangVersion=10 + dotnet run --no-build } finally { Set-PSDebug -Off diff --git a/src/Shared/Program.cs b/src/Shared/Program.cs index 161c7bd77..df19feff3 100644 --- a/src/Shared/Program.cs +++ b/src/Shared/Program.cs @@ -45,6 +45,15 @@ public static async Task Main(string[] args) { input = ParseListingName(input); + // We handle listing 1.1 specially since the listing is a top level statement and + // the file (Listing01.01.HelloWorldInC#.cs) is set to not build as part of the project. + if(input == "01_01") + { + throw new InvalidOperationException( + "This listing (HelloWorld) is left as an exercise for the reader on the command line. "); + } + + Regex reg = new Regex($"Listing{input}\\.+"); IEnumerable targets = assembly.GetTypes().Where(type => From c01f45e2330b9c6396db1b7a96194eeee9e653d8 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 30 Sep 2022 17:26:19 -0700 Subject: [PATCH 23/56] Added top level statement --- EssentialCSharp.sln | 8 ----- ...g01.01A.Tests.cs => Listing01.01.Tests.cs} | 2 +- src/Chapter01/Chapter01.csproj | 3 +- src/Chapter01/Listing01.01.HelloWorldInC#.cs | 3 ++ src/Chapter10.Tests/Chapter10.Tests.csproj | 8 ----- ...ngTypesAvailableOutsideAnAssembly.Tests.cs | 18 +--------- ...isteringAFinalizerWithProcessExit.Tests.cs | 35 +++++-------------- ...stUtilities => PowerShellTestUtilities.cs} | 0 8 files changed, 15 insertions(+), 62 deletions(-) rename src/Chapter01.Tests/{Listing01.01A.Tests.cs => Listing01.01.Tests.cs} (98%) create mode 100644 src/Chapter01/Listing01.01.HelloWorldInC#.cs rename src/Shared/Tests/{PowerShellTestUtilities.cs~RefactorPowerShellTestUtilities => PowerShellTestUtilities.cs} (100%) diff --git a/EssentialCSharp.sln b/EssentialCSharp.sln index ae313b7e9..e8c41d8f5 100644 --- a/EssentialCSharp.sln +++ b/EssentialCSharp.sln @@ -121,15 +121,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Chapter23.Tests", "src\Chap EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{22D1D24E-29B7-478D-ADBA-0F4836D3857A}" ProjectSection(SolutionItems) = preProject -<<<<<<< RefactorPowerShellTestUtilities -<<<<<<< RefactorPowerShellTestUtilities src\Shared\Tests\PowerShellTestUtilities.cs = src\Shared\Tests\PowerShellTestUtilities.cs -======= - src\Shared\Tests\PowerShellTestsUtilities.cs = src\Shared\Tests\PowerShellTestsUtilities.cs ->>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. -======= - src\Shared\Tests\PowerShellTestUtilities.cs = src\Shared\Tests\PowerShellTestUtilities.cs ->>>>>>> Minor rename of PowerShellTestUtilities EndProjectSection EndProject Global diff --git a/src/Chapter01.Tests/Listing01.01A.Tests.cs b/src/Chapter01.Tests/Listing01.01.Tests.cs similarity index 98% rename from src/Chapter01.Tests/Listing01.01A.Tests.cs rename to src/Chapter01.Tests/Listing01.01.Tests.cs index 60afc56d1..dd95805f2 100644 --- a/src/Chapter01.Tests/Listing01.01A.Tests.cs +++ b/src/Chapter01.Tests/Listing01.01.Tests.cs @@ -6,7 +6,7 @@ using System.Text.RegularExpressions; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01A.Tests +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01.Tests { [TestClass] public class HelloWorldTests diff --git a/src/Chapter01/Chapter01.csproj b/src/Chapter01/Chapter01.csproj index c029bb629..e17d2c63b 100644 --- a/src/Chapter01/Chapter01.csproj +++ b/src/Chapter01/Chapter01.csproj @@ -13,6 +13,7 @@ + @@ -24,7 +25,7 @@ - + diff --git a/src/Chapter01/Listing01.01.HelloWorldInC#.cs b/src/Chapter01/Listing01.01.HelloWorldInC#.cs new file mode 100644 index 000000000..cd491b735 --- /dev/null +++ b/src/Chapter01/Listing01.01.HelloWorldInC#.cs @@ -0,0 +1,3 @@ +#region INCLUDE +System.Console.WriteLine("Hello. My name is Inigo Montoya."); +#endregion INCLUDE diff --git a/src/Chapter10.Tests/Chapter10.Tests.csproj b/src/Chapter10.Tests/Chapter10.Tests.csproj index f94ae6856..12a7dbcd3 100644 --- a/src/Chapter10.Tests/Chapter10.Tests.csproj +++ b/src/Chapter10.Tests/Chapter10.Tests.csproj @@ -4,15 +4,7 @@ -<<<<<<< RefactorPowerShellTestUtilities -<<<<<<< RefactorPowerShellTestUtilities -======= - ->>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. -======= - ->>>>>>> Minor rename of PowerShellTestUtilities diff --git a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs index d623af9e4..8e6a6f9d1 100644 --- a/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs +++ b/src/Chapter10.Tests/Listing10.13.MakingTypesAvailableOutsideAnAssembly.Tests.cs @@ -13,29 +13,13 @@ public class TypeTests [TestMethod] public void MakingTypesAvailableExternallyPS1_ExitCodeIs0() { -<<<<<<< RefactorPowerShellTestUtilities -<<<<<<< RefactorPowerShellTestUtilities if (PowerShellTestUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); -======= - if (PowerShellTestsUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); ->>>>>>> Added top level statement and refactored PowerShellTestsUtilities -======= - if (PowerShellTestUtilities.PowerShellNotInstalled) Assert.Inconclusive("Powershell not installed"); ->>>>>>> Minor rename of PowerShellTestUtilities //EssentialCSharp\\src\\Chapter10.Tests\\bin\\Debug\\netcoreapp3.0 string ps1Path = Path.GetFullPath("../../../../Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1", Environment.CurrentDirectory); string traceValue = "0"; -<<<<<<< RefactorPowerShellTestUtilities -<<<<<<< RefactorPowerShellTestUtilities - int exitCode = PowerShellTestUtilities.RunPowerShellScript(ps1Path, traceValue); -======= - int exitCode = PowerShellTestsUtilities.RunPowerShellScript(ps1Path, traceValue); ->>>>>>> Added top level statement and refactored PowerShellTestsUtilities -======= int exitCode = PowerShellTestUtilities.RunPowerShellScript(ps1Path, traceValue); ->>>>>>> Minor rename of PowerShellTestUtilities - + Assert.AreEqual(0, exitCode); } } diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 0490736bf..a2ec69f04 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -11,18 +11,11 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_23.Tests [TestClass] public class DisposeTests { -<<<<<<< RefactorPowerShellTestUtilities public TestContext TestContext { get; set; } = null!; // Auto-initialized by MSTest. -<<<<<<< RefactorPowerShellTestUtilities - static string Ps1DirectoryPath { get; } = - Path.GetFullPath(Path.Join("..","..", "..", "..", "Chapter10"), Environment.CurrentDirectory); + static string Ps1DirectoryPath { get; } = + Path.GetFullPath(Path.Join("..", "..", "..", "..", "Chapter10"), Environment.CurrentDirectory); static string Ps1Path { get; } = Path.GetFullPath($"{Ps1DirectoryPath}/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); -======= - static string Ps1Path { get; } = Path.GetFullPath("../../../../Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); - static bool PowerShellNotAvailable = PowerShellTestsUtilities.PowerShellNotInstalled; - static string PowershellEnvironmentVariableName { get; set; } = "powershell"; ->>>>>>> Added top level statement and refactored PowerShellTestsUtilities [ClassInitialize] public static void ClassInitialize(TestContext testContext) @@ -36,15 +29,18 @@ public static void ClassInitialize(TestContext testContext) $"The expected project file, '{projectFilePath}', was not created."); } + private static int RunPowerShellScript(string testStage, out string psOutput) => + RunPowerShellScript(testStage, null, 0, out psOutput); + private static int RunPowerShellScript( + string testStage, string? finalizerOrderOption, int traceLevel, out string psOutput) => PowerShellTestUtilities.RunPowerShellScript( + Ps1Path, $"-TestStage {testStage} -FinalizerOption {finalizerOrderOption ?? "ignore"} {traceLevel}", out psOutput); + [ClassCleanup] public static void RemoveProcessExitProj() { Assert.AreEqual(0, RunPowerShellScript( "cleanup", out string _)); } -======= - static string Ps1Path { get; } = Path.GetFullPath("../../../../Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); ->>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. [DataTestMethod] [DataRow("processExit", FinalizerRegisteredWithProcessExit, DisplayName = "Finalizer Registered With ProcessExit")] @@ -52,30 +48,15 @@ public static void RemoveProcessExitProj() [DataRow("gc", GCCalled, DisplayName = "Garbage Collected called")] public void FinalizerRunsAsPredicted_ConsoleOutputIsInOrder(string finalizerOrderOption, string expectedOutput) { -<<<<<<< RefactorPowerShellTestUtilities int traceValue = 0; -======= - string traceValue = "0"; ->>>>>>> Refactored PowerShellTestsUtilities into a solution shared file. string testStatus = "run"; -<<<<<<< RefactorPowerShellTestUtilities -<<<<<<< RefactorPowerShellTestUtilities TestContext.WriteLine($"Ps1Path = '{Path.GetFullPath(Ps1Path)}'"); string psOutput; int exitCode = RunPowerShellScript( testStatus, finalizerOrderOption, traceValue, out psOutput); Assert.AreEqual(0, exitCode, $"PowerShell Output: {psOutput}"); -======= - int exitCode = PowerShellTestsUtilities.RunPowerShellScript( -======= - int exitCode = PowerShellTestUtilities.RunPowerShellScript( ->>>>>>> Minor rename of PowerShellTestUtilities - Ps1Path, $"{traceValue} {finalizerOrderOption} {testStatus}", out string psOutput); - - Assert.AreEqual(0, exitCode); ->>>>>>> Added top level statement and refactored PowerShellTestsUtilities Assert.AreEqual(RemoveWhiteSpace(expectedOutput), RemoveWhiteSpace(psOutput), $"Unexpected output from '{Ps1Path} {traceValue} {finalizerOrderOption} {testStatus}:{Environment.NewLine}{psOutput}"); diff --git a/src/Shared/Tests/PowerShellTestUtilities.cs~RefactorPowerShellTestUtilities b/src/Shared/Tests/PowerShellTestUtilities.cs similarity index 100% rename from src/Shared/Tests/PowerShellTestUtilities.cs~RefactorPowerShellTestUtilities rename to src/Shared/Tests/PowerShellTestUtilities.cs From 9be5f771d3a38231cec9bb545b8e560ff00f739c Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 30 Sep 2022 20:14:20 -0700 Subject: [PATCH 24/56] Minor edit --- ...ting10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index a2ec69f04..1d42d686a 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -1,6 +1,5 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using System; -using System.Diagnostics; using System.IO; using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; @@ -29,12 +28,6 @@ public static void ClassInitialize(TestContext testContext) $"The expected project file, '{projectFilePath}', was not created."); } - private static int RunPowerShellScript(string testStage, out string psOutput) => - RunPowerShellScript(testStage, null, 0, out psOutput); - private static int RunPowerShellScript( - string testStage, string? finalizerOrderOption, int traceLevel, out string psOutput) => PowerShellTestUtilities.RunPowerShellScript( - Ps1Path, $"-TestStage {testStage} -FinalizerOption {finalizerOrderOption ?? "ignore"} {traceLevel}", out psOutput); - [ClassCleanup] public static void RemoveProcessExitProj() { From 5001135be7331059b341facb05537540a8b0726e Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 1 Oct 2022 18:59:04 -0700 Subject: [PATCH 25/56] Minor addition of Path.Join() --- .../Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 1d42d686a..cdd319c3c 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -14,7 +14,8 @@ public class DisposeTests static string Ps1DirectoryPath { get; } = Path.GetFullPath(Path.Join("..", "..", "..", "..", "Chapter10"), Environment.CurrentDirectory); - static string Ps1Path { get; } = Path.GetFullPath($"{Ps1DirectoryPath}/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1", Environment.CurrentDirectory); + static string Ps1Path { get; } = + Path.GetFullPath(Path.Join(Ps1DirectoryPath, "Listing10.23.RegisteringAFinalizerWithProcessExit.ps1"), Environment.CurrentDirectory); [ClassInitialize] public static void ClassInitialize(TestContext testContext) From cd1f76c73a668f7753c86705f3e93d82d64b3c09 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 1 Oct 2022 19:00:11 -0700 Subject: [PATCH 26/56] Added support to only test HelloWorld ps1 execution output when compiling in English HelloWorld execution output tested regardless. --- src/Chapter01.Tests/Listing01.01.Tests.cs | 41 ++++++++++++++++------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/src/Chapter01.Tests/Listing01.01.Tests.cs b/src/Chapter01.Tests/Listing01.01.Tests.cs index dd95805f2..91ccdf3b6 100644 --- a/src/Chapter01.Tests/Listing01.01.Tests.cs +++ b/src/Chapter01.Tests/Listing01.01.Tests.cs @@ -5,13 +5,19 @@ using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; using System.Text.RegularExpressions; +using System.Linq; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01.Tests { [TestClass] public class HelloWorldTests { - static string Ps1Path { get; } = Path.GetFullPath("../../../../Chapter01/Listing01.01.HelloWorldInC#.ps1", Environment.CurrentDirectory); + static string Ps1DirectoryPath { get; } = + Path.GetFullPath(Path.Join("..", "..", "..", "..", "Chapter01"), Environment.CurrentDirectory); + static string Ps1Path { get; } = + Path.GetFullPath( + Path.Join(Ps1DirectoryPath, "Listing01.01.HelloWorldInC#.ps1"), Environment.CurrentDirectory); + [TestMethod] public void CreateAndRunNewConsoleProject() @@ -23,19 +29,30 @@ public void CreateAndRunNewConsoleProject() Assert.AreEqual(0, exitCode); - // Test that the program successfully produced the expected output. - string[] expectedText = { - "The template \"Console App\" was created successfully.", - "Build succeeded.", - "0 Error(s)", - "0 Warning(s)", - "Hello. My name is Inigo Montoya." - }; + // Check that the program successfully ran and + // produced the expected output. + Assert.IsTrue( + psOutput.Contains( + $"{Environment.NewLine}Hello. My name is Inigo Montoya.{Environment.NewLine}"), + "The expected HelloWorld output was not found."); - foreach (string text in expectedText) + // If the output is in English + if (psOutput.Contains("Error(s)") && psOutput.Contains("Warning(s)")) { - Assert.IsTrue(psOutput.Contains(text), - $"Unexpectedly, '{text}' did not appear in the console output: \n {psOutput}"); + // Test that the program successfully produced the expected output. + string[] expectedText = + { + "The template \"Console App\" was created successfully.", + "Build succeeded.", + "0 Error(s)", + "0 Warning(s)" + }; + + foreach (string text in expectedText) + { + Assert.IsTrue(psOutput.Contains(text), + $"Unexpectedly, '{text}' did not appear in the console output: \n {psOutput}"); + } } } From e419742b2421f63359c4aee6bafe3d7d2a736abd Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sun, 2 Oct 2022 21:00:54 -0700 Subject: [PATCH 27/56] Started initial draft with top level statement for initial listing --- ...g01.06.Tests.cs => Listing01.02B.Tests.cs} | 2 +- src/Chapter01.Tests/Listing01.02C.Tests.cs | 20 +++++++++++++++++++ ...01.01B.Tests.cs => Listing01.02D.Tests.cs} | 2 +- ...g01.07.Tests.cs => Listing01.02E.Tests.cs} | 2 +- ...ing01.02B.MultipleStatementsOneOneLine.cs} | 2 +- ...1.02C.MultipleStatementsOnSeparateLines.cs | 14 +++++++++++++ ...SplittingAStatementAcrossMultipleLines.cs} | 2 +- ...nC#.cs => Listing01.02E.HelloWorldInC#.cs} | 2 +- 8 files changed, 40 insertions(+), 6 deletions(-) rename src/Chapter01.Tests/{Listing01.06.Tests.cs => Listing01.02B.Tests.cs} (96%) create mode 100644 src/Chapter01.Tests/Listing01.02C.Tests.cs rename src/Chapter01.Tests/{Listing01.01B.Tests.cs => Listing01.02D.Tests.cs} (96%) rename src/Chapter01.Tests/{Listing01.07.Tests.cs => Listing01.02E.Tests.cs} (96%) rename src/Chapter01/{Listing01.06.MultipleStatementsOneOneLine.cs => Listing01.02B.MultipleStatementsOneOneLine.cs} (96%) create mode 100644 src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs rename src/Chapter01/{Listing01.07.SplittingAStatementAcrossMultipleLines.cs => Listing01.02D.SplittingAStatementAcrossMultipleLines.cs} (96%) rename src/Chapter01/{Listing01.01B.HelloWorldInC#.cs => Listing01.02E.HelloWorldInC#.cs} (96%) diff --git a/src/Chapter01.Tests/Listing01.06.Tests.cs b/src/Chapter01.Tests/Listing01.02B.Tests.cs similarity index 96% rename from src/Chapter01.Tests/Listing01.06.Tests.cs rename to src/Chapter01.Tests/Listing01.02B.Tests.cs index 2a0365cc8..5f73830b4 100644 --- a/src/Chapter01.Tests/Listing01.06.Tests.cs +++ b/src/Chapter01.Tests/Listing01.02B.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_06.Tests +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02B.Tests { [TestClass] public class HelloWorldTests diff --git a/src/Chapter01.Tests/Listing01.02C.Tests.cs b/src/Chapter01.Tests/Listing01.02C.Tests.cs new file mode 100644 index 000000000..b42cd4a40 --- /dev/null +++ b/src/Chapter01.Tests/Listing01.02C.Tests.cs @@ -0,0 +1,20 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02C.Tests +{ + [TestClass] + public class HelloWorldTests + { + [TestMethod] + public void Main_InigoHello() + { + const string expected = + @"Down +Side +Up"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, HelloWorld.Main); + } + } +} \ No newline at end of file diff --git a/src/Chapter01.Tests/Listing01.01B.Tests.cs b/src/Chapter01.Tests/Listing01.02D.Tests.cs similarity index 96% rename from src/Chapter01.Tests/Listing01.01B.Tests.cs rename to src/Chapter01.Tests/Listing01.02D.Tests.cs index 24a9d8368..8ffeb5081 100644 --- a/src/Chapter01.Tests/Listing01.01B.Tests.cs +++ b/src/Chapter01.Tests/Listing01.02D.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01B.Tests +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02D.Tests { [TestClass] public class HelloWorldTests diff --git a/src/Chapter01.Tests/Listing01.07.Tests.cs b/src/Chapter01.Tests/Listing01.02E.Tests.cs similarity index 96% rename from src/Chapter01.Tests/Listing01.07.Tests.cs rename to src/Chapter01.Tests/Listing01.02E.Tests.cs index 94622cbc2..345902b0f 100644 --- a/src/Chapter01.Tests/Listing01.07.Tests.cs +++ b/src/Chapter01.Tests/Listing01.02E.Tests.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_07.Tests +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02E.Tests { [TestClass] public class HelloWorldTests diff --git a/src/Chapter01/Listing01.06.MultipleStatementsOneOneLine.cs b/src/Chapter01/Listing01.02B.MultipleStatementsOneOneLine.cs similarity index 96% rename from src/Chapter01/Listing01.06.MultipleStatementsOneOneLine.cs rename to src/Chapter01/Listing01.02B.MultipleStatementsOneOneLine.cs index e7d5a6685..3af250ee6 100644 --- a/src/Chapter01/Listing01.06.MultipleStatementsOneOneLine.cs +++ b/src/Chapter01/Listing01.02B.MultipleStatementsOneOneLine.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_06 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02B { public class HelloWorld { diff --git a/src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs b/src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs new file mode 100644 index 000000000..f5f492cfd --- /dev/null +++ b/src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs @@ -0,0 +1,14 @@ +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02C +{ + public class HelloWorld + { + public static void Main() + { + #region INCLUDE + System.Console.WriteLine("Down"); + System.Console.WriteLine("Side"); + System.Console.WriteLine("Up"); + #endregion INCLUDE + } + } +} diff --git a/src/Chapter01/Listing01.07.SplittingAStatementAcrossMultipleLines.cs b/src/Chapter01/Listing01.02D.SplittingAStatementAcrossMultipleLines.cs similarity index 96% rename from src/Chapter01/Listing01.07.SplittingAStatementAcrossMultipleLines.cs rename to src/Chapter01/Listing01.02D.SplittingAStatementAcrossMultipleLines.cs index 97ddd95c3..6882ca0f7 100644 --- a/src/Chapter01/Listing01.07.SplittingAStatementAcrossMultipleLines.cs +++ b/src/Chapter01/Listing01.02D.SplittingAStatementAcrossMultipleLines.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_07 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02D { public class HelloWorld { diff --git a/src/Chapter01/Listing01.01B.HelloWorldInC#.cs b/src/Chapter01/Listing01.02E.HelloWorldInC#.cs similarity index 96% rename from src/Chapter01/Listing01.01B.HelloWorldInC#.cs rename to src/Chapter01/Listing01.02E.HelloWorldInC#.cs index 11b529695..5e6ca4dd9 100644 --- a/src/Chapter01/Listing01.01B.HelloWorldInC#.cs +++ b/src/Chapter01/Listing01.02E.HelloWorldInC#.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01B +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02E { #region INCLUDE public class HelloWorld From fe1ffa27052a9fc529a276b2bdf0c3cff09cd5de Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 10 Oct 2022 17:20:07 -0700 Subject: [PATCH 28/56] Updated for C# 10 --- src/Chapter01/Chapter01.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Chapter01/Chapter01.csproj b/src/Chapter01/Chapter01.csproj index e17d2c63b..e5e17e3a6 100644 --- a/src/Chapter01/Chapter01.csproj +++ b/src/Chapter01/Chapter01.csproj @@ -9,6 +9,7 @@ unexpected exception as concept to check for null hasn't been explained yet--> $(IgnoredWarnings),CS8600,CA1052,IDE0059,IDE0060 AddisonWesley.Michaelis.EssentialCSharp.Shared.Program + Enable From 488e2c418af02f5b79978826e197ebaac169446c Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 10 Oct 2022 17:20:38 -0700 Subject: [PATCH 29/56] Updated to reflect VS new project generated file. --- src/Chapter01/Listing01.01.HelloWorldInC#.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Chapter01/Listing01.01.HelloWorldInC#.cs b/src/Chapter01/Listing01.01.HelloWorldInC#.cs index cd491b735..1133ef3da 100644 --- a/src/Chapter01/Listing01.01.HelloWorldInC#.cs +++ b/src/Chapter01/Listing01.01.HelloWorldInC#.cs @@ -1,3 +1,4 @@ +// See https://aka.ms/new-console-template for more information #region INCLUDE -System.Console.WriteLine("Hello. My name is Inigo Montoya."); +Console.WriteLine("Hello. My name is Inigo Montoya."); #endregion INCLUDE From e9136250da6fe9a5cba4afff8c25ad1f1902918f Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 10 Oct 2022 17:21:14 -0700 Subject: [PATCH 30/56] Added comments to identify various constructs --- .../Listing01.04.BreakingApartHelloWorld.cs | 13 +++++++------ .../Listing01.10.DeclaringAndAssigningAVariable.cs | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/Chapter01/Listing01.04.BreakingApartHelloWorld.cs b/src/Chapter01/Listing01.04.BreakingApartHelloWorld.cs index 39fea4fd5..c62f01bb6 100644 --- a/src/Chapter01/Listing01.04.BreakingApartHelloWorld.cs +++ b/src/Chapter01/Listing01.04.BreakingApartHelloWorld.cs @@ -1,12 +1,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_04 { #region INCLUDE - public class Program//Class definition + public class Program // BEGIN Class definition { - public static void Main()//Method declaration - { - System.Console.WriteLine("Hello, My name is Inigo Montoya");//This is the statement - }//This is the end of the method - }//end of the class definition + public static void Main() // Method declaration + { // BEGIN method implementation + Console.WriteLine( // This statement spans 2 lines + "Hello, My name is Inigo Montoya"); + } // END method implementation + } // END class definition #endregion INCLUDE } diff --git a/src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs b/src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs index b1b18fffd..06e2e30b5 100644 --- a/src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs +++ b/src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs @@ -5,8 +5,8 @@ public class MiracleMax { public static void Main() { - string max; - + string max; // "string" identifies the data type + // "max" is the variable max = "Have fun storming the castle!"; System.Console.WriteLine(max); } From 8a4a699114033a394fa71e17f95fc66105cf7023 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Tue, 11 Oct 2022 10:27:19 -0700 Subject: [PATCH 31/56] Bumped version numbers to 11. --- Directory.Build.props | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 18b272bda..1ccecf8e3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - 9.0 + preview enable Chapter$(ChapterNumber) false @@ -9,7 +9,7 @@ Copyright © Addison Wesley 2022 Essential C# $(LangVersion) $(Product) - 9.0 + 11.0 .\bin\Linux\$(Configuration)\ CS8600,CS8601,CS8602,CS8603,CS8604,CS8610,CS8614,CS8618,CS8622,CS8625,CS8653,CS8714 From 42ac94a8e05c52e6ffce879635b2da5e2221ce1b Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 22 Oct 2022 14:22:35 -0700 Subject: [PATCH 32/56] Minor updates --- src/Shared/Tests/PowerShellTestUtilities.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Shared/Tests/PowerShellTestUtilities.cs b/src/Shared/Tests/PowerShellTestUtilities.cs index 38a33039e..6af319a05 100644 --- a/src/Shared/Tests/PowerShellTestUtilities.cs +++ b/src/Shared/Tests/PowerShellTestUtilities.cs @@ -49,7 +49,7 @@ public static int RunPowerShellScript(string scriptPath, string arguments, out s if(!System.IO.File.Exists(scriptPath)) { - throw new InvalidOperationException($"scriptPath, '{scriptPath}', not found."); + throw new ArgumentException($"scriptPath, '{scriptPath}', not found.", nameof(scriptPath)); } using var powerShell = new Process(); @@ -63,7 +63,7 @@ public static int RunPowerShellScript(string scriptPath, string arguments, out s return powerShell.ExitCode; } - public static string? PowerShellCommand => _PowerShellCommand!.Value; + public static string? PowerShellCommand => _PowerShellCommand.Value; public static bool PowerShellNotInstalled =>_PowerShellCommand.Value == null; } } From 05b620911c5b7e58388d0b9a1eb99bd07036f9eb Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 22 Oct 2022 14:48:04 -0700 Subject: [PATCH 33/56] Upgraded to .net7.0/v11 Switched to dotnet 6.0 & 7.0 dotnet required console rather than Console Include pre-release for setup-dotnet Update LocalesTest.yml Updated tests to support different versions of .NET Updated to C# 11.0 Modified for GitHub build actions. --- .github/workflows/LocalesTest.yml | 4 +- .github/workflows/build-and-test.yml | 8 +- Common.props | 2 +- Directory.Build.props | 3 +- global.json | 5 +- src/Chapter01/Chapter01.csproj | 1 - ...ng01.02.SampleNETCoreConsoleProjectFile.cs | 2 +- src/Chapter02.Tests/Listing02.14.Tests.cs | 2 +- ...singTheNewlineCharacterToInsertANewline.cs | 4 +- ...ingATriangleUsingAVerbatimStringLiteral.cs | 6 +- .../Listing02.14B.RawLiteralStrings.cs | 28 ++++++ ...isting03.03.EnablingNullableProjectWide.cs | 2 +- ...3.RegisteringAFinalizerWithProcessExit.ps1 | 6 +- src/Chapter11/Properties/launchSettings.json | 8 ++ src/Chapter16.Tests/Chapter16.Tests.csproj | 3 + src/Chapter16.Tests/Listing16.15.Tests.cs | 92 +++++++++++++++++-- 16 files changed, 146 insertions(+), 30 deletions(-) create mode 100644 src/Chapter02/Listing02.14B.RawLiteralStrings.cs create mode 100644 src/Chapter11/Properties/launchSettings.json diff --git a/.github/workflows/LocalesTest.yml b/.github/workflows/LocalesTest.yml index ad2ce25bb..253612d7d 100644 --- a/.github/workflows/LocalesTest.yml +++ b/.github/workflows/LocalesTest.yml @@ -19,9 +19,9 @@ jobs: uses: actions/setup-dotnet@v2 with: dotnet-version: | - 3.1.x - 5.x 6.x + 7.x + include-prerelease: true - name: Get Build Information run: | pwd diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f564e6984..cd8213dd5 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,4 +1,4 @@ -name: Build and Test v9.0 +name: Build and Test v11.0 on: push: @@ -19,12 +19,12 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup dotnet SDK - uses: actions/setup-dotnet@v2 + uses: actions/setup-dotnet@v3 with: dotnet-version: | - 3.1.x - 5.x 6.x + 7.x + include-prerelease: true - name: Get Build Information run: | pwd diff --git a/Common.props b/Common.props index 3d99393e6..305fa2619 100644 --- a/Common.props +++ b/Common.props @@ -1,5 +1,5 @@ - net5.0;netcoreapp3.1 + net7.0;net6.0 \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 1ccecf8e3..932efbc6b 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,8 @@ - preview + 11.0 enable + enable Chapter$(ChapterNumber) false Mark Michaelis diff --git a/global.json b/global.json index 1bcf6c03c..602392863 100644 --- a/global.json +++ b/global.json @@ -1,7 +1,6 @@ { "sdk": { - "version": "6.0.0", - "rollForward": "latestMinor", - "allowPrerelease": false + "rollForward": "latestPatch", + "allowPrerelease": true } } \ No newline at end of file diff --git a/src/Chapter01/Chapter01.csproj b/src/Chapter01/Chapter01.csproj index e5e17e3a6..e17d2c63b 100644 --- a/src/Chapter01/Chapter01.csproj +++ b/src/Chapter01/Chapter01.csproj @@ -9,7 +9,6 @@ unexpected exception as concept to check for null hasn't been explained yet--> $(IgnoredWarnings),CS8600,CA1052,IDE0059,IDE0060 AddisonWesley.Michaelis.EssentialCSharp.Shared.Program - Enable diff --git a/src/Chapter01/Listing01.02.SampleNETCoreConsoleProjectFile.cs b/src/Chapter01/Listing01.02.SampleNETCoreConsoleProjectFile.cs index 1b869315b..041166a8b 100644 --- a/src/Chapter01/Listing01.02.SampleNETCoreConsoleProjectFile.cs +++ b/src/Chapter01/Listing01.02.SampleNETCoreConsoleProjectFile.cs @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 #endregion INCLUDE \ No newline at end of file diff --git a/src/Chapter02.Tests/Listing02.14.Tests.cs b/src/Chapter02.Tests/Listing02.14.Tests.cs index feb9c9522..b6430dcd1 100644 --- a/src/Chapter02.Tests/Listing02.14.Tests.cs +++ b/src/Chapter02.Tests/Listing02.14.Tests.cs @@ -14,7 +14,7 @@ public void Main_WriteTriangle() / \ / \ /________\ - end"; +end"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Triangle.Main); diff --git a/src/Chapter02/Listing02.13.UsingTheNewlineCharacterToInsertANewline.cs b/src/Chapter02/Listing02.13.UsingTheNewlineCharacterToInsertANewline.cs index 5ab53376b..fe2a9e0f8 100644 --- a/src/Chapter02/Listing02.13.UsingTheNewlineCharacterToInsertANewline.cs +++ b/src/Chapter02/Listing02.13.UsingTheNewlineCharacterToInsertANewline.cs @@ -1,14 +1,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_13 { - #region INCLUDE public class DuelOfWits { public static void Main() { + #region INCLUDE System.Console.Write( "\"Truly, you have a dizzying intellect.\""); System.Console.Write("\n\"Wait 'til I get going!\"\n"); + #endregion INCLUDE } } - #endregion INCLUDE } diff --git a/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs b/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs index 54f58bb11..029f56e6e 100644 --- a/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs +++ b/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs @@ -1,18 +1,18 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_14 { - #region INCLUDE public class Triangle { public static void Main() { + #region INCLUDE System.Console.Write(@"begin /\ / \ / \ / \ /________\ - end"); +end"); + #endregion INCLUDE } } - #endregion INCLUDE } diff --git a/src/Chapter02/Listing02.14B.RawLiteralStrings.cs b/src/Chapter02/Listing02.14B.RawLiteralStrings.cs new file mode 100644 index 000000000..f078139cb --- /dev/null +++ b/src/Chapter02/Listing02.14B.RawLiteralStrings.cs @@ -0,0 +1,28 @@ +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_14B +{ + public class Triangle + { + public static void Main() + { + #region INCLUDE +// System.Console.Write( +// """begin +// ____ +// / /\ +// /___/ \ +// / s /\ /\ +// / u / \/ \ +// / i / /\ \ +// / b / / \ \ +// / o / /\ \ \ +// / m / / \ \ \ +// /___/___/____\ \ \ +// / / \ \ /\ +///___/____________\___\/ \ +//\ \ \ \ / +// \___\_____________\___\/ +//end"""); + #endregion INCLUDE + } + } +} diff --git a/src/Chapter03/Listing03.03.EnablingNullableProjectWide.cs b/src/Chapter03/Listing03.03.EnablingNullableProjectWide.cs index 2e946f7aa..b10370f05 100644 --- a/src/Chapter03/Listing03.03.EnablingNullableProjectWide.cs +++ b/src/Chapter03/Listing03.03.EnablingNullableProjectWide.cs @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 enable diff --git a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 index d41c7462b..e91ccd345 100644 --- a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 +++ b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 @@ -5,7 +5,9 @@ param( [int]$TraceLevel=$null ) -if(($TraceLevel == null) -and 'TraceLevel' -notin $PSBoundParameters.Keys) { +Set-StrictMode -Version 3.0 + +if(($TraceLevel -eq $null) -and 'TraceLevel' -notin $PSBoundParameters.Keys) { $TraceLevel = Read-Host -Prompt @" Specifiy the trace level: - 0: Turn script tracing off. @@ -25,7 +27,7 @@ switch ($TestStage) { Write-Host "`$projectDirectory: $projectDirectory" Get-Item $projectDirectory -ErrorAction Ignore | Remove-Item -Recurse -Force Set-PSDebug -Trace $TraceLevel - dotnet new Console --output $projectDirectory + dotnet new console --output $projectDirectory Set-Content (Join-Path $projectDirectory 'Directory.Build.props') 'enable' $SutCSFile = split-path -leaf $MyInvocation.MyCommand.Definition diff --git a/src/Chapter11/Properties/launchSettings.json b/src/Chapter11/Properties/launchSettings.json new file mode 100644 index 000000000..33504c948 --- /dev/null +++ b/src/Chapter11/Properties/launchSettings.json @@ -0,0 +1,8 @@ +{ + "profiles": { + "WSL": { + "commandName": "WSL2", + "distributionName": "" + } + } +} \ No newline at end of file diff --git a/src/Chapter16.Tests/Chapter16.Tests.csproj b/src/Chapter16.Tests/Chapter16.Tests.csproj index 41fd8444c..9a4e2767d 100644 --- a/src/Chapter16.Tests/Chapter16.Tests.csproj +++ b/src/Chapter16.Tests/Chapter16.Tests.csproj @@ -3,6 +3,9 @@ 16 + + + diff --git a/src/Chapter16.Tests/Listing16.15.Tests.cs b/src/Chapter16.Tests/Listing16.15.Tests.cs index 228958953..01945b491 100644 --- a/src/Chapter16.Tests/Listing16.15.Tests.cs +++ b/src/Chapter16.Tests/Listing16.15.Tests.cs @@ -1,22 +1,98 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; +using System.Diagnostics; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16_15.Tests { [TestClass] public class ProgramTests { + public TestContext TestContext { get; set; } = null!; // Assigned by MSTest. + [TestMethod] public void SelectingAnonymousTypeFollowingGroupClause() { + string e = Shared.NetCore.GetNetCoreVersion() switch + { + string value when string.Compare(value, "6")<0 => """ + Aggregate, All, Any, Append, AsEnumerable, Average, Cast, Concat, Contains, + Count, DefaultIfEmpty, Distinct, ElementAt, ElementAtOrDefault, Empty, + Except, First, FirstOrDefault, GroupBy, GroupJoin, Intersect, Join, Last, + LastOrDefault, LongCount, Max, Min, OfType, OrderBy, OrderByDescending, + Prepend, Range, Repeat, Reverse, Select, SelectMany, SequenceEqual, + Single, SingleOrDefault, Skip, SkipLast, SkipWhile, Sum, Take, TakeLast, TakeWhile, ThenBy, + ThenByDescending, ToArray, ToDictionary, ToHashSet, ToList, ToLookup, Union, Where, Zip, + """, + string value when string.Compare(value, "7")<0 => """ + Aggregate, All, Any, Append, AsEnumerable, Average, Cast, + Chunk, Concat, Contains, Count, DefaultIfEmpty, Distinct, DistinctBy, + ElementAt, ElementAtOrDefault, Empty, Except, ExceptBy, First, + FirstOrDefault, GroupBy, GroupJoin, Intersect, IntersectBy, Join, + Last, LastOrDefault, LongCount, Max, MaxBy, Min, MinBy, OfType, + OrderBy, OrderByDescending, Prepend, Range, Repeat, Reverse, + Select, SelectMany, SequenceEqual, Single, SingleOrDefault, Skip, + SkipLast, SkipWhile, Sum, Take, TakeLast, TakeWhile, ThenBy, + ThenByDescending, ToArray, ToDictionary, ToHashSet, ToList, + ToLookup, TryGetNonEnumeratedCount, Union, UnionBy, Where, Zip, + """, + // Version 7.0 + _ => """ + Aggregate, All, Any, Append, AsEnumerable, Average, Cast, + Chunk, Concat, Contains, Count, DefaultIfEmpty, Distinct, DistinctBy, + ElementAt, ElementAtOrDefault, Empty, Except, ExceptBy, First, + FirstOrDefault, GroupBy, GroupJoin, Intersect, IntersectBy, Join, + Last, LastOrDefault, LongCount, Max, MaxBy, Min, MinBy, OfType, + Order, OrderBy, OrderByDescending, OrderDescending, Prepend, Range, + Repeat, Reverse, Select, SelectMany, SequenceEqual, Single, + SingleOrDefault, Skip, SkipLast, SkipWhile, Sum, Take, TakeLast, + TakeWhile, ThenBy, ThenByDescending, ToArray, ToDictionary, ToHashSet, + ToList, ToLookup, TryGetNonEnumeratedCount, Union, UnionBy, Where, Zip, + """ + }; + + // New lines added for output formatting in the chapter. - string expected = -@"Aggregate, All, Any, Append, AsEnumerable, Average, Cast, Concat, Contains, -Count, DefaultIfEmpty, Distinct, ElementAt, ElementAtOrDefault, Empty, -Except, First, FirstOrDefault, GroupBy, GroupJoin, Intersect, Join, Last, -LastOrDefault, LongCount, Max, Min, OfType, OrderBy, OrderByDescending, -Prepend, Range, Repeat, Reverse, Select, SelectMany, SequenceEqual, -Single, SingleOrDefault, Skip, SkipLast, SkipWhile, Sum, Take, TakeLast, TakeWhile, ThenBy, -ThenByDescending, ToArray, ToDictionary, ToHashSet, ToList, ToLookup, Union, Where, Zip, "; + string expected = """ + Aggregate, All, Any, Append, AsEnumerable, Average, Cast, + Chunk, Concat, Contains, Count, DefaultIfEmpty, Distinct, DistinctBy, + ElementAt, ElementAtOrDefault, Empty, Except, ExceptBy, First, + FirstOrDefault, GroupBy, GroupJoin, Intersect, IntersectBy, Join, + Last, LastOrDefault, LongCount, Max, MaxBy, Min, MinBy, OfType, + Order, OrderBy, OrderByDescending, OrderDescending, Prepend, Range, + Repeat, Reverse, Select, SelectMany, SequenceEqual, Single, + SingleOrDefault, Skip, SkipLast, SkipWhile, Sum, Take, TakeLast, + TakeWhile, ThenBy, ThenByDescending, ToArray, ToDictionary, ToHashSet, + ToList, ToLookup, TryGetNonEnumeratedCount, Union, UnionBy, Where, Zip, + """; + + TestContext.WriteLine(Shared.NetCore.GetNetCoreVersion()); + if (string.Compare(Shared.NetCore.GetNetCoreVersion(), "7") < 0) + { + expected = """ + Aggregate, All, Any, Append, AsEnumerable, Average, Cast, + Chunk, Concat, Contains, Count, DefaultIfEmpty, Distinct, DistinctBy, + ElementAt, ElementAtOrDefault, Empty, Except, ExceptBy, First, + FirstOrDefault, GroupBy, GroupJoin, Intersect, IntersectBy, Join, + Last, LastOrDefault, LongCount, Max, MaxBy, Min, MinBy, OfType, + OrderBy, OrderByDescending, Prepend, Range, Repeat, Reverse, + Select, SelectMany, SequenceEqual, Single, SingleOrDefault, Skip, + SkipLast, SkipWhile, Sum, Take, TakeLast, TakeWhile, ThenBy, + ThenByDescending, ToArray, ToDictionary, ToHashSet, ToList, + ToLookup, TryGetNonEnumeratedCount, Union, UnionBy, Where, Zip, + """; + + if (string.Compare(Shared.NetCore.GetNetCoreVersion(), "5") < 0) + { + expected = """ + Aggregate, All, Any, Append, AsEnumerable, Average, Cast, Concat, Contains, + Count, DefaultIfEmpty, Distinct, ElementAt, ElementAtOrDefault, Empty, + Except, First, FirstOrDefault, GroupBy, GroupJoin, Intersect, Join, Last, + LastOrDefault, LongCount, Max, Min, OfType, OrderBy, OrderByDescending, + Prepend, Range, Repeat, Reverse, Select, SelectMany, SequenceEqual, + Single, SingleOrDefault, Skip, SkipLast, SkipWhile, Sum, Take, TakeLast, TakeWhile, ThenBy, + ThenByDescending, ToArray, ToDictionary, ToHashSet, ToList, ToLookup, Union, Where, Zip, + """; + } + } expected = expected.Replace("\r\n", string.Empty); expected = expected.Replace("\n", string.Empty); From 4189a5303b616ef755d96d2c9d376142efdb1ce2 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 22 Oct 2022 11:29:39 -0700 Subject: [PATCH 34/56] Updated to use IntelliTect.Multitool to find location --- src/Chapter10.Tests/Chapter10.Tests.csproj | 3 +++ ...Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Chapter10.Tests/Chapter10.Tests.csproj b/src/Chapter10.Tests/Chapter10.Tests.csproj index 12a7dbcd3..bfa74621b 100644 --- a/src/Chapter10.Tests/Chapter10.Tests.csproj +++ b/src/Chapter10.Tests/Chapter10.Tests.csproj @@ -6,6 +6,9 @@ + + + diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index cdd319c3c..5cd7424ce 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -13,7 +13,9 @@ public class DisposeTests public TestContext TestContext { get; set; } = null!; // Auto-initialized by MSTest. static string Ps1DirectoryPath { get; } = - Path.GetFullPath(Path.Join("..", "..", "..", "..", "Chapter10"), Environment.CurrentDirectory); + Path.GetFullPath( + Path.Join(IntelliTect.Multitool.RepositoryPaths.GetDefaultRepoRoot(),"src", "Chapter10")); + static string Ps1Path { get; } = Path.GetFullPath(Path.Join(Ps1DirectoryPath, "Listing10.23.RegisteringAFinalizerWithProcessExit.ps1"), Environment.CurrentDirectory); From ee345fe7c1d89918254c94563100e5953e05264f Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 22 Oct 2022 11:31:18 -0700 Subject: [PATCH 35/56] Removed errant file --- ...cs~Minor rename of PowerShellTestUtilities | 77 ------------------- 1 file changed, 77 deletions(-) delete mode 100644 src/Shared/Tests/PowerShellTestUtilities.cs~Minor rename of PowerShellTestUtilities diff --git a/src/Shared/Tests/PowerShellTestUtilities.cs~Minor rename of PowerShellTestUtilities b/src/Shared/Tests/PowerShellTestUtilities.cs~Minor rename of PowerShellTestUtilities deleted file mode 100644 index c67cc96ae..000000000 --- a/src/Shared/Tests/PowerShellTestUtilities.cs~Minor rename of PowerShellTestUtilities +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Runtime.InteropServices; -using System.Diagnostics; -using System.Linq; -using System.Collections.Generic; - -namespace AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests -{ - public class PowerShellTestUtilities - { - public static bool WindowsEnvironment() - { - return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); - } - - - public static Lazy _PowerShellCommand = new Lazy(() => - { - string? powershellCommand = WindowsEnvironment() ? "powershell" : null; - - IEnumerable? environmentVariables = Environment.GetEnvironmentVariables().Values.Cast(); - - if(environmentVariables.Any(item => item.ToLowerInvariant().Contains("pwsh"))) - { - powershellCommand = "pwsh"; - } - - if (powershellCommand is not null) - { - // Verify that the PowerShell command executes successfully. - try - { - Process powershell = Process.Start(powershellCommand, "-h"); - powershell.WaitForExit(); - var exitCode = powershell.ExitCode; - if (exitCode != 0) - { - powershellCommand = null; - } - } - catch (System.ComponentModel.Win32Exception) - { - powershellCommand = null; - } - } - return powershellCommand; - }); - public static int RunPowerShellScript(string scriptPath, string arguments) => - RunPowerShellScript(scriptPath, arguments, out string psOutput); - - public static int RunPowerShellScript(string scriptPath, string arguments, out string psOutput) - { - if(PowerShellCommand is null) - { - throw new InvalidOperationException("PowerShell is not installed"); - } - - if(!System.IO.File.Exists(scriptPath)) - { - throw new InvalidOperationException($"scriptPath, '{scriptPath}', not found."); - } - - using var powerShell = new Process(); - powerShell.StartInfo.RedirectStandardOutput = true; - powerShell.StartInfo.FileName = PowerShellCommand; - powerShell.StartInfo.Arguments = $"-noprofile -command \"{scriptPath} {arguments}\""; - powerShell.Start(); - psOutput = powerShell.StandardOutput.ReadToEnd(); - powerShell.WaitForExit(); - - return powerShell.ExitCode; - } - - public static string? PowerShellCommand => _PowerShellCommand!.Value; - public static bool PowerShellNotInstalled =>_PowerShellCommand.Value == null; - } -} From 2b938ded4f0a5fde30e4fa2b9539da5dce62974d Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 22 Oct 2022 15:15:42 -0700 Subject: [PATCH 36/56] Minor update to csproj file --- src/Chapter10.Tests/Chapter10.Tests.csproj | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Chapter10.Tests/Chapter10.Tests.csproj b/src/Chapter10.Tests/Chapter10.Tests.csproj index bfa74621b..332783325 100644 --- a/src/Chapter10.Tests/Chapter10.Tests.csproj +++ b/src/Chapter10.Tests/Chapter10.Tests.csproj @@ -6,13 +6,11 @@ - - - + all runtime; build; native; contentfiles; analyzers From 68a48e4fe7a0dd2450a29183f51c0aa6c6982643 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 22 Oct 2022 19:22:33 -0700 Subject: [PATCH 37/56] Added Raw Literal String samples --- src/Chapter02.Tests/Listing02.14A.Tests.cs | 32 +++++++++++++++++++ .../Listing02.14A.RawLiteralStrings.cs | 31 ++++++++++++++++++ .../Listing02.14B.RawLiteralStrings.cs | 28 ---------------- src/Chapter11/Properties/launchSettings.json | 8 ----- 4 files changed, 63 insertions(+), 36 deletions(-) create mode 100644 src/Chapter02.Tests/Listing02.14A.Tests.cs create mode 100644 src/Chapter02/Listing02.14A.RawLiteralStrings.cs delete mode 100644 src/Chapter02/Listing02.14B.RawLiteralStrings.cs delete mode 100644 src/Chapter11/Properties/launchSettings.json diff --git a/src/Chapter02.Tests/Listing02.14A.Tests.cs b/src/Chapter02.Tests/Listing02.14A.Tests.cs new file mode 100644 index 000000000..dd3a99d93 --- /dev/null +++ b/src/Chapter02.Tests/Listing02.14A.Tests.cs @@ -0,0 +1,32 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_14A.Tests +{ + [TestClass] + public class TriangleTests + { + [TestMethod] + public void Main_WriteTriangle() + { + const string expected = @"begin + ____ + / /\ + / / \ + / / /\ + / / / \ + / / /\ \ + / / / \ \ + / / /\ \ \ + / / / \ \ \ + /___/___/____\ \ \ + / {mobius} \ \ \ +/________________\ \ \ +\ \ \ / + \_________________\___\/ +end"; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Triangle.Main); + } + } +} \ No newline at end of file diff --git a/src/Chapter02/Listing02.14A.RawLiteralStrings.cs b/src/Chapter02/Listing02.14A.RawLiteralStrings.cs new file mode 100644 index 000000000..9b75aa595 --- /dev/null +++ b/src/Chapter02/Listing02.14A.RawLiteralStrings.cs @@ -0,0 +1,31 @@ +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_14A +{ + public class Triangle + { + public static void Main() + { + #region INCLUDE + string name = "mobius"; + Console.Write( + $$""" + begin + ____ + / /\ + / / \ + / / /\ + / / / \ + / / /\ \ + / / / \ \ + / / /\ \ \ + / / / \ \ \ + /___/___/____\ \ \ + / {{{name}}} \ \ \ + /________________\ \ \ + \ \ \ / + \_________________\___\/ + end + """); + #endregion INCLUDE + } + } +} diff --git a/src/Chapter02/Listing02.14B.RawLiteralStrings.cs b/src/Chapter02/Listing02.14B.RawLiteralStrings.cs deleted file mode 100644 index f078139cb..000000000 --- a/src/Chapter02/Listing02.14B.RawLiteralStrings.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_14B -{ - public class Triangle - { - public static void Main() - { - #region INCLUDE -// System.Console.Write( -// """begin -// ____ -// / /\ -// /___/ \ -// / s /\ /\ -// / u / \/ \ -// / i / /\ \ -// / b / / \ \ -// / o / /\ \ \ -// / m / / \ \ \ -// /___/___/____\ \ \ -// / / \ \ /\ -///___/____________\___\/ \ -//\ \ \ \ / -// \___\_____________\___\/ -//end"""); - #endregion INCLUDE - } - } -} diff --git a/src/Chapter11/Properties/launchSettings.json b/src/Chapter11/Properties/launchSettings.json deleted file mode 100644 index 33504c948..000000000 --- a/src/Chapter11/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "WSL": { - "commandName": "WSL2", - "distributionName": "" - } - } -} \ No newline at end of file From f1e7b160cfcce87943f2f601113d48a70f1e08fe Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 22 Oct 2022 19:25:51 -0700 Subject: [PATCH 38/56] Removed CurrentPath dependency --- src/Chapter01.Tests/Chapter01.Tests.csproj | 3 ++- src/Chapter01.Tests/Listing01.01.Tests.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Chapter01.Tests/Chapter01.Tests.csproj b/src/Chapter01.Tests/Chapter01.Tests.csproj index 61d02c65a..994b3b080 100644 --- a/src/Chapter01.Tests/Chapter01.Tests.csproj +++ b/src/Chapter01.Tests/Chapter01.Tests.csproj @@ -10,7 +10,8 @@ - + + all runtime; build; native; contentfiles; analyzers diff --git a/src/Chapter01.Tests/Listing01.01.Tests.cs b/src/Chapter01.Tests/Listing01.01.Tests.cs index 91ccdf3b6..66efd7f0a 100644 --- a/src/Chapter01.Tests/Listing01.01.Tests.cs +++ b/src/Chapter01.Tests/Listing01.01.Tests.cs @@ -13,7 +13,8 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01.Tests public class HelloWorldTests { static string Ps1DirectoryPath { get; } = - Path.GetFullPath(Path.Join("..", "..", "..", "..", "Chapter01"), Environment.CurrentDirectory); + Path.GetFullPath(Path.Join( + IntelliTect.Multitool.RepositoryPaths.GetDefaultRepoRoot(), "src", "Chapter01")); static string Ps1Path { get; } = Path.GetFullPath( Path.Join(Ps1DirectoryPath, "Listing01.01.HelloWorldInC#.ps1"), Environment.CurrentDirectory); From dbec67f3b66980df1ff581a76abf4a8b9acee485 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sat, 22 Oct 2022 19:26:45 -0700 Subject: [PATCH 39/56] Updated now that we are on C#11/.NET7.0 --- src/Chapter01/Listing01.01.HelloWorldInC#.ps1 | 6 +----- .../Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 | 3 ++- src/Shared/Tests/PowerShellTestUtilities.cs | 1 - 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 b/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 index def6f6470..18247f060 100644 --- a/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 +++ b/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 @@ -36,11 +36,7 @@ class HelloWorld $codeListing > Program.cs Get-Content Program.cs - - Write-Warning "Remove dotnet build step once we upgrade to version 10" - # Build with version 10 because dotnet version 6 defaults to an ImplicitUsings element in the project file. - dotnet build /property:LangVersion=10 - dotnet run --no-build + dotnet run } finally { Set-PSDebug -Off diff --git a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 index e91ccd345..8dfed0b50 100644 --- a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 +++ b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 @@ -28,7 +28,8 @@ switch ($TestStage) { Get-Item $projectDirectory -ErrorAction Ignore | Remove-Item -Recurse -Force Set-PSDebug -Trace $TraceLevel dotnet new console --output $projectDirectory - Set-Content (Join-Path $projectDirectory 'Directory.Build.props') 'enable' + # No longer needed in .net7.0./C#11 + # Set-Content (Join-Path $projectDirectory 'Directory.Build.props') 'enable' $SutCSFile = split-path -leaf $MyInvocation.MyCommand.Definition $SutCSFile = Join-Path $PSScriptRoot "$([IO.Path]::GetFileNameWithoutExtension($SutCSFile)).cs" diff --git a/src/Shared/Tests/PowerShellTestUtilities.cs b/src/Shared/Tests/PowerShellTestUtilities.cs index 6af319a05..08faf0258 100644 --- a/src/Shared/Tests/PowerShellTestUtilities.cs +++ b/src/Shared/Tests/PowerShellTestUtilities.cs @@ -12,7 +12,6 @@ public static bool WindowsEnvironment() return RuntimeInformation.IsOSPlatform(OSPlatform.Windows); } - public static Lazy _PowerShellCommand = new Lazy(() => { string? powershellCommand = null; From edeb997c98d9bae63ea18f0597d0a6d4838baddd Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sun, 23 Oct 2022 12:20:26 -0700 Subject: [PATCH 40/56] Update src/Shared/Tests/PowerShellTestUtilities.cs Co-authored-by: Benjamin Michaelis --- src/Shared/Tests/PowerShellTestUtilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Shared/Tests/PowerShellTestUtilities.cs b/src/Shared/Tests/PowerShellTestUtilities.cs index 08faf0258..ab5a1db03 100644 --- a/src/Shared/Tests/PowerShellTestUtilities.cs +++ b/src/Shared/Tests/PowerShellTestUtilities.cs @@ -63,6 +63,6 @@ public static int RunPowerShellScript(string scriptPath, string arguments, out s } public static string? PowerShellCommand => _PowerShellCommand.Value; - public static bool PowerShellNotInstalled =>_PowerShellCommand.Value == null; + public static bool PowerShellNotInstalled => _PowerShellCommand.Value is null; } } From c010b59abbdbe28d3fd979ec5e302bc83a29d9c7 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sun, 23 Oct 2022 13:10:22 -0700 Subject: [PATCH 41/56] Removed Version element from Directory.Build.props - relying soley on LangVersion instead --- Directory.Build.props | 1 - 1 file changed, 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 932efbc6b..0e8732658 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -10,7 +10,6 @@ Copyright © Addison Wesley 2022 Essential C# $(LangVersion) $(Product) - 11.0 .\bin\Linux\$(Configuration)\ CS8600,CS8601,CS8602,CS8603,CS8604,CS8610,CS8614,CS8618,CS8622,CS8625,CS8653,CS8714 From 6ed7de488902904d531139c7c176b28498b1bcbd Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Sun, 23 Oct 2022 23:56:19 -0700 Subject: [PATCH 42/56] Updated to use .NET 6 or higher --- global.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/global.json b/global.json index 602392863..9e5e1fd1d 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,7 @@ { "sdk": { - "rollForward": "latestPatch", + "version": "6.0.0", + "rollForward": "latestMajor", "allowPrerelease": true } } \ No newline at end of file From 8fdef0224ac544b948f958ea7012fb34af4b434e Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 24 Oct 2022 00:24:15 -0700 Subject: [PATCH 43/56] Removed System. prefix. And fixed line breaks for 1.19 comments example. --- ...ting01.02B.MultipleStatementsOneOneLine.cs | 2 +- ...1.02C.MultipleStatementsOnSeparateLines.cs | 6 +-- ....SplittingAStatementAcrossMultipleLines.cs | 2 +- .../Listing01.08.NoIndentationFormatting.cs | 2 +- .../Listing01.09.RemovingWhitespace.cs | 2 +- ...ing01.10.DeclaringAndAssigningAVariable.cs | 2 +- ...DeclaringTwoVariablesWithinOneStatement.cs | 4 +- ...isting01.12.ChangingTheValueOfAVariable.cs | 6 +-- ...ntReturningAValueThatCanBeassignedAgain.cs | 2 +- ...Listing01.14.UsingSystemConsoleReadLine.cs | 10 ++--- .../Listing01.15.UsingSystemConsoleRead.cs | 4 +- ...1.16.FormattingUsingStringInterpolation.cs | 12 +++--- ...1.17.FormattingUsingCompositeFormatting.cs | 12 +++--- ...edPlaceholdersAndCorrespondingVariables.cs | 12 +++--- .../Listing01.19.CommentingYourCode.cs | 43 +++++++++---------- 15 files changed, 59 insertions(+), 62 deletions(-) diff --git a/src/Chapter01/Listing01.02B.MultipleStatementsOneOneLine.cs b/src/Chapter01/Listing01.02B.MultipleStatementsOneOneLine.cs index 3af250ee6..97fd4fe53 100644 --- a/src/Chapter01/Listing01.02B.MultipleStatementsOneOneLine.cs +++ b/src/Chapter01/Listing01.02B.MultipleStatementsOneOneLine.cs @@ -5,7 +5,7 @@ public class HelloWorld public static void Main() { #region INCLUDE - System.Console.WriteLine("Up");System.Console.WriteLine("Down"); + Console.WriteLine("Up"); Console.WriteLine("Down"); #endregion INCLUDE } } diff --git a/src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs b/src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs index f5f492cfd..95c3c7129 100644 --- a/src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs +++ b/src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs @@ -5,9 +5,9 @@ public class HelloWorld public static void Main() { #region INCLUDE - System.Console.WriteLine("Down"); - System.Console.WriteLine("Side"); - System.Console.WriteLine("Up"); + Console.WriteLine("Down"); + Console.WriteLine("Side"); + Console.WriteLine("Up"); #endregion INCLUDE } } diff --git a/src/Chapter01/Listing01.02D.SplittingAStatementAcrossMultipleLines.cs b/src/Chapter01/Listing01.02D.SplittingAStatementAcrossMultipleLines.cs index 6882ca0f7..5edb62189 100644 --- a/src/Chapter01/Listing01.02D.SplittingAStatementAcrossMultipleLines.cs +++ b/src/Chapter01/Listing01.02D.SplittingAStatementAcrossMultipleLines.cs @@ -5,7 +5,7 @@ public class HelloWorld public static void Main() { #region INCLUDE - System.Console.WriteLine( + Console.WriteLine( "Hello. My name is Inigo Montoya."); #endregion INCLUDE } diff --git a/src/Chapter01/Listing01.08.NoIndentationFormatting.cs b/src/Chapter01/Listing01.08.NoIndentationFormatting.cs index 99467243a..a2c863295 100644 --- a/src/Chapter01/Listing01.08.NoIndentationFormatting.cs +++ b/src/Chapter01/Listing01.08.NoIndentationFormatting.cs @@ -5,7 +5,7 @@ public class HelloWorld { public static void Main() { -System.Console.WriteLine("Hello Inigo Montoya"); + Console.WriteLine("Hello Inigo Montoya"); } } #endregion INCLUDE diff --git a/src/Chapter01/Listing01.09.RemovingWhitespace.cs b/src/Chapter01/Listing01.09.RemovingWhitespace.cs index b1c6c34e3..7fdc7f0d5 100644 --- a/src/Chapter01/Listing01.09.RemovingWhitespace.cs +++ b/src/Chapter01/Listing01.09.RemovingWhitespace.cs @@ -2,6 +2,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_09 { #region INCLUDE public class HelloWorld{public static void Main() -{System.Console.WriteLine("Hello Inigo Montoya");}} +{ Console.WriteLine("Hello Inigo Montoya");}} #endregion INCLUDE } diff --git a/src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs b/src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs index 06e2e30b5..6a5925185 100644 --- a/src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs +++ b/src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs @@ -8,7 +8,7 @@ public static void Main() string max; // "string" identifies the data type // "max" is the variable max = "Have fun storming the castle!"; - System.Console.WriteLine(max); + Console.WriteLine(max); } } #endregion INCLUDE diff --git a/src/Chapter01/Listing01.11.DeclaringTwoVariablesWithinOneStatement.cs b/src/Chapter01/Listing01.11.DeclaringTwoVariablesWithinOneStatement.cs index fea6ab986..67cf4b9a2 100644 --- a/src/Chapter01/Listing01.11.DeclaringTwoVariablesWithinOneStatement.cs +++ b/src/Chapter01/Listing01.11.DeclaringTwoVariablesWithinOneStatement.cs @@ -11,8 +11,8 @@ public static void Main() message1 = "My name is Inigo Montoya.";; message2 = "You killed my father...."; - System.Console.WriteLine(message1); - System.Console.WriteLine(message2); + Console.WriteLine(message1); + Console.WriteLine(message2); } } } diff --git a/src/Chapter01/Listing01.12.ChangingTheValueOfAVariable.cs b/src/Chapter01/Listing01.12.ChangingTheValueOfAVariable.cs index 1f446e970..1bc9fc7a2 100644 --- a/src/Chapter01/Listing01.12.ChangingTheValueOfAVariable.cs +++ b/src/Chapter01/Listing01.12.ChangingTheValueOfAVariable.cs @@ -12,13 +12,13 @@ public static void Main() valerie = "Think it will work?"; #endregion HIGHLIGHT - System.Console.WriteLine(miracleMax); - System.Console.WriteLine(valerie); + Console.WriteLine(miracleMax); + Console.WriteLine(valerie); #region HIGHLIGHT miracleMax = "It would take a miracle."; #endregion HIGHLIGHT - System.Console.WriteLine(miracleMax); + Console.WriteLine(miracleMax); } } #endregion INCLUDE diff --git a/src/Chapter01/Listing01.13.AssignmentReturningAValueThatCanBeassignedAgain.cs b/src/Chapter01/Listing01.13.AssignmentReturningAValueThatCanBeassignedAgain.cs index 6c7e855f1..2e004c494 100644 --- a/src/Chapter01/Listing01.13.AssignmentReturningAValueThatCanBeassignedAgain.cs +++ b/src/Chapter01/Listing01.13.AssignmentReturningAValueThatCanBeassignedAgain.cs @@ -9,7 +9,7 @@ public static void Main() string requirements, miracleMax; requirements = miracleMax = "It would take a miracle."; #region EXCLUDE - System.Console.WriteLine(miracleMax); + Console.WriteLine(miracleMax); #endregion EXCLUDE } } diff --git a/src/Chapter01/Listing01.14.UsingSystemConsoleReadLine.cs b/src/Chapter01/Listing01.14.UsingSystemConsoleReadLine.cs index fc9484779..b72777f7d 100644 --- a/src/Chapter01/Listing01.14.UsingSystemConsoleReadLine.cs +++ b/src/Chapter01/Listing01.14.UsingSystemConsoleReadLine.cs @@ -8,13 +8,13 @@ public static void Main() string firstName; string lastName; - System.Console.WriteLine("Hey you!"); + Console.WriteLine("Hey you!"); - System.Console.Write("Enter your first name: "); - firstName = System.Console.ReadLine(); + Console.Write("Enter your first name: "); + firstName = Console.ReadLine(); - System.Console.Write("Enter your last name: "); - lastName = System.Console.ReadLine(); + Console.Write("Enter your last name: "); + lastName = Console.ReadLine(); } } #endregion INCLUDE diff --git a/src/Chapter01/Listing01.15.UsingSystemConsoleRead.cs b/src/Chapter01/Listing01.15.UsingSystemConsoleRead.cs index 6d94e6762..3bdbc2860 100644 --- a/src/Chapter01/Listing01.15.UsingSystemConsoleRead.cs +++ b/src/Chapter01/Listing01.15.UsingSystemConsoleRead.cs @@ -7,9 +7,9 @@ public static void Main() #region INCLUDE int readValue; char character; - readValue = System.Console.Read(); + readValue = Console.Read(); character = (char) readValue; - System.Console.Write(character); + Console.Write(character); #endregion INCLUDE } } diff --git a/src/Chapter01/Listing01.16.FormattingUsingStringInterpolation.cs b/src/Chapter01/Listing01.16.FormattingUsingStringInterpolation.cs index 13c7acc09..72287d026 100644 --- a/src/Chapter01/Listing01.16.FormattingUsingStringInterpolation.cs +++ b/src/Chapter01/Listing01.16.FormattingUsingStringInterpolation.cs @@ -8,15 +8,15 @@ public static void Main() string firstName; string lastName; - System.Console.WriteLine("Hey you!"); + Console.WriteLine("Hey you!"); - System.Console.Write("Enter your first name: "); - firstName = System.Console.ReadLine(); + Console.Write("Enter your first name: "); + firstName = Console.ReadLine(); - System.Console.Write("Enter your last name: "); - lastName = System.Console.ReadLine(); + Console.Write("Enter your last name: "); + lastName = Console.ReadLine(); - System.Console.WriteLine( + Console.WriteLine( #region HIGHLIGHT $"Your full name is { firstName } { lastName }."); #endregion HIGHLIGHT diff --git a/src/Chapter01/Listing01.17.FormattingUsingCompositeFormatting.cs b/src/Chapter01/Listing01.17.FormattingUsingCompositeFormatting.cs index af6560474..609b4114d 100644 --- a/src/Chapter01/Listing01.17.FormattingUsingCompositeFormatting.cs +++ b/src/Chapter01/Listing01.17.FormattingUsingCompositeFormatting.cs @@ -8,17 +8,17 @@ public static void Main() string firstName; string lastName; - System.Console.WriteLine("Hey you!"); + Console.WriteLine("Hey you!"); - System.Console.Write("Enter your first name: "); - firstName = System.Console.ReadLine(); + Console.Write("Enter your first name: "); + firstName = Console.ReadLine(); #region HIGHLIGHT - System.Console.Write("Enter your last name: "); - lastName = System.Console.ReadLine(); + Console.Write("Enter your last name: "); + lastName = Console.ReadLine(); #endregion HIGHLIGHT - System.Console.WriteLine( + Console.WriteLine( "Your full name is {0} {1}.", firstName, lastName); } } diff --git a/src/Chapter01/Listing01.18.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs b/src/Chapter01/Listing01.18.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs index 0dba6a5db..f650bd900 100644 --- a/src/Chapter01/Listing01.18.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs +++ b/src/Chapter01/Listing01.18.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs @@ -7,15 +7,15 @@ public static void Main() string firstName; string lastName; - System.Console.WriteLine("Hey you!"); + Console.WriteLine("Hey you!"); - System.Console.Write("Enter your first name: "); - firstName = System.Console.ReadLine(); + Console.Write("Enter your first name: "); + firstName = Console.ReadLine(); - System.Console.Write("Enter your last name: "); - lastName = System.Console.ReadLine(); + Console.Write("Enter your last name: "); + lastName = Console.ReadLine(); #region INCLUDE - System.Console.WriteLine("Your full name is {1}, {0}.", firstName, lastName); + Console.WriteLine("Your full name is {1}, {0}.", firstName, lastName); #endregion INCLUDE } } diff --git a/src/Chapter01/Listing01.19.CommentingYourCode.cs b/src/Chapter01/Listing01.19.CommentingYourCode.cs index b3fa5dcc2..9f8e69585 100644 --- a/src/Chapter01/Listing01.19.CommentingYourCode.cs +++ b/src/Chapter01/Listing01.19.CommentingYourCode.cs @@ -1,31 +1,28 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_19 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_19; + +#region INCLUDE +public class CommentSamples { - #region INCLUDE - public class CommentSamples + public static void Main() { - public static void Main() - { - string firstName; // Variable for storing the first name - string lastName; // Variable for storing the last name + string firstName; // Variable for storing the first name + string lastName; // Variable for storing the last name - System.Console.WriteLine("Hey you!"); + Console.WriteLine("Hey you!"); - System.Console.Write /* No new line */ ( - "Enter your first name: "); - firstName = System.Console.ReadLine(); + Console.Write /* No new line */ ("Enter your first name: "); + firstName = Console.ReadLine(); - System.Console.Write /* No new line */ ( - "Enter your last name: "); - lastName = System.Console.ReadLine(); + Console.Write /* No new line */ ("Enter your last name: "); + lastName = Console.ReadLine(); - /* Display a greeting to the console - using composite fomatting. */ + /* Display a greeting to the console + using composite fomatting. */ - System.Console.WriteLine("Your full name is {1}, {0}.", - firstName, lastName); - // This is the end - // of the program listing - } + Console.WriteLine("Your full name is {1}, {0}.", + firstName, lastName); + // This is the end + // of the program listing } - #endregion INCLUDE -} \ No newline at end of file +} +#endregion INCLUDE From 2743d65b43e63142bc859c0e3f552f553383fb15 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 24 Oct 2022 00:24:41 -0700 Subject: [PATCH 44/56] Removed stale code --- src/Chapter16.Tests/Listing16.15.Tests.cs | 54 +++-------------------- 1 file changed, 7 insertions(+), 47 deletions(-) diff --git a/src/Chapter16.Tests/Listing16.15.Tests.cs b/src/Chapter16.Tests/Listing16.15.Tests.cs index 01945b491..3689d5713 100644 --- a/src/Chapter16.Tests/Listing16.15.Tests.cs +++ b/src/Chapter16.Tests/Listing16.15.Tests.cs @@ -11,8 +11,10 @@ public class ProgramTests [TestMethod] public void SelectingAnonymousTypeFollowingGroupClause() { - string e = Shared.NetCore.GetNetCoreVersion() switch + string dotnetCoreVersion = Shared.NetCore.GetNetCoreVersion(); + string expected = dotnetCoreVersion switch { + // Version <= 5 string value when string.Compare(value, "6")<0 => """ Aggregate, All, Any, Append, AsEnumerable, Average, Cast, Concat, Contains, Count, DefaultIfEmpty, Distinct, ElementAt, ElementAtOrDefault, Empty, @@ -22,7 +24,8 @@ string value when string.Compare(value, "6")<0 => """ Single, SingleOrDefault, Skip, SkipLast, SkipWhile, Sum, Take, TakeLast, TakeWhile, ThenBy, ThenByDescending, ToArray, ToDictionary, ToHashSet, ToList, ToLookup, Union, Where, Zip, """, - string value when string.Compare(value, "7")<0 => """ + // Version 6 + string value when value.StartsWith("6") => """ Aggregate, All, Any, Append, AsEnumerable, Average, Cast, Chunk, Concat, Contains, Count, DefaultIfEmpty, Distinct, DistinctBy, ElementAt, ElementAtOrDefault, Empty, Except, ExceptBy, First, @@ -34,7 +37,7 @@ string value when string.Compare(value, "7")<0 => """ ThenByDescending, ToArray, ToDictionary, ToHashSet, ToList, ToLookup, TryGetNonEnumeratedCount, Union, UnionBy, Where, Zip, """, - // Version 7.0 + // Version 7 _ => """ Aggregate, All, Any, Append, AsEnumerable, Average, Cast, Chunk, Concat, Contains, Count, DefaultIfEmpty, Distinct, DistinctBy, @@ -49,50 +52,7 @@ string value when string.Compare(value, "7")<0 => """ """ }; - - // New lines added for output formatting in the chapter. - string expected = """ - Aggregate, All, Any, Append, AsEnumerable, Average, Cast, - Chunk, Concat, Contains, Count, DefaultIfEmpty, Distinct, DistinctBy, - ElementAt, ElementAtOrDefault, Empty, Except, ExceptBy, First, - FirstOrDefault, GroupBy, GroupJoin, Intersect, IntersectBy, Join, - Last, LastOrDefault, LongCount, Max, MaxBy, Min, MinBy, OfType, - Order, OrderBy, OrderByDescending, OrderDescending, Prepend, Range, - Repeat, Reverse, Select, SelectMany, SequenceEqual, Single, - SingleOrDefault, Skip, SkipLast, SkipWhile, Sum, Take, TakeLast, - TakeWhile, ThenBy, ThenByDescending, ToArray, ToDictionary, ToHashSet, - ToList, ToLookup, TryGetNonEnumeratedCount, Union, UnionBy, Where, Zip, - """; - - TestContext.WriteLine(Shared.NetCore.GetNetCoreVersion()); - if (string.Compare(Shared.NetCore.GetNetCoreVersion(), "7") < 0) - { - expected = """ - Aggregate, All, Any, Append, AsEnumerable, Average, Cast, - Chunk, Concat, Contains, Count, DefaultIfEmpty, Distinct, DistinctBy, - ElementAt, ElementAtOrDefault, Empty, Except, ExceptBy, First, - FirstOrDefault, GroupBy, GroupJoin, Intersect, IntersectBy, Join, - Last, LastOrDefault, LongCount, Max, MaxBy, Min, MinBy, OfType, - OrderBy, OrderByDescending, Prepend, Range, Repeat, Reverse, - Select, SelectMany, SequenceEqual, Single, SingleOrDefault, Skip, - SkipLast, SkipWhile, Sum, Take, TakeLast, TakeWhile, ThenBy, - ThenByDescending, ToArray, ToDictionary, ToHashSet, ToList, - ToLookup, TryGetNonEnumeratedCount, Union, UnionBy, Where, Zip, - """; - - if (string.Compare(Shared.NetCore.GetNetCoreVersion(), "5") < 0) - { - expected = """ - Aggregate, All, Any, Append, AsEnumerable, Average, Cast, Concat, Contains, - Count, DefaultIfEmpty, Distinct, ElementAt, ElementAtOrDefault, Empty, - Except, First, FirstOrDefault, GroupBy, GroupJoin, Intersect, Join, Last, - LastOrDefault, LongCount, Max, Min, OfType, OrderBy, OrderByDescending, - Prepend, Range, Repeat, Reverse, Select, SelectMany, SequenceEqual, - Single, SingleOrDefault, Skip, SkipLast, SkipWhile, Sum, Take, TakeLast, TakeWhile, ThenBy, - ThenByDescending, ToArray, ToDictionary, ToHashSet, ToList, ToLookup, Union, Where, Zip, - """; - } - } + TestContext.WriteLine(dotnetCoreVersion); expected = expected.Replace("\r\n", string.Empty); expected = expected.Replace("\n", string.Empty); From 315421ade27facf3aa83390dc406588e7e66b393 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 24 Oct 2022 00:25:00 -0700 Subject: [PATCH 45/56] Renamed HelloWorld class to Program --- src/Chapter01.Tests/Listing01.02E.Tests.cs | 2 +- src/Chapter01/Listing01.02E.HelloWorldInC#.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Chapter01.Tests/Listing01.02E.Tests.cs b/src/Chapter01.Tests/Listing01.02E.Tests.cs index 345902b0f..9d7e25320 100644 --- a/src/Chapter01.Tests/Listing01.02E.Tests.cs +++ b/src/Chapter01.Tests/Listing01.02E.Tests.cs @@ -12,7 +12,7 @@ public void Main_InigoHello() @"Hello. My name is Inigo Montoya."; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, HelloWorld.Main); + expected, Program.Main); } } } \ No newline at end of file diff --git a/src/Chapter01/Listing01.02E.HelloWorldInC#.cs b/src/Chapter01/Listing01.02E.HelloWorldInC#.cs index 5e6ca4dd9..8a9b6ebdc 100644 --- a/src/Chapter01/Listing01.02E.HelloWorldInC#.cs +++ b/src/Chapter01/Listing01.02E.HelloWorldInC#.cs @@ -1,7 +1,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02E { #region INCLUDE - public class HelloWorld + public class Program { public static void Main() { From 33f0ef01cf011c95f675585f2cb0bca66c93f09d Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Sun, 23 Oct 2022 21:06:01 -0700 Subject: [PATCH 46/56] Automerge dependabot and add Github actions to dependabot (#374) --- .github/dependabot.yml | 7 ++++++- .github/workflows/build-and-test.yml | 11 +++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 79dd88cb1..fc452c249 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,4 +3,9 @@ updates: - package-ecosystem: "nuget" # See documentation for possible values directory: "/" # Location of package manifests schedule: - interval: "daily" + interval: "weekly" + + - package-ecosystem: "github-actions" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index cd8213dd5..02252a8df 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -36,3 +36,14 @@ jobs: run: dotnet build --no-restore - name: Test run: dotnet test --no-build --no-restore --verbosity normal + + automerge: + needs: [build-and-test] + runs-on: ubuntu-latest + + permissions: + pull-requests: write + contents: write + + steps: + - uses: fastify/github-action-merge-dependabot@v3.4.1 From 54151ec3ca7f8fb432f875077a2c1bb939d8b1e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Oct 2022 04:12:04 +0000 Subject: [PATCH 47/56] Bump actions/upload-artifact from 2 to 3 (#381) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3.
Release notes

Sourced from actions/upload-artifact's releases.

v3.0.0

What's Changed

  • Update default runtime to node16 (#293)
  • Update package-lock.json file version to 2 (#302)

Breaking Changes

With the update to Node 16, all scripts will now be run with Node 16 rather than Node 12.

v2.3.1

Fix for empty fails on Windows failing on upload #281

v2.3.0 Upload Artifact

  • Optimizations for faster uploads of larger files that are already compressed
  • Significantly improved logging when there are chunked uploads
  • Clarifications in logs around the upload size and prohibited characters that aren't allowed in the artifact name or any uploaded files
  • Various other small bugfixes & optimizations

v2.2.4

  • Retry on HTTP 500 responses from the service

v2.2.3

  • Fixes for proxy related issues

v2.2.2

  • Improved retryability and error handling

v2.2.1

  • Update used actions/core package to the latest version

v2.2.0

  • Support for artifact retention

v2.1.4

  • Add Third Party License Information

v2.1.3

  • Use updated version of the @action/artifact NPM package

v2.1.2

  • Increase upload chunk size from 4MB to 8MB
  • Detect case insensitive file uploads

v2.1.1

  • Fix for certain symlinks not correctly being identified as directories before starting uploads

v2.1.0

  • Support for uploading artifacts with multiple paths
  • Support for using exclude paths
  • Updates to dependencies

... (truncated)

Commits
  • 83fd05a Bump actions-core to v1.10.0 (#356)
  • 3cea537 Merge pull request #327 from actions/robherley/artifact-1.1.0
  • 849aa77 nvm use 12 & npm run release
  • 4d39869 recompile with correct ncc version
  • 2e0d362 bump @​actions/artifact to 1.1.0
  • 09a5d6a Merge pull request #320 from actions/dependabot/npm_and_yarn/ansi-regex-4.1.1
  • 189315d Bump ansi-regex from 4.1.0 to 4.1.1
  • d159c2d Merge pull request #297 from actions/dependabot/npm_and_yarn/ajv-6.12.6
  • c26a7ba Bump ajv from 6.11.0 to 6.12.6
  • 6ed6c72 Merge pull request #303 from actions/dependabot/npm_and_yarn/yargs-parser-13.1.2
  • Additional commits viewable in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/upload-artifact&package-manager=github_actions&previous-version=2&new-version=3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/Code-Analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Code-Analysis.yml b/.github/workflows/Code-Analysis.yml index b2fd6b7b0..0da93833e 100644 --- a/.github/workflows/Code-Analysis.yml +++ b/.github/workflows/Code-Analysis.yml @@ -33,7 +33,7 @@ jobs: # Upload the analysis results file - name: Upload analysis results - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: analysis_results.sarif path: ${{ steps.code-analysis.outputs.sarifFile }} From 9324dd28de1a780a0f1e3d308ea2ecf65c75c0b8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 23 Oct 2022 21:35:56 -0700 Subject: [PATCH 48/56] Bump actions/setup-dotnet from 2 to 3 (#380) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/setup-dotnet](https://github.com/actions/setup-dotnet) from 2 to 3.
Release notes

Sourced from actions/setup-dotnet's releases.

v3.0.0

This major release includes the following changes:

  • #219 New input dotnet-quality was added in #315:
    - uses: actions/setup-dotnet@v3
      with:
        dotnet-version: '6.0.x'
        dotnet-quality: 'preview'
    - run: dotnet build <my project>

More in detail here.

  • #241 The output variable dotnet-version which contains the installed by the action SDK version was added in #324:
    - uses: actions/setup-dotnet@v3
      id: cp310
      with:
        dotnet-version: '3.1.422'
- run: echo '${{ steps.cp310.outputs.dotnet-version }}' # outputs
3.1.422

More in detail here.

  • The dotnet-version syntax was updated and now it allows to specify the prerelease version without using include-prerelease input. The include-prerelease input was cut out:
    - uses: actions/setup-dotnet@v3
      with:
        dotnet-version: '5.0.0-preview.6'

More in detail here.

  • #251 The problem with out of support .NET version warnings was solved in #315.

Breaking changes:

  • Installation paths for Windows and Ubuntu images were changed to match the location of pre-installed SDKs. In more detail, read here.

Add support for Windows-arm

In scope of this release we add support for Windows-arm. Besides, we change getInput to getBooleanInput for include-prerelease.

Package updates, support for global json file in a subdirectory, installer scripts updates

This release includes the following PRs:

  • Adding support for the global-json-file input: #276 Example of usage:
    - uses: actions/setup-dotnet@v2
      with:
        global-json-file: csharp/global.json
    - run: dotnet build <my project>
      working-directory: csharp
    

... (truncated)

Commits
  • 4d4a70f Add logic for processing DOTNET_INSTALL_DIR environment variable (#332)
  • 70c3f4d Merge pull request #331 from rentziass/rentziass/update-actions-core
  • 9260643 Update @​actions/core to 1.10.0
  • 45c9f23 Enable ability to change .NET SDK installation directory by `DOTNET_INSTALL_D...
  • c7e7147 Add ability to write resolved version of SDK into the output variable (#324)
  • 0705ef0 Implement proposal stated in ADR for setup-dotnet v3 and functionality from f...
  • See full diff in compare view

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=actions/setup-dotnet&package-manager=github_actions&previous-version=2&new-version=3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/Code-Analysis.yml | 2 +- .github/workflows/LocalesTest.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/Code-Analysis.yml b/.github/workflows/Code-Analysis.yml index 0da93833e..1a3395afd 100644 --- a/.github/workflows/Code-Analysis.yml +++ b/.github/workflows/Code-Analysis.yml @@ -14,7 +14,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Setup dotnet SDK - uses: actions/setup-dotnet@v1 + uses: actions/setup-dotnet@v3 with: dotnet-version: | 3.1.x diff --git a/.github/workflows/LocalesTest.yml b/.github/workflows/LocalesTest.yml index 253612d7d..1e3b81dd4 100644 --- a/.github/workflows/LocalesTest.yml +++ b/.github/workflows/LocalesTest.yml @@ -16,7 +16,7 @@ jobs: steps: - uses: actions/checkout@v3 - name: Setup dotnet SDK - uses: actions/setup-dotnet@v2 + uses: actions/setup-dotnet@v3 with: dotnet-version: | 6.x From 4f1589b95829d4c77ad1070b4bb82c5496947d57 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 24 Oct 2022 00:18:20 -0700 Subject: [PATCH 49/56] Change extension on test/generated folders to "*.g" --- .gitignore | 4 ++-- ...Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 4 +++- src/Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1 | 4 ++-- .../Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index b378e23b8..a94f2d4cb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Files specific to this project: *.encrypt # Generated by one of the projects and left around on occasion. -src/Chapter10/ProcessExitTestProgram/ -HelloWorld/ +**/*.gc/ # Folders generated buy tests will use the *.g extension so they aren't check in. +src/Chapter01/HelloWorld/ # Don't ignore DLLs in the src/Shared/Lib folder (which are frequently ignored by default in the .gitignore_global file) !src/Shared/Lib/* diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 5cd7424ce..dcdaeace5 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -19,6 +19,8 @@ public class DisposeTests static string Ps1Path { get; } = Path.GetFullPath(Path.Join(Ps1DirectoryPath, "Listing10.23.RegisteringAFinalizerWithProcessExit.ps1"), Environment.CurrentDirectory); + private const string ProjectName = "ProcessExitTestProgram.g"; + [ClassInitialize] public static void ClassInitialize(TestContext testContext) { @@ -26,7 +28,7 @@ public static void ClassInitialize(TestContext testContext) Assert.AreEqual(0, RunPowerShellScript(testStage, out string psOutput), $"Script failed with $testStage='{testStage}'. psOutput:\n{psOutput}"); string projectFilePath = - Path.Join(Ps1DirectoryPath, "ProcessExitTestProgram", "ProcessExitTestProgram.csproj"); + Path.Join(Ps1DirectoryPath, ProjectName, $"{ProjectName}.csproj"); Assert.IsTrue(File.Exists(projectFilePath), $"The expected project file, '{projectFilePath}', was not created."); } diff --git a/src/Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1 b/src/Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1 index 9dd198a63..0cfdcfbb6 100644 --- a/src/Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1 +++ b/src/Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1 @@ -13,8 +13,8 @@ if('traceLevel' -notin $PSBoundParameters.Keys) { "@ } -[string]$LibraryProjectName = 'GeoCoordinates' -[string]$ConsoleProgramProjectName = 'GeoCoordinateProgram' +[string]$LibraryProjectName = 'GeoCoordinates.g' +[string]$ConsoleProgramProjectName = 'GeoCoordinateProgram.g' [xml]$directoryBuildPropsXml = ([xml](Get-Content "$PSScriptRoot/../../Directory.Build.props")) [string]$langVersion = $directoryBuildPropsXml.Project.PropertyGroup.LangVersion diff --git a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 index 8dfed0b50..35bd6c383 100644 --- a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 +++ b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 @@ -17,7 +17,7 @@ if(($TraceLevel -eq $null) -and 'TraceLevel' -notin $PSBoundParameters.Keys) { } #$LibraryProjectName = 'ProcessExit' -$ConsoleProgramProjectName = 'ProcessExitTestProgram' +$ConsoleProgramProjectName = 'ProcessExitTestProgram.g' [string]$projectDirectory = (Join-Path $PSScriptRoot $ConsoleProgramProjectName) From 73d3dac151ece21ab871e6359e521fcd6ad714e0 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 24 Oct 2022 08:35:28 -0700 Subject: [PATCH 50/56] Removed errant indent and whitespace --- .../Listing01.08.NoIndentationFormatting.cs | 2 +- src/Chapter01/Listing01.09.RemovingWhitespace.cs | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/Chapter01/Listing01.08.NoIndentationFormatting.cs b/src/Chapter01/Listing01.08.NoIndentationFormatting.cs index a2c863295..45582d740 100644 --- a/src/Chapter01/Listing01.08.NoIndentationFormatting.cs +++ b/src/Chapter01/Listing01.08.NoIndentationFormatting.cs @@ -5,7 +5,7 @@ public class HelloWorld { public static void Main() { - Console.WriteLine("Hello Inigo Montoya"); +Console.WriteLine("Hello Inigo Montoya"); } } #endregion INCLUDE diff --git a/src/Chapter01/Listing01.09.RemovingWhitespace.cs b/src/Chapter01/Listing01.09.RemovingWhitespace.cs index 7fdc7f0d5..fcf07c986 100644 --- a/src/Chapter01/Listing01.09.RemovingWhitespace.cs +++ b/src/Chapter01/Listing01.09.RemovingWhitespace.cs @@ -1,7 +1,6 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_09 -{ - #region INCLUDE - public class HelloWorld{public static void Main() -{ Console.WriteLine("Hello Inigo Montoya");}} - #endregion INCLUDE -} +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_09; + +#region INCLUDE +public class HelloWorld{public static void Main() +{Console.WriteLine("Hello Inigo Montoya");}} +#endregion INCLUDE From 6569cbf096c233ab0f8906e1ee163307869a17d1 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 24 Oct 2022 09:35:20 -0700 Subject: [PATCH 51/56] Added cleanup at start (in addition to end) --- ...ing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index dcdaeace5..453214e11 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -24,6 +24,8 @@ public class DisposeTests [ClassInitialize] public static void ClassInitialize(TestContext testContext) { + // Clean up at the start incase the class cleanup doesn't run (due to debug for example) + Assert.AreEqual(0, RunPowerShellScript("cleanup", out string _)); string testStage = "create"; Assert.AreEqual(0, RunPowerShellScript(testStage, out string psOutput), $"Script failed with $testStage='{testStage}'. psOutput:\n{psOutput}"); @@ -34,10 +36,10 @@ public static void ClassInitialize(TestContext testContext) } [ClassCleanup] - public static void RemoveProcessExitProj() + public static void ClassCleanup() { - Assert.AreEqual(0, RunPowerShellScript( - "cleanup", out string _)); + // No return check since an exception here will be ignored. + RunPowerShellScript("cleanup", out string _); } [DataTestMethod] From 8e3f5d4f58cfc926508bada2aedb1246b565d473 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 24 Oct 2022 09:51:38 -0700 Subject: [PATCH 52/56] Change extension on test/generated folders to "*.testing" --- .gitignore | 4 ++-- Directory.Build.targets | 3 +++ ...Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs | 2 +- src/Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1 | 4 ++-- .../Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index a94f2d4cb..89570d03f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ -# Files specific to this project: +# Files/Folders specific to this project: *.encrypt # Generated by one of the projects and left around on occasion. -**/*.gc/ # Folders generated buy tests will use the *.g extension so they aren't check in. +**/*.testing/ # Folders generated by tests will use the *.testing extension so they aren't checked in. src/Chapter01/HelloWorld/ # Don't ignore DLLs in the src/Shared/Lib folder (which are frequently ignored by default in the .gitignore_global file) diff --git a/Directory.Build.targets b/Directory.Build.targets index 7cc39cfa7..a2c51002b 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -6,6 +6,9 @@ "WarningsNotAsErrors" so they don't trigger a failure in the build. --> $(ExpectedWarnings) + + + diff --git a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs index 453214e11..e839e62fa 100644 --- a/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.23.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -19,7 +19,7 @@ public class DisposeTests static string Ps1Path { get; } = Path.GetFullPath(Path.Join(Ps1DirectoryPath, "Listing10.23.RegisteringAFinalizerWithProcessExit.ps1"), Environment.CurrentDirectory); - private const string ProjectName = "ProcessExitTestProgram.g"; + private const string ProjectName = "ProcessExitTestProgram.testing"; [ClassInitialize] public static void ClassInitialize(TestContext testContext) diff --git a/src/Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1 b/src/Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1 index 0cfdcfbb6..5d85a0dbf 100644 --- a/src/Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1 +++ b/src/Chapter10/Listing10.13.MakingTypesAvailableExternally.ps1 @@ -13,8 +13,8 @@ if('traceLevel' -notin $PSBoundParameters.Keys) { "@ } -[string]$LibraryProjectName = 'GeoCoordinates.g' -[string]$ConsoleProgramProjectName = 'GeoCoordinateProgram.g' +[string]$LibraryProjectName = 'GeoCoordinates.testing' +[string]$ConsoleProgramProjectName = 'GeoCoordinateProgram.testing' [xml]$directoryBuildPropsXml = ([xml](Get-Content "$PSScriptRoot/../../Directory.Build.props")) [string]$langVersion = $directoryBuildPropsXml.Project.PropertyGroup.LangVersion diff --git a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 index 35bd6c383..8355d249e 100644 --- a/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 +++ b/src/Chapter10/Listing10.23.RegisteringAFinalizerWithProcessExit.ps1 @@ -17,7 +17,7 @@ if(($TraceLevel -eq $null) -and 'TraceLevel' -notin $PSBoundParameters.Keys) { } #$LibraryProjectName = 'ProcessExit' -$ConsoleProgramProjectName = 'ProcessExitTestProgram.g' +$ConsoleProgramProjectName = 'ProcessExitTestProgram.testing' [string]$projectDirectory = (Join-Path $PSScriptRoot $ConsoleProgramProjectName) From 029f465b07450c83c3d7ce965e78af6dac0987a8 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 24 Oct 2022 11:34:31 -0700 Subject: [PATCH 53/56] Removed redundant System. namespace qualifier --- src/Chapter02/Listing02.01.SpecifyingLiteralValues.cs | 4 ++-- src/Chapter02/Listing02.02.SpecifyingALiteralDouble.cs | 2 +- .../Listing02.03.SpecifyingALiteralDecimal.cs | 2 +- src/Chapter02/Listing02.04.UsingTheDigitSeparator.cs | 2 +- src/Chapter02/Listing02.05.ExponentialNotation.cs | 2 +- src/Chapter02/Listing02.06.HexadecimalLiteralValue.cs | 2 +- src/Chapter02/Listing02.07.BinaryLiteralValue.cs | 2 +- ...sting02.08.ExamplesOfAHexadecimalFormatSpecifier.cs | 2 +- .../Listing02.09.FormattingUsingTheRFormatSpecifier.cs | 4 ++-- ...sting02.10.CaseInsensitiveComparisonOfTwoStrings.cs | 2 +- ...2.11.DisplayingASingleQuoteUsingAnEscapeSequence.cs | 2 +- ...ng02.12.UsingUnicodeEncodingToDisplayASmileyFace.cs | 4 ++-- ...ng02.13.UsingTheNewlineCharacterToInsertANewline.cs | 4 ++-- ...4.DisplayingATriangleUsingAVerbatimStringLiteral.cs | 2 +- src/Chapter02/Listing02.16.UsingStringsLengthMember.cs | 6 +++--- src/Chapter02/Listing02.17.Error-StringIsImmutable.cs | 6 +++--- src/Chapter02/Listing02.18.WorkingWithStrings.cs | 6 +++--- src/Chapter02/Listing02.19.AssigningNullToAString.cs | 2 +- .../Listing02.21.OverflowingAnIntegerValue.cs | 2 +- src/Chapter02/Listing02.22.ACheckedBlockExample.cs | 2 +- src/Chapter02/Listing02.23.AnUncheckedBlockExample.cs | 2 +- .../Listing02.27.TypeConversionUsingSystemConvert.cs | 4 ++-- .../Listing02.28.UsingToStringToConvertToAString.cs | 2 +- ....29.UsingTryParseInPlaceOfAnInvalidCastException.cs | 6 +++--- .../Listing02.30.UsingTryParseWithInlineOut.cs | 10 +++++----- 25 files changed, 42 insertions(+), 42 deletions(-) diff --git a/src/Chapter02/Listing02.01.SpecifyingLiteralValues.cs b/src/Chapter02/Listing02.01.SpecifyingLiteralValues.cs index 139ebb887..47d782eb0 100644 --- a/src/Chapter02/Listing02.01.SpecifyingLiteralValues.cs +++ b/src/Chapter02/Listing02.01.SpecifyingLiteralValues.cs @@ -5,9 +5,9 @@ public class Program public static void Main() { #region INCLUDE - System.Console.WriteLine(42); + Console.WriteLine(42); - System.Console.WriteLine(1.618034); + Console.WriteLine(1.618034); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.02.SpecifyingALiteralDouble.cs b/src/Chapter02/Listing02.02.SpecifyingALiteralDouble.cs index 8fd4630cd..c4a06ad7a 100644 --- a/src/Chapter02/Listing02.02.SpecifyingALiteralDouble.cs +++ b/src/Chapter02/Listing02.02.SpecifyingALiteralDouble.cs @@ -5,7 +5,7 @@ public class Program public static void Main() { #region INCLUDE - System.Console.WriteLine(1.6180339887498948); + Console.WriteLine(1.6180339887498948); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.03.SpecifyingALiteralDecimal.cs b/src/Chapter02/Listing02.03.SpecifyingALiteralDecimal.cs index 48f2a19f5..8258aa5b8 100644 --- a/src/Chapter02/Listing02.03.SpecifyingALiteralDecimal.cs +++ b/src/Chapter02/Listing02.03.SpecifyingALiteralDecimal.cs @@ -5,7 +5,7 @@ public class Program public static void Main() { #region INCLUDE - System.Console.WriteLine(1.6180339887498948M); + Console.WriteLine(1.6180339887498948M); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.04.UsingTheDigitSeparator.cs b/src/Chapter02/Listing02.04.UsingTheDigitSeparator.cs index be1f0ecb9..73e017ebd 100644 --- a/src/Chapter02/Listing02.04.UsingTheDigitSeparator.cs +++ b/src/Chapter02/Listing02.04.UsingTheDigitSeparator.cs @@ -5,7 +5,7 @@ public class Program public static void Main() { #region INCLUDE - System.Console.WriteLine(9_814_072_356M); + Console.WriteLine(9_814_072_356M); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.05.ExponentialNotation.cs b/src/Chapter02/Listing02.05.ExponentialNotation.cs index b6154b6c3..23633109f 100644 --- a/src/Chapter02/Listing02.05.ExponentialNotation.cs +++ b/src/Chapter02/Listing02.05.ExponentialNotation.cs @@ -5,7 +5,7 @@ public class Program public static void Main() { #region INCLUDE - System.Console.WriteLine(6.023E23F); + Console.WriteLine(6.023E23F); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.06.HexadecimalLiteralValue.cs b/src/Chapter02/Listing02.06.HexadecimalLiteralValue.cs index 133accccf..3acc6ec8c 100644 --- a/src/Chapter02/Listing02.06.HexadecimalLiteralValue.cs +++ b/src/Chapter02/Listing02.06.HexadecimalLiteralValue.cs @@ -6,7 +6,7 @@ public static void Main() { #region INCLUDE //Display the value 42 using a hexadecimal literal - System.Console.WriteLine(0x002A); + Console.WriteLine(0x002A); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.07.BinaryLiteralValue.cs b/src/Chapter02/Listing02.07.BinaryLiteralValue.cs index 09a92287c..18f570c29 100644 --- a/src/Chapter02/Listing02.07.BinaryLiteralValue.cs +++ b/src/Chapter02/Listing02.07.BinaryLiteralValue.cs @@ -6,7 +6,7 @@ public static void Main() { #region INCLUDE // Display the value 42 using a binary literal - System.Console.WriteLine(0b101010); + Console.WriteLine(0b101010); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.08.ExamplesOfAHexadecimalFormatSpecifier.cs b/src/Chapter02/Listing02.08.ExamplesOfAHexadecimalFormatSpecifier.cs index ba0cfaa44..2209b05cf 100644 --- a/src/Chapter02/Listing02.08.ExamplesOfAHexadecimalFormatSpecifier.cs +++ b/src/Chapter02/Listing02.08.ExamplesOfAHexadecimalFormatSpecifier.cs @@ -6,7 +6,7 @@ public static void Main() { #region INCLUDE //Displays "0x2A" - System.Console.WriteLine($"0x{42:X}"); + Console.WriteLine($"0x{42:X}"); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.09.FormattingUsingTheRFormatSpecifier.cs b/src/Chapter02/Listing02.09.FormattingUsingTheRFormatSpecifier.cs index 98391fd63..e33794f55 100644 --- a/src/Chapter02/Listing02.09.FormattingUsingTheRFormatSpecifier.cs +++ b/src/Chapter02/Listing02.09.FormattingUsingTheRFormatSpecifier.cs @@ -12,11 +12,11 @@ public static void Main() text = $"{number}"; result = double.Parse(text); - System.Console.WriteLine($"{result == number}: {result} == {number}"); + Console.WriteLine($"{result == number}: {result} == {number}"); text = string.Format("{0:R}", number); result = double.Parse(text); - System.Console.WriteLine($"{result == number}: {result} == {number}"); + Console.WriteLine($"{result == number}: {result} == {number}"); // ... #endregion INCLUDE diff --git a/src/Chapter02/Listing02.10.CaseInsensitiveComparisonOfTwoStrings.cs b/src/Chapter02/Listing02.10.CaseInsensitiveComparisonOfTwoStrings.cs index 79997bfae..50f0d1fe0 100644 --- a/src/Chapter02/Listing02.10.CaseInsensitiveComparisonOfTwoStrings.cs +++ b/src/Chapter02/Listing02.10.CaseInsensitiveComparisonOfTwoStrings.cs @@ -10,7 +10,7 @@ public static void Main() int comparison = string.Compare(option, "/Help", true); #endregion INCLUDE - System.Console.WriteLine($"{comparison}"); + Console.WriteLine($"{comparison}"); } } } diff --git a/src/Chapter02/Listing02.11.DisplayingASingleQuoteUsingAnEscapeSequence.cs b/src/Chapter02/Listing02.11.DisplayingASingleQuoteUsingAnEscapeSequence.cs index 10b00b8cc..43a1237fa 100644 --- a/src/Chapter02/Listing02.11.DisplayingASingleQuoteUsingAnEscapeSequence.cs +++ b/src/Chapter02/Listing02.11.DisplayingASingleQuoteUsingAnEscapeSequence.cs @@ -5,7 +5,7 @@ public class SingleQuote { public static void Main() { - System.Console.WriteLine('\''); + Console.WriteLine('\''); } } #endregion INCLUDE diff --git a/src/Chapter02/Listing02.12.UsingUnicodeEncodingToDisplayASmileyFace.cs b/src/Chapter02/Listing02.12.UsingUnicodeEncodingToDisplayASmileyFace.cs index 0278ddc8a..d330458a6 100644 --- a/src/Chapter02/Listing02.12.UsingUnicodeEncodingToDisplayASmileyFace.cs +++ b/src/Chapter02/Listing02.12.UsingUnicodeEncodingToDisplayASmileyFace.cs @@ -5,9 +5,9 @@ public class SingleQuote public static void Main() { #region INCLUDE - System.Console.Write('\u003A'); + Console.Write('\u003A'); - System.Console.WriteLine('\u0029'); + Console.WriteLine('\u0029'); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.13.UsingTheNewlineCharacterToInsertANewline.cs b/src/Chapter02/Listing02.13.UsingTheNewlineCharacterToInsertANewline.cs index fe2a9e0f8..e2b02e3cd 100644 --- a/src/Chapter02/Listing02.13.UsingTheNewlineCharacterToInsertANewline.cs +++ b/src/Chapter02/Listing02.13.UsingTheNewlineCharacterToInsertANewline.cs @@ -5,9 +5,9 @@ public class DuelOfWits public static void Main() { #region INCLUDE - System.Console.Write( + Console.Write( "\"Truly, you have a dizzying intellect.\""); - System.Console.Write("\n\"Wait 'til I get going!\"\n"); + Console.Write("\n\"Wait 'til I get going!\"\n"); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs b/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs index 029f56e6e..fd383cd86 100644 --- a/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs +++ b/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs @@ -5,7 +5,7 @@ public class Triangle public static void Main() { #region INCLUDE - System.Console.Write(@"begin + Console.Write(@"begin /\ / \ / \ diff --git a/src/Chapter02/Listing02.16.UsingStringsLengthMember.cs b/src/Chapter02/Listing02.16.UsingStringsLengthMember.cs index d17474a9b..6948002d5 100644 --- a/src/Chapter02/Listing02.16.UsingStringsLengthMember.cs +++ b/src/Chapter02/Listing02.16.UsingStringsLengthMember.cs @@ -7,10 +7,10 @@ public static void Main() { string palindrome; - System.Console.Write("Enter a palindrome: "); - palindrome = System.Console.ReadLine(); + Console.Write("Enter a palindrome: "); + palindrome = Console.ReadLine(); - System.Console.WriteLine( + Console.WriteLine( $"The palindrome \"{palindrome}\" is" #region HIGHLIGHT + $" {palindrome.Length} characters."); diff --git a/src/Chapter02/Listing02.17.Error-StringIsImmutable.cs b/src/Chapter02/Listing02.17.Error-StringIsImmutable.cs index 455c5225f..fc1c4f7af 100644 --- a/src/Chapter02/Listing02.17.Error-StringIsImmutable.cs +++ b/src/Chapter02/Listing02.17.Error-StringIsImmutable.cs @@ -7,15 +7,15 @@ public static void Main() { string text; - System.Console.Write("Enter text: "); - text = System.Console.ReadLine(); + Console.Write("Enter text: "); + text = Console.ReadLine(); #region HIGHLIGHT // UNEXPECTED: Does not convert text to uppercase text.ToUpper(); #endregion HIGHLIGHT - System.Console.WriteLine(text); + Console.WriteLine(text); } } #endregion INCLUDE diff --git a/src/Chapter02/Listing02.18.WorkingWithStrings.cs b/src/Chapter02/Listing02.18.WorkingWithStrings.cs index 31769512b..914546fe8 100644 --- a/src/Chapter02/Listing02.18.WorkingWithStrings.cs +++ b/src/Chapter02/Listing02.18.WorkingWithStrings.cs @@ -7,15 +7,15 @@ public static void Main() { string text, uppercase; - System.Console.Write("Enter text: "); - text = System.Console.ReadLine(); + Console.Write("Enter text: "); + text = Console.ReadLine(); // Return a new string in uppercase #region HIGHLIGHT uppercase = text.ToUpper(); #endregion HIGHLIGHT - System.Console.WriteLine(uppercase); + Console.WriteLine(uppercase); } } #endregion INCLUDE diff --git a/src/Chapter02/Listing02.19.AssigningNullToAString.cs b/src/Chapter02/Listing02.19.AssigningNullToAString.cs index 1c9b9d948..e2a7cc8ea 100644 --- a/src/Chapter02/Listing02.19.AssigningNullToAString.cs +++ b/src/Chapter02/Listing02.19.AssigningNullToAString.cs @@ -12,7 +12,7 @@ public static void Main() age = null; #region EXCLUDE - System.Console.WriteLine($"The age is: {age}"); + Console.WriteLine($"The age is: {age}"); #endregion EXCLUDE } #endregion INCLUDE diff --git a/src/Chapter02/Listing02.21.OverflowingAnIntegerValue.cs b/src/Chapter02/Listing02.21.OverflowingAnIntegerValue.cs index abcfd8bcb..34be67f0c 100644 --- a/src/Chapter02/Listing02.21.OverflowingAnIntegerValue.cs +++ b/src/Chapter02/Listing02.21.OverflowingAnIntegerValue.cs @@ -8,7 +8,7 @@ public static void Main() // int.MaxValue equals 2147483647 int n = int.MaxValue; n = n + 1; - System.Console.WriteLine(n); + Console.WriteLine(n); } } #endregion INCLUDE diff --git a/src/Chapter02/Listing02.22.ACheckedBlockExample.cs b/src/Chapter02/Listing02.22.ACheckedBlockExample.cs index b61786f02..9d0cfc852 100644 --- a/src/Chapter02/Listing02.22.ACheckedBlockExample.cs +++ b/src/Chapter02/Listing02.22.ACheckedBlockExample.cs @@ -12,7 +12,7 @@ public static void Main() // int.MaxValue equals 2147483647 int n = int.MaxValue; n = n + 1; - System.Console.WriteLine(n); + Console.WriteLine(n); #region HIGHLIGHT } #endregion HIGHLIGHT diff --git a/src/Chapter02/Listing02.23.AnUncheckedBlockExample.cs b/src/Chapter02/Listing02.23.AnUncheckedBlockExample.cs index c2f0c735b..d02900212 100644 --- a/src/Chapter02/Listing02.23.AnUncheckedBlockExample.cs +++ b/src/Chapter02/Listing02.23.AnUncheckedBlockExample.cs @@ -10,7 +10,7 @@ public static void Main() // int.MaxValue equals 2147483647 int n = int.MaxValue; n = n + 1; - System.Console.WriteLine(n); + Console.WriteLine(n); } } } diff --git a/src/Chapter02/Listing02.27.TypeConversionUsingSystemConvert.cs b/src/Chapter02/Listing02.27.TypeConversionUsingSystemConvert.cs index 2c205e539..8c1d8d365 100644 --- a/src/Chapter02/Listing02.27.TypeConversionUsingSystemConvert.cs +++ b/src/Chapter02/Listing02.27.TypeConversionUsingSystemConvert.cs @@ -6,8 +6,8 @@ public static void Main() { #region INCLUDE string middleCText = "261.626"; - double middleC = System.Convert.ToDouble(middleCText); - bool boolean = System.Convert.ToBoolean(middleC); + double middleC = Convert.ToDouble(middleCText); + bool boolean = Convert.ToBoolean(middleC); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.28.UsingToStringToConvertToAString.cs b/src/Chapter02/Listing02.28.UsingToStringToConvertToAString.cs index 20236bf32..86113cfbe 100644 --- a/src/Chapter02/Listing02.28.UsingToStringToConvertToAString.cs +++ b/src/Chapter02/Listing02.28.UsingToStringToConvertToAString.cs @@ -8,7 +8,7 @@ public static void Main() bool boolean = true; string text = boolean.ToString(); // Display "True" - System.Console.WriteLine(text); + Console.WriteLine(text); #endregion INCLUDE } } diff --git a/src/Chapter02/Listing02.29.UsingTryParseInPlaceOfAnInvalidCastException.cs b/src/Chapter02/Listing02.29.UsingTryParseInPlaceOfAnInvalidCastException.cs index 6db85ffbf..f7fb7aecd 100644 --- a/src/Chapter02/Listing02.29.UsingTryParseInPlaceOfAnInvalidCastException.cs +++ b/src/Chapter02/Listing02.29.UsingTryParseInPlaceOfAnInvalidCastException.cs @@ -10,8 +10,8 @@ public static void Main() double number; string input; - System.Console.Write("Enter a number: "); - input = System.Console.ReadLine(); + Console.Write("Enter a number: "); + input = Console.ReadLine(); #region HIGHLIGHT if (double.TryParse(input, out number)) { @@ -21,7 +21,7 @@ public static void Main() else #endregion HIGHLIGHT { - System.Console.WriteLine( + Console.WriteLine( "The text entered was not a valid number."); } #endregion INCLUDE diff --git a/src/Chapter02/Listing02.30.UsingTryParseWithInlineOut.cs b/src/Chapter02/Listing02.30.UsingTryParseWithInlineOut.cs index 5a1d8d005..ed1681d42 100644 --- a/src/Chapter02/Listing02.30.UsingTryParseWithInlineOut.cs +++ b/src/Chapter02/Listing02.30.UsingTryParseWithInlineOut.cs @@ -8,11 +8,11 @@ public static void Main() // double number; string input; - System.Console.Write("Enter a number: "); - input = System.Console.ReadLine(); + Console.Write("Enter a number: "); + input = Console.ReadLine(); if (double.TryParse(input, out double number)) { - System.Console.WriteLine( + Console.WriteLine( #region HIGHLIGHT $"input was parsed successfully to {number}."); #endregion HIGHLIGHT @@ -20,11 +20,11 @@ public static void Main() else { // Note: number scope is here too (although not assigned) - System.Console.WriteLine( + Console.WriteLine( "The text entered was not a valid number."); } - System.Console.WriteLine( + Console.WriteLine( $"'number' currently has the value: {number}"); #endregion INCLUDE } From 908df2257ab88073f6ebd5a73bf322b53c7f4a14 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Mon, 24 Oct 2022 11:35:53 -0700 Subject: [PATCH 54/56] Remove unnecessary using declaratives These using statements became unnecessary due to implicit using statements. --- src/Shared/Program.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Shared/Program.cs b/src/Shared/Program.cs index df19feff3..a8e31e226 100644 --- a/src/Shared/Program.cs +++ b/src/Shared/Program.cs @@ -1,11 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics.CodeAnalysis; -using System.Linq; +using System.Diagnostics.CodeAnalysis; using System.Reflection; using System.Runtime.CompilerServices; using System.Text.RegularExpressions; -using System.Threading.Tasks; namespace AddisonWesley.Michaelis.EssentialCSharp.Shared { From b4a84b93f4508bbfc2d835e2308b2808467d1390 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 28 Oct 2022 20:46:15 -0700 Subject: [PATCH 55/56] Renumbered Chaper 1 listings --- src/Chapter01.Tests/Listing01.02C.Tests.cs | 20 ------------------ src/Chapter01.Tests/Listing01.02D.Tests.cs | 18 ---------------- ...g01.02B.Tests.cs => Listing01.03.Tests.cs} | 6 +++--- src/Chapter01.Tests/Listing01.04.Tests.cs | 13 +++++++----- src/Chapter01.Tests/Listing01.05.Tests.cs | 14 ++++++------- ...g01.02E.Tests.cs => Listing01.06.Tests.cs} | 6 +++--- src/Chapter01.Tests/Listing01.08.Tests.cs | 12 +++++------ src/Chapter01.Tests/Listing01.09.Tests.cs | 13 ++++++------ src/Chapter01.Tests/Listing01.10.Tests.cs | 12 +++++------ src/Chapter01.Tests/Listing01.11.Tests.cs | 13 ++++++------ src/Chapter01.Tests/Listing01.12.Tests.cs | 13 +++++------- src/Chapter01.Tests/Listing01.13.Tests.cs | 12 +++++------ src/Chapter01.Tests/Listing01.14.Tests.cs | 17 +++++++-------- src/Chapter01.Tests/Listing01.15.Tests.cs | 13 ++++++------ src/Chapter01.Tests/Listing01.16.Tests.cs | 10 ++++----- src/Chapter01.Tests/Listing01.17.Tests.cs | 14 +++++-------- src/Chapter01.Tests/Listing01.18.Tests.cs | 10 ++++----- src/Chapter01.Tests/Listing01.19.Tests.cs | 8 +++---- src/Chapter01.Tests/Listing01.20.Tests.cs | 21 +++++++++++++++++++ src/Chapter01.Tests/Listing01.21.Tests.cs | 21 +++++++++++++++++++ ...ting01.03.MultipleStatementsOneOneLine.cs} | 2 +- ...1.04.MultipleStatementsOnSeparateLines.cs} | 2 +- ...SplittingAStatementAcrossMultipleLines.cs} | 2 +- ...InC#.cs => Listing01.06.HelloWorldInC#.cs} | 2 +- ... => Listing01.07.BasicClassDeclaration.cs} | 2 +- ...> Listing01.08.BreakingApartHelloWorld.cs} | 2 +- ....TheMainMethodWithParametersAndAReturn.cs} | 2 +- ...> Listing01.10.NoIndentationFormatting.cs} | 2 +- ....cs => Listing01.11.RemovingWhitespace.cs} | 2 +- ...ng01.12.DeclaringAndAssigningAVariable.cs} | 2 +- ...eclaringTwoVariablesWithinOneStatement.cs} | 2 +- ...sting01.14.ChangingTheValueOfAVariable.cs} | 2 +- ...tReturningAValueThatCanBeassignedAgain.cs} | 2 +- ...isting01.16.UsingSystemConsoleReadLine.cs} | 2 +- ...=> Listing01.17.UsingSystemConsoleRead.cs} | 2 +- ....18.FormattingUsingStringInterpolation.cs} | 2 +- ....19.FormattingUsingCompositeFormatting.cs} | 2 +- ...dPlaceholdersAndCorrespondingVariables.cs} | 2 +- ....cs => Listing01.21.CommentingYourCode.cs} | 2 +- ...put.cs => Listing01.22.SampleCILOutput.cs} | 4 ++-- 40 files changed, 154 insertions(+), 154 deletions(-) delete mode 100644 src/Chapter01.Tests/Listing01.02C.Tests.cs delete mode 100644 src/Chapter01.Tests/Listing01.02D.Tests.cs rename src/Chapter01.Tests/{Listing01.02B.Tests.cs => Listing01.03.Tests.cs} (83%) rename src/Chapter01.Tests/{Listing01.02E.Tests.cs => Listing01.06.Tests.cs} (84%) create mode 100644 src/Chapter01.Tests/Listing01.20.Tests.cs create mode 100644 src/Chapter01.Tests/Listing01.21.Tests.cs rename src/Chapter01/{Listing01.02B.MultipleStatementsOneOneLine.cs => Listing01.03.MultipleStatementsOneOneLine.cs} (96%) rename src/Chapter01/{Listing01.02C.MultipleStatementsOnSeparateLines.cs => Listing01.04.MultipleStatementsOnSeparateLines.cs} (97%) rename src/Chapter01/{Listing01.02D.SplittingAStatementAcrossMultipleLines.cs => Listing01.05.SplittingAStatementAcrossMultipleLines.cs} (96%) rename src/Chapter01/{Listing01.02E.HelloWorldInC#.cs => Listing01.06.HelloWorldInC#.cs} (96%) rename src/Chapter01/{Listing01.03.BasicClassDeclaration.cs => Listing01.07.BasicClassDeclaration.cs} (94%) rename src/Chapter01/{Listing01.04.BreakingApartHelloWorld.cs => Listing01.08.BreakingApartHelloWorld.cs} (98%) rename src/Chapter01/{Listing01.05.TheMainMethodWithParametersAndAReturn.cs => Listing01.09.TheMainMethodWithParametersAndAReturn.cs} (97%) rename src/Chapter01/{Listing01.08.NoIndentationFormatting.cs => Listing01.10.NoIndentationFormatting.cs} (95%) rename src/Chapter01/{Listing01.09.RemovingWhitespace.cs => Listing01.11.RemovingWhitespace.cs} (95%) rename src/Chapter01/{Listing01.10.DeclaringAndAssigningAVariable.cs => Listing01.12.DeclaringAndAssigningAVariable.cs} (97%) rename src/Chapter01/{Listing01.11.DeclaringTwoVariablesWithinOneStatement.cs => Listing01.13.DeclaringTwoVariablesWithinOneStatement.cs} (98%) rename src/Chapter01/{Listing01.12.ChangingTheValueOfAVariable.cs => Listing01.14.ChangingTheValueOfAVariable.cs} (98%) rename src/Chapter01/{Listing01.13.AssignmentReturningAValueThatCanBeassignedAgain.cs => Listing01.15.AssignmentReturningAValueThatCanBeassignedAgain.cs} (98%) rename src/Chapter01/{Listing01.14.UsingSystemConsoleReadLine.cs => Listing01.16.UsingSystemConsoleReadLine.cs} (98%) rename src/Chapter01/{Listing01.15.UsingSystemConsoleRead.cs => Listing01.17.UsingSystemConsoleRead.cs} (97%) rename src/Chapter01/{Listing01.16.FormattingUsingStringInterpolation.cs => Listing01.18.FormattingUsingStringInterpolation.cs} (98%) rename src/Chapter01/{Listing01.17.FormattingUsingCompositeFormatting.cs => Listing01.19.FormattingUsingCompositeFormatting.cs} (98%) rename src/Chapter01/{Listing01.18.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs => Listing01.20.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs} (98%) rename src/Chapter01/{Listing01.19.CommentingYourCode.cs => Listing01.21.CommentingYourCode.cs} (98%) rename src/Chapter01/{Listing01.20.SampleCILOutput.cs => Listing01.22.SampleCILOutput.cs} (97%) diff --git a/src/Chapter01.Tests/Listing01.02C.Tests.cs b/src/Chapter01.Tests/Listing01.02C.Tests.cs deleted file mode 100644 index b42cd4a40..000000000 --- a/src/Chapter01.Tests/Listing01.02C.Tests.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02C.Tests -{ - [TestClass] - public class HelloWorldTests - { - [TestMethod] - public void Main_InigoHello() - { - const string expected = - @"Down -Side -Up"; - - IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, HelloWorld.Main); - } - } -} \ No newline at end of file diff --git a/src/Chapter01.Tests/Listing01.02D.Tests.cs b/src/Chapter01.Tests/Listing01.02D.Tests.cs deleted file mode 100644 index 8ffeb5081..000000000 --- a/src/Chapter01.Tests/Listing01.02D.Tests.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; - -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02D.Tests -{ - [TestClass] - public class HelloWorldTests - { - [TestMethod] - public void Main_InigoHello() - { - const string expected = - @"Hello. My name is Inigo Montoya."; - - IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, HelloWorld.Main); - } - } -} \ No newline at end of file diff --git a/src/Chapter01.Tests/Listing01.02B.Tests.cs b/src/Chapter01.Tests/Listing01.03.Tests.cs similarity index 83% rename from src/Chapter01.Tests/Listing01.02B.Tests.cs rename to src/Chapter01.Tests/Listing01.03.Tests.cs index 5f73830b4..89f0e8cf1 100644 --- a/src/Chapter01.Tests/Listing01.02B.Tests.cs +++ b/src/Chapter01.Tests/Listing01.03.Tests.cs @@ -1,6 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02B.Tests +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03.Tests { [TestClass] public class HelloWorldTests @@ -16,4 +16,4 @@ public void Main_UpDown() expected, HelloWorld.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.04.Tests.cs b/src/Chapter01.Tests/Listing01.04.Tests.cs index ff0253da7..c6c79599c 100644 --- a/src/Chapter01.Tests/Listing01.04.Tests.cs +++ b/src/Chapter01.Tests/Listing01.04.Tests.cs @@ -1,17 +1,20 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_04.Tests { [TestClass] - public class ProgramTests + public class HelloWorldTests { [TestMethod] public void Main_InigoHello() { - const string expected = @"Hello, My name is Inigo Montoya"; + const string expected = + @"Down +Side +Up"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, Program.Main); + expected, HelloWorld.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.05.Tests.cs b/src/Chapter01.Tests/Listing01.05.Tests.cs index 8289943e7..09ee5ca86 100644 --- a/src/Chapter01.Tests/Listing01.05.Tests.cs +++ b/src/Chapter01.Tests/Listing01.05.Tests.cs @@ -1,18 +1,18 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; -using System; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_05.Tests { [TestClass] - public class ProgramTests + public class HelloWorldTests { [TestMethod] - public void Main_GiveNone_GetZero() + public void Main_InigoHello() { - int expected = 0; - int value = Program.Main(Array.Empty()); + const string expected = + @"Hello. My name is Inigo Montoya."; - Assert.AreEqual(expected, value); + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, HelloWorld.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.02E.Tests.cs b/src/Chapter01.Tests/Listing01.06.Tests.cs similarity index 84% rename from src/Chapter01.Tests/Listing01.02E.Tests.cs rename to src/Chapter01.Tests/Listing01.06.Tests.cs index 9d7e25320..c0fa40ca6 100644 --- a/src/Chapter01.Tests/Listing01.02E.Tests.cs +++ b/src/Chapter01.Tests/Listing01.06.Tests.cs @@ -1,6 +1,6 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02E.Tests +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_06.Tests { [TestClass] public class HelloWorldTests @@ -15,4 +15,4 @@ public void Main_InigoHello() expected, Program.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.08.Tests.cs b/src/Chapter01.Tests/Listing01.08.Tests.cs index 9a284f8c2..95e2d5527 100644 --- a/src/Chapter01.Tests/Listing01.08.Tests.cs +++ b/src/Chapter01.Tests/Listing01.08.Tests.cs @@ -1,17 +1,17 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_08.Tests { [TestClass] - public class HelloWorldTests + public class ProgramTests { [TestMethod] - public void Main_HelloToInigo() + public void Main_InigoHello() { - const string expected = @"Hello Inigo Montoya"; + const string expected = @"Hello, My name is Inigo Montoya"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, HelloWorld.Main); + expected, Program.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.09.Tests.cs b/src/Chapter01.Tests/Listing01.09.Tests.cs index 4a66d6ffa..8fcd472d7 100644 --- a/src/Chapter01.Tests/Listing01.09.Tests.cs +++ b/src/Chapter01.Tests/Listing01.09.Tests.cs @@ -1,4 +1,5 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using System; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_09.Tests { @@ -6,12 +7,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_09.Tests public class ProgramTests { [TestMethod] - public void Main_HelloToInigo() + public void Main_GiveNone_GetZero() { - const string expected = @"Hello Inigo Montoya"; + int expected = 0; + int value = Program.Main(Array.Empty()); - IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, HelloWorld.Main); + Assert.AreEqual(expected, value); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.10.Tests.cs b/src/Chapter01.Tests/Listing01.10.Tests.cs index 505db793d..7330f7c9f 100644 --- a/src/Chapter01.Tests/Listing01.10.Tests.cs +++ b/src/Chapter01.Tests/Listing01.10.Tests.cs @@ -1,17 +1,17 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_10.Tests { [TestClass] - public class MiracleMaxTests + public class HelloWorldTests { [TestMethod] - public void Main_StormCastleShort() + public void Main_HelloToInigo() { - const string expected = @"Have fun storming the castle!"; + const string expected = @"Hello Inigo Montoya"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, MiracleMax.Main); + expected, HelloWorld.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.11.Tests.cs b/src/Chapter01.Tests/Listing01.11.Tests.cs index 8ebd6f3e8..821eb50b6 100644 --- a/src/Chapter01.Tests/Listing01.11.Tests.cs +++ b/src/Chapter01.Tests/Listing01.11.Tests.cs @@ -3,16 +3,15 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11.Tests { [TestClass] - public class HelloWorldTests + public class ProgramTests { [TestMethod] - public void Main_InigoMantra_ProperOutput() + public void Main_HelloToInigo() { - const string expected = -@"My name is Inigo Montoya. -You killed my father...."; + const string expected = @"Hello Inigo Montoya"; - IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, HelloWorld.Main); + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, HelloWorld.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.12.Tests.cs b/src/Chapter01.Tests/Listing01.12.Tests.cs index 42ca0caca..ee4d51e82 100644 --- a/src/Chapter01.Tests/Listing01.12.Tests.cs +++ b/src/Chapter01.Tests/Listing01.12.Tests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_12.Tests { @@ -6,15 +6,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_12.Tests public class MiracleMaxTests { [TestMethod] - public void Main_StormCastleLong() + public void Main_StormCastleShort() { - const string expected = -@"Have fun storming the castle! -Think it will work? -It would take a miracle."; + const string expected = @"Have fun storming the castle!"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, StormingTheCastle.Main); + expected, MiracleMax.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.13.Tests.cs b/src/Chapter01.Tests/Listing01.13.Tests.cs index 3c71ecd45..2f6dca2d1 100644 --- a/src/Chapter01.Tests/Listing01.13.Tests.cs +++ b/src/Chapter01.Tests/Listing01.13.Tests.cs @@ -3,16 +3,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_13.Tests { [TestClass] - public class Listing01_13_Tests + public class HelloWorldTests { [TestMethod] - public void Main_ItWouldTakeAMiracle_OutputWrittenToConsole() + public void Main_InigoMantra_ProperOutput() { const string expected = -@"It would take a miracle."; +@"My name is Inigo Montoya. +You killed my father...."; - IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, StormingTheCastle.Main); + IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, HelloWorld.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.14.Tests.cs b/src/Chapter01.Tests/Listing01.14.Tests.cs index 9b00a990d..c05d3adba 100644 --- a/src/Chapter01.Tests/Listing01.14.Tests.cs +++ b/src/Chapter01.Tests/Listing01.14.Tests.cs @@ -1,21 +1,20 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_14.Tests { [TestClass] - public class HeyYouTests + public class MiracleMaxTests { [TestMethod] - public void Main_InputInigoMontoya_WriteNothing() + public void Main_StormCastleLong() { const string expected = -@"Hey you! -Enter your first name: <>Enter your last name: <>"; +@"Have fun storming the castle! +Think it will work? +It would take a miracle."; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, HeyYou.Main); + expected, StormingTheCastle.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.15.Tests.cs b/src/Chapter01.Tests/Listing01.15.Tests.cs index 82a35cfd7..c32f37eb0 100644 --- a/src/Chapter01.Tests/Listing01.15.Tests.cs +++ b/src/Chapter01.Tests/Listing01.15.Tests.cs @@ -1,17 +1,18 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_15.Tests { [TestClass] - public class ProgramTests + public class Listing01_13_Tests { [TestMethod] - public void Main_InputOne_WriteOne() + public void Main_ItWouldTakeAMiracle_OutputWrittenToConsole() { - const string expected = @"1<<1>>"; + const string expected = +@"It would take a miracle."; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, Program.Main); + expected, StormingTheCastle.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.16.Tests.cs b/src/Chapter01.Tests/Listing01.16.Tests.cs index 6bc0bb8f4..6fa9abda1 100644 --- a/src/Chapter01.Tests/Listing01.16.Tests.cs +++ b/src/Chapter01.Tests/Listing01.16.Tests.cs @@ -1,21 +1,21 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_16.Tests { [TestClass] - public class ProgramTests + public class HeyYouTests { [TestMethod] - public void Main_InputInigoMontoya_WriteFirstLast() + public void Main_InputInigoMontoya_WriteNothing() { const string expected = @"Hey you! Enter your first name: <>Enter your last name: <>Your full name is Inigo Montoya."; +>>"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, HeyYou.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.17.Tests.cs b/src/Chapter01.Tests/Listing01.17.Tests.cs index 919150ef6..35d11440f 100644 --- a/src/Chapter01.Tests/Listing01.17.Tests.cs +++ b/src/Chapter01.Tests/Listing01.17.Tests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_17.Tests { @@ -6,16 +6,12 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_17.Tests public class ProgramTests { [TestMethod] - public void Main_InputInigoMontoya_WriteFirstLast() + public void Main_InputOne_WriteOne() { - const string expected = -@"Hey you! -Enter your first name: <>Enter your last name: <>Your full name is Inigo Montoya."; + const string expected = @"1<<1>>"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, HeyYou.Main); + expected, Program.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.18.Tests.cs b/src/Chapter01.Tests/Listing01.18.Tests.cs index 9574333cc..233aa8ff7 100644 --- a/src/Chapter01.Tests/Listing01.18.Tests.cs +++ b/src/Chapter01.Tests/Listing01.18.Tests.cs @@ -1,4 +1,4 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; +using Microsoft.VisualStudio.TestTools.UnitTesting; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_18.Tests { @@ -6,16 +6,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_18.Tests public class ProgramTests { [TestMethod] - public void Main_InputInigoMontoya_WriteLastFirst() + public void Main_InputInigoMontoya_WriteFirstLast() { const string expected = @"Hey you! Enter your first name: <>Enter your last name: <>Your full name is Montoya, Inigo."; +>>Your full name is Inigo Montoya."; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, Program.Main); + expected, HeyYou.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.19.Tests.cs b/src/Chapter01.Tests/Listing01.19.Tests.cs index 30bd8d445..05f1baaa4 100644 --- a/src/Chapter01.Tests/Listing01.19.Tests.cs +++ b/src/Chapter01.Tests/Listing01.19.Tests.cs @@ -6,16 +6,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_19.Tests public class ProgramTests { [TestMethod] - public void Main_InputInigoMontoya_WriteLastFirst() + public void Main_InputInigoMontoya_WriteFirstLast() { const string expected = @"Hey you! Enter your first name: <>Enter your last name: <>Your full name is Montoya, Inigo."; +>>Your full name is Inigo Montoya."; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - expected, CommentSamples.Main); + expected, HeyYou.Main); } } -} \ No newline at end of file +} diff --git a/src/Chapter01.Tests/Listing01.20.Tests.cs b/src/Chapter01.Tests/Listing01.20.Tests.cs new file mode 100644 index 000000000..008a7a470 --- /dev/null +++ b/src/Chapter01.Tests/Listing01.20.Tests.cs @@ -0,0 +1,21 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_20.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_InputInigoMontoya_WriteLastFirst() + { + const string expected = +@"Hey you! +Enter your first name: <>Enter your last name: <>Your full name is Montoya, Inigo."; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, Program.Main); + } + } +} diff --git a/src/Chapter01.Tests/Listing01.21.Tests.cs b/src/Chapter01.Tests/Listing01.21.Tests.cs new file mode 100644 index 000000000..1c5a66821 --- /dev/null +++ b/src/Chapter01.Tests/Listing01.21.Tests.cs @@ -0,0 +1,21 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_21.Tests +{ + [TestClass] + public class ProgramTests + { + [TestMethod] + public void Main_InputInigoMontoya_WriteLastFirst() + { + const string expected = +@"Hey you! +Enter your first name: <>Enter your last name: <>Your full name is Montoya, Inigo."; + + IntelliTect.TestTools.Console.ConsoleAssert.Expect( + expected, CommentSamples.Main); + } + } +} diff --git a/src/Chapter01/Listing01.02B.MultipleStatementsOneOneLine.cs b/src/Chapter01/Listing01.03.MultipleStatementsOneOneLine.cs similarity index 96% rename from src/Chapter01/Listing01.02B.MultipleStatementsOneOneLine.cs rename to src/Chapter01/Listing01.03.MultipleStatementsOneOneLine.cs index 97fd4fe53..bc0376b14 100644 --- a/src/Chapter01/Listing01.02B.MultipleStatementsOneOneLine.cs +++ b/src/Chapter01/Listing01.03.MultipleStatementsOneOneLine.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02B +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03 { public class HelloWorld { diff --git a/src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs b/src/Chapter01/Listing01.04.MultipleStatementsOnSeparateLines.cs similarity index 97% rename from src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs rename to src/Chapter01/Listing01.04.MultipleStatementsOnSeparateLines.cs index 95c3c7129..c7040c245 100644 --- a/src/Chapter01/Listing01.02C.MultipleStatementsOnSeparateLines.cs +++ b/src/Chapter01/Listing01.04.MultipleStatementsOnSeparateLines.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02C +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_04 { public class HelloWorld { diff --git a/src/Chapter01/Listing01.02D.SplittingAStatementAcrossMultipleLines.cs b/src/Chapter01/Listing01.05.SplittingAStatementAcrossMultipleLines.cs similarity index 96% rename from src/Chapter01/Listing01.02D.SplittingAStatementAcrossMultipleLines.cs rename to src/Chapter01/Listing01.05.SplittingAStatementAcrossMultipleLines.cs index 5edb62189..dd30d8921 100644 --- a/src/Chapter01/Listing01.02D.SplittingAStatementAcrossMultipleLines.cs +++ b/src/Chapter01/Listing01.05.SplittingAStatementAcrossMultipleLines.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02D +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_05 { public class HelloWorld { diff --git a/src/Chapter01/Listing01.02E.HelloWorldInC#.cs b/src/Chapter01/Listing01.06.HelloWorldInC#.cs similarity index 96% rename from src/Chapter01/Listing01.02E.HelloWorldInC#.cs rename to src/Chapter01/Listing01.06.HelloWorldInC#.cs index 8a9b6ebdc..79fcd62be 100644 --- a/src/Chapter01/Listing01.02E.HelloWorldInC#.cs +++ b/src/Chapter01/Listing01.06.HelloWorldInC#.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_02E +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_06 { #region INCLUDE public class Program diff --git a/src/Chapter01/Listing01.03.BasicClassDeclaration.cs b/src/Chapter01/Listing01.07.BasicClassDeclaration.cs similarity index 94% rename from src/Chapter01/Listing01.03.BasicClassDeclaration.cs rename to src/Chapter01/Listing01.07.BasicClassDeclaration.cs index ed417e637..20c646c2b 100644 --- a/src/Chapter01/Listing01.03.BasicClassDeclaration.cs +++ b/src/Chapter01/Listing01.07.BasicClassDeclaration.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_07 { #region INCLUDE public class HelloWorld diff --git a/src/Chapter01/Listing01.04.BreakingApartHelloWorld.cs b/src/Chapter01/Listing01.08.BreakingApartHelloWorld.cs similarity index 98% rename from src/Chapter01/Listing01.04.BreakingApartHelloWorld.cs rename to src/Chapter01/Listing01.08.BreakingApartHelloWorld.cs index c62f01bb6..32f606294 100644 --- a/src/Chapter01/Listing01.04.BreakingApartHelloWorld.cs +++ b/src/Chapter01/Listing01.08.BreakingApartHelloWorld.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_04 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_08 { #region INCLUDE public class Program // BEGIN Class definition diff --git a/src/Chapter01/Listing01.05.TheMainMethodWithParametersAndAReturn.cs b/src/Chapter01/Listing01.09.TheMainMethodWithParametersAndAReturn.cs similarity index 97% rename from src/Chapter01/Listing01.05.TheMainMethodWithParametersAndAReturn.cs rename to src/Chapter01/Listing01.09.TheMainMethodWithParametersAndAReturn.cs index 10dfc8427..e1af597ad 100644 --- a/src/Chapter01/Listing01.05.TheMainMethodWithParametersAndAReturn.cs +++ b/src/Chapter01/Listing01.09.TheMainMethodWithParametersAndAReturn.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_05 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_09 { public class Program { diff --git a/src/Chapter01/Listing01.08.NoIndentationFormatting.cs b/src/Chapter01/Listing01.10.NoIndentationFormatting.cs similarity index 95% rename from src/Chapter01/Listing01.08.NoIndentationFormatting.cs rename to src/Chapter01/Listing01.10.NoIndentationFormatting.cs index 45582d740..ef9755445 100644 --- a/src/Chapter01/Listing01.08.NoIndentationFormatting.cs +++ b/src/Chapter01/Listing01.10.NoIndentationFormatting.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_08 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_10 { #region INCLUDE public class HelloWorld diff --git a/src/Chapter01/Listing01.09.RemovingWhitespace.cs b/src/Chapter01/Listing01.11.RemovingWhitespace.cs similarity index 95% rename from src/Chapter01/Listing01.09.RemovingWhitespace.cs rename to src/Chapter01/Listing01.11.RemovingWhitespace.cs index fcf07c986..8557e5ab1 100644 --- a/src/Chapter01/Listing01.09.RemovingWhitespace.cs +++ b/src/Chapter01/Listing01.11.RemovingWhitespace.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_09; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11 #region INCLUDE public class HelloWorld{public static void Main() diff --git a/src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs b/src/Chapter01/Listing01.12.DeclaringAndAssigningAVariable.cs similarity index 97% rename from src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs rename to src/Chapter01/Listing01.12.DeclaringAndAssigningAVariable.cs index 6a5925185..3935219bd 100644 --- a/src/Chapter01/Listing01.10.DeclaringAndAssigningAVariable.cs +++ b/src/Chapter01/Listing01.12.DeclaringAndAssigningAVariable.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_10 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_12 { #region INCLUDE public class MiracleMax diff --git a/src/Chapter01/Listing01.11.DeclaringTwoVariablesWithinOneStatement.cs b/src/Chapter01/Listing01.13.DeclaringTwoVariablesWithinOneStatement.cs similarity index 98% rename from src/Chapter01/Listing01.11.DeclaringTwoVariablesWithinOneStatement.cs rename to src/Chapter01/Listing01.13.DeclaringTwoVariablesWithinOneStatement.cs index 67cf4b9a2..482a46a61 100644 --- a/src/Chapter01/Listing01.11.DeclaringTwoVariablesWithinOneStatement.cs +++ b/src/Chapter01/Listing01.13.DeclaringTwoVariablesWithinOneStatement.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_13 { public class HelloWorld { diff --git a/src/Chapter01/Listing01.12.ChangingTheValueOfAVariable.cs b/src/Chapter01/Listing01.14.ChangingTheValueOfAVariable.cs similarity index 98% rename from src/Chapter01/Listing01.12.ChangingTheValueOfAVariable.cs rename to src/Chapter01/Listing01.14.ChangingTheValueOfAVariable.cs index 1bc9fc7a2..3d9f8d567 100644 --- a/src/Chapter01/Listing01.12.ChangingTheValueOfAVariable.cs +++ b/src/Chapter01/Listing01.14.ChangingTheValueOfAVariable.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_12 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_14 { #region INCLUDE public class StormingTheCastle diff --git a/src/Chapter01/Listing01.13.AssignmentReturningAValueThatCanBeassignedAgain.cs b/src/Chapter01/Listing01.15.AssignmentReturningAValueThatCanBeassignedAgain.cs similarity index 98% rename from src/Chapter01/Listing01.13.AssignmentReturningAValueThatCanBeassignedAgain.cs rename to src/Chapter01/Listing01.15.AssignmentReturningAValueThatCanBeassignedAgain.cs index 2e004c494..850dcbcb4 100644 --- a/src/Chapter01/Listing01.13.AssignmentReturningAValueThatCanBeassignedAgain.cs +++ b/src/Chapter01/Listing01.15.AssignmentReturningAValueThatCanBeassignedAgain.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_13 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_15 { #region INCLUDE public class StormingTheCastle diff --git a/src/Chapter01/Listing01.14.UsingSystemConsoleReadLine.cs b/src/Chapter01/Listing01.16.UsingSystemConsoleReadLine.cs similarity index 98% rename from src/Chapter01/Listing01.14.UsingSystemConsoleReadLine.cs rename to src/Chapter01/Listing01.16.UsingSystemConsoleReadLine.cs index b72777f7d..6184fe6e9 100644 --- a/src/Chapter01/Listing01.14.UsingSystemConsoleReadLine.cs +++ b/src/Chapter01/Listing01.16.UsingSystemConsoleReadLine.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_14 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_16 { #region INCLUDE public class HeyYou diff --git a/src/Chapter01/Listing01.15.UsingSystemConsoleRead.cs b/src/Chapter01/Listing01.17.UsingSystemConsoleRead.cs similarity index 97% rename from src/Chapter01/Listing01.15.UsingSystemConsoleRead.cs rename to src/Chapter01/Listing01.17.UsingSystemConsoleRead.cs index 3bdbc2860..6cc9d5673 100644 --- a/src/Chapter01/Listing01.15.UsingSystemConsoleRead.cs +++ b/src/Chapter01/Listing01.17.UsingSystemConsoleRead.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_15 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_17 { public class Program { diff --git a/src/Chapter01/Listing01.16.FormattingUsingStringInterpolation.cs b/src/Chapter01/Listing01.18.FormattingUsingStringInterpolation.cs similarity index 98% rename from src/Chapter01/Listing01.16.FormattingUsingStringInterpolation.cs rename to src/Chapter01/Listing01.18.FormattingUsingStringInterpolation.cs index 72287d026..5b2a320e5 100644 --- a/src/Chapter01/Listing01.16.FormattingUsingStringInterpolation.cs +++ b/src/Chapter01/Listing01.18.FormattingUsingStringInterpolation.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_16 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_18 { #region INCLUDE public class HeyYou diff --git a/src/Chapter01/Listing01.17.FormattingUsingCompositeFormatting.cs b/src/Chapter01/Listing01.19.FormattingUsingCompositeFormatting.cs similarity index 98% rename from src/Chapter01/Listing01.17.FormattingUsingCompositeFormatting.cs rename to src/Chapter01/Listing01.19.FormattingUsingCompositeFormatting.cs index 609b4114d..88ef16dbd 100644 --- a/src/Chapter01/Listing01.17.FormattingUsingCompositeFormatting.cs +++ b/src/Chapter01/Listing01.19.FormattingUsingCompositeFormatting.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_17 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_19 { #region INCLUDE public class HeyYou diff --git a/src/Chapter01/Listing01.18.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs b/src/Chapter01/Listing01.20.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs similarity index 98% rename from src/Chapter01/Listing01.18.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs rename to src/Chapter01/Listing01.20.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs index f650bd900..e7b2b345b 100644 --- a/src/Chapter01/Listing01.18.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs +++ b/src/Chapter01/Listing01.20.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_18 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_20 { public class Program { diff --git a/src/Chapter01/Listing01.19.CommentingYourCode.cs b/src/Chapter01/Listing01.21.CommentingYourCode.cs similarity index 98% rename from src/Chapter01/Listing01.19.CommentingYourCode.cs rename to src/Chapter01/Listing01.21.CommentingYourCode.cs index 9f8e69585..15f7d51e9 100644 --- a/src/Chapter01/Listing01.19.CommentingYourCode.cs +++ b/src/Chapter01/Listing01.21.CommentingYourCode.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_19; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_21 #region INCLUDE public class CommentSamples diff --git a/src/Chapter01/Listing01.20.SampleCILOutput.cs b/src/Chapter01/Listing01.22.SampleCILOutput.cs similarity index 97% rename from src/Chapter01/Listing01.20.SampleCILOutput.cs rename to src/Chapter01/Listing01.22.SampleCILOutput.cs index acec609b7..a8c93bfe7 100644 --- a/src/Chapter01/Listing01.20.SampleCILOutput.cs +++ b/src/Chapter01/Listing01.22.SampleCILOutput.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_20 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_22 { /* #region INCLUDE @@ -72,4 +72,4 @@ .maxstack 8 } // End of class HelloWorld.Program #endregion INCLUDE */ -} \ No newline at end of file +} From 0702d127fa626898bd5aef53917cc357be93f330 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Fri, 28 Oct 2022 20:53:21 -0700 Subject: [PATCH 56/56] Updated with missing semicolons from running ListingManager --- src/Chapter01/Listing01.11.RemovingWhitespace.cs | 2 +- src/Chapter01/Listing01.21.CommentingYourCode.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Chapter01/Listing01.11.RemovingWhitespace.cs b/src/Chapter01/Listing01.11.RemovingWhitespace.cs index 8557e5ab1..66b7aba50 100644 --- a/src/Chapter01/Listing01.11.RemovingWhitespace.cs +++ b/src/Chapter01/Listing01.11.RemovingWhitespace.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11; #region INCLUDE public class HelloWorld{public static void Main() diff --git a/src/Chapter01/Listing01.21.CommentingYourCode.cs b/src/Chapter01/Listing01.21.CommentingYourCode.cs index 15f7d51e9..a03aaade9 100644 --- a/src/Chapter01/Listing01.21.CommentingYourCode.cs +++ b/src/Chapter01/Listing01.21.CommentingYourCode.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_21 +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_21; #region INCLUDE public class CommentSamples