diff --git a/README.md b/README.md index d9a5b962..73ac6396 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# EssentialCSharp - C#本质论 +# EssentialCSharp - C#本质论 本项目包含《C# 12.0本质论》的源代码,2024年清华大学出版社出版。 @@ -58,7 +58,9 @@ ## 测试 -注:中文版请忽略。 +测试断言按中文版译稿及本仓库的配套示例维护,覆盖现有的 net6.0、net7.0 和 net8.0 目标框架。 + +部分清单刻意演示编译错误或运行时异常;对应测试会核对编译诊断或预期异常,不应为了通过测试而消除这些教学示例中的错误。 许多代码清单都有相应的单元测试。 diff --git a/src/Chapter01.Tests/Listing01.01.Tests.cs b/src/Chapter01.Tests/Listing01.01.Tests.cs index 5a7adfac..d31c8465 100644 --- a/src/Chapter01.Tests/Listing01.01.Tests.cs +++ b/src/Chapter01.Tests/Listing01.01.Tests.cs @@ -1,4 +1,4 @@ -using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; +using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01.Tests; @@ -27,7 +27,7 @@ public void CreateAndRunNewConsoleProject() // produced the expected output. Assert.IsTrue( psOutput.Contains( - $"{Environment.NewLine}Hello. My name is Inigo Montoya.{Environment.NewLine}"), + $"{Environment.NewLine}你好,我叫Inigo Montoya。{Environment.NewLine}"), "The expected HelloWorld output was not found."); // If the output is in English diff --git a/src/Chapter01.Tests/Listing01.03.Tests.cs b/src/Chapter01.Tests/Listing01.03.Tests.cs index 9ca9c5c5..9606afcb 100644 --- a/src/Chapter01.Tests/Listing01.03.Tests.cs +++ b/src/Chapter01.Tests/Listing01.03.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03.Tests; [TestClass] @@ -8,8 +8,8 @@ public class HelloWorldTests public void Main_UpDown() { const string expected = -@"Up -Down"; +@"上 +下"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, HelloWorld.Main); diff --git a/src/Chapter01.Tests/Listing01.04.Tests.cs b/src/Chapter01.Tests/Listing01.04.Tests.cs index a878942b..ca9de61f 100644 --- a/src/Chapter01.Tests/Listing01.04.Tests.cs +++ b/src/Chapter01.Tests/Listing01.04.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_04.Tests; [TestClass] @@ -8,9 +8,9 @@ public class HelloWorldTests public void Main_InigoHello() { const string expected = - @"Down -Side -Up"; + @"上 +中 +下"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, HelloWorld.Main); diff --git a/src/Chapter01.Tests/Listing01.05.Tests.cs b/src/Chapter01.Tests/Listing01.05.Tests.cs index 2647bffb..e867e641 100644 --- a/src/Chapter01.Tests/Listing01.05.Tests.cs +++ b/src/Chapter01.Tests/Listing01.05.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_05.Tests; [TestClass] @@ -8,7 +8,7 @@ public class HelloWorldTests public void Main_InigoHello() { const string expected = - @"Hello. My name is Inigo Montoya."; + @"你好,我叫Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, HelloWorld.Main); diff --git a/src/Chapter01.Tests/Listing01.06.Tests.cs b/src/Chapter01.Tests/Listing01.06.Tests.cs index 123e9ada..d63f3bc5 100644 --- a/src/Chapter01.Tests/Listing01.06.Tests.cs +++ b/src/Chapter01.Tests/Listing01.06.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_06.Tests; [TestClass] @@ -8,7 +8,7 @@ public class HelloWorldTests public void Main_InigoHello() { const string expected = - @"Hello. My name is Inigo Montoya."; + @"你好,我叫Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter01.Tests/Listing01.08.Tests.cs b/src/Chapter01.Tests/Listing01.08.Tests.cs index 1652c29d..a684defe 100644 --- a/src/Chapter01.Tests/Listing01.08.Tests.cs +++ b/src/Chapter01.Tests/Listing01.08.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_08.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void Main_InigoHello() { - const string expected = @"Hello, My name is Inigo Montoya"; + const string expected = @"你好,我叫Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter01.Tests/Listing01.10.Tests.cs b/src/Chapter01.Tests/Listing01.10.Tests.cs index 9bd04f95..286b789b 100644 --- a/src/Chapter01.Tests/Listing01.10.Tests.cs +++ b/src/Chapter01.Tests/Listing01.10.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_10.Tests; [TestClass] @@ -7,7 +7,7 @@ public class HelloWorldTests [TestMethod] public void Main_HelloToInigo() { - const string expected = @"Hello Inigo Montoya"; + const string expected = @"你好,Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, HelloWorld.Main); diff --git a/src/Chapter01.Tests/Listing01.11.Tests.cs b/src/Chapter01.Tests/Listing01.11.Tests.cs index 6b7f6d50..a4449f30 100644 --- a/src/Chapter01.Tests/Listing01.11.Tests.cs +++ b/src/Chapter01.Tests/Listing01.11.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void Main_HelloToInigo() { - const string expected = @"Hello Inigo Montoya"; + const string expected = @"你好,Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, HelloWorld.Main); diff --git a/src/Chapter01.Tests/Listing01.12.Tests.cs b/src/Chapter01.Tests/Listing01.12.Tests.cs index d3f4b2f7..cc8490a9 100644 --- a/src/Chapter01.Tests/Listing01.12.Tests.cs +++ b/src/Chapter01.Tests/Listing01.12.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_12.Tests; [TestClass] @@ -7,7 +7,7 @@ public class MiracleMaxTests [TestMethod] public void Main_StormCastleShort() { - const string expected = @"Have fun storming the castle!"; + const string expected = @"愉快地袭击古堡吧!"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, MiracleMax.Main); diff --git a/src/Chapter01.Tests/Listing01.13.Tests.cs b/src/Chapter01.Tests/Listing01.13.Tests.cs index 344631a7..def43781 100644 --- a/src/Chapter01.Tests/Listing01.13.Tests.cs +++ b/src/Chapter01.Tests/Listing01.13.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_13.Tests; [TestClass] @@ -8,8 +8,8 @@ public class HelloWorldTests public void Main_InigoMantra_ProperOutput() { const string expected = -@"My name is Inigo Montoya. -You killed my father...."; +@"你好,我叫Inigo Montoya。 +你杀死了我的父亲...."; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, HelloWorld.Main); } diff --git a/src/Chapter01.Tests/Listing01.14.Tests.cs b/src/Chapter01.Tests/Listing01.14.Tests.cs index fe32aaac..59fb381d 100644 --- a/src/Chapter01.Tests/Listing01.14.Tests.cs +++ b/src/Chapter01.Tests/Listing01.14.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_14.Tests; [TestClass] @@ -8,9 +8,9 @@ public class MiracleMaxTests public void Main_StormCastleLong() { const string expected = -@"Have fun storming the castle! -Think it will work? -It would take a miracle."; +@"愉快地袭击古堡吧! +你觉得可以吗? +这需要奇迹。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, StormingTheCastle.Main); diff --git a/src/Chapter01.Tests/Listing01.15.Tests.cs b/src/Chapter01.Tests/Listing01.15.Tests.cs index 520f8518..f587b494 100644 --- a/src/Chapter01.Tests/Listing01.15.Tests.cs +++ b/src/Chapter01.Tests/Listing01.15.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_15.Tests; [TestClass] @@ -8,7 +8,7 @@ public class Listing01_13_Tests public void Main_ItWouldTakeAMiracle_OutputWrittenToConsole() { const string expected = -@"It would take a miracle."; +@"这需要奇迹。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, StormingTheCastle.Main); diff --git a/src/Chapter01.Tests/Listing01.16.Tests.cs b/src/Chapter01.Tests/Listing01.16.Tests.cs index 264fa257..27f74a64 100644 --- a/src/Chapter01.Tests/Listing01.16.Tests.cs +++ b/src/Chapter01.Tests/Listing01.16.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_16.Tests; [TestClass] @@ -8,9 +8,9 @@ public class HeyYouTests public void Main_InputInigoMontoya_WriteNothing() { const string expected = -@"Hey you! -Enter your first name: <>Enter your last name: <>请输入你的姓氏: <>"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter01.Tests/Listing01.17.Tests.cs b/src/Chapter01.Tests/Listing01.17.Tests.cs index 7116ae34..91dad34e 100644 --- a/src/Chapter01.Tests/Listing01.17.Tests.cs +++ b/src/Chapter01.Tests/Listing01.17.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_17.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void Main_InputOne_WriteOne() { - const string expected = @"1<<1>>"; + const string expected = "随意输入,按Enter键结束:<<1\r>>1"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter01.Tests/Listing01.18.Tests.cs b/src/Chapter01.Tests/Listing01.18.Tests.cs index 585cf033..f7e4613f 100644 --- a/src/Chapter01.Tests/Listing01.18.Tests.cs +++ b/src/Chapter01.Tests/Listing01.18.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_18.Tests; [TestClass] @@ -8,10 +8,10 @@ public class ProgramTests public void Main_InputInigoMontoya_WriteFirstLast() { const string expected = -@"Hey you! -Enter your first name: <>Enter your last name: <>Your full name is Inigo Montoya."; +@"嘿,你! +请输入你的名字: <>请输入你的姓氏: <>你的全名是Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, HeyYou.Main); diff --git a/src/Chapter01.Tests/Listing01.19.Tests.cs b/src/Chapter01.Tests/Listing01.19.Tests.cs index 53512da4..133456bc 100644 --- a/src/Chapter01.Tests/Listing01.19.Tests.cs +++ b/src/Chapter01.Tests/Listing01.19.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_19.Tests; [TestClass] @@ -8,10 +8,10 @@ public class ProgramTests public void Main_InputInigoMontoya_WriteFirstLast() { const string expected = -@"Hey you! -Enter your first name: <>Enter your last name: <>Your full name is Inigo Montoya."; +@"嘿,你! +请输入你的名字: <>请输入你的姓氏: <>你的全名是Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, HeyYou.Main); diff --git a/src/Chapter01.Tests/Listing01.20.Tests.cs b/src/Chapter01.Tests/Listing01.20.Tests.cs index fd9568ce..0dea7eb0 100644 --- a/src/Chapter01.Tests/Listing01.20.Tests.cs +++ b/src/Chapter01.Tests/Listing01.20.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_20.Tests; [TestClass] @@ -8,10 +8,10 @@ public class ProgramTests public void Main_InputInigoMontoya_WriteLastFirst() { const string expected = -@"Hey you! -Enter your first name: <>Enter your last name: <>Your full name is Montoya, Inigo."; +@"嘿,你! +请输入你的名字: <>请输入你的姓氏: <>你的全名是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 index a6227396..a7fdeb5c 100644 --- a/src/Chapter01.Tests/Listing01.21.Tests.cs +++ b/src/Chapter01.Tests/Listing01.21.Tests.cs @@ -1,17 +1,17 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_21.Tests; [TestClass] 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."; +@"嘿,你! +请输入你的名字: <>请输入你的姓氏: <>你的全名是Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, CommentSamples.Main); diff --git a/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 b/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 index 019a72c1..95b04b23 100644 --- a/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 +++ b/src/Chapter01/Listing01.01.HelloWorldInC#.ps1 @@ -1,4 +1,4 @@ -[CmdletBinding()] +[CmdletBinding()] param( [int]$traceLevel ) @@ -10,26 +10,27 @@ if('traceLevel' -notin $PSBoundParameters.Keys) { - 1: Trace script lines as they run. - 2: Trace script lines, variable assignments, function calls, and scripts. -"@ +"@ } try { Get-Item .\HelloWorld -ErrorAction Ignore | ForEach-Object { Start-Sleep 10;Remove-Item -Recurse $_ } - $startLocation = Get-Location + $startLocation = Get-Location Set-PSDebug -Trace $traceLevel New-Item -ItemType Directory ./HelloWorld Set-Location ./HelloWorld/ dotnet new console + if ($LASTEXITCODE -ne 0) { throw "dotnet new failed with exit code $LASTEXITCODE" } Get-Content Program.cs - $codeListing = + $codeListing = @" class HelloWorld { static void Main() { - Console.WriteLine(""Äãºã¬ÎҽÐInigo Montoya¡£""); + Console.WriteLine("你好,我叫Inigo Montoya。"); } } "@ @@ -37,6 +38,7 @@ class HelloWorld $codeListing > Program.cs Get-Content Program.cs dotnet run + if ($LASTEXITCODE -ne 0) { throw "dotnet run failed with exit code $LASTEXITCODE" } } finally { Set-PSDebug -Off diff --git a/src/Chapter01/Listing01.03.MultipleStatementsOneOneLine.cs b/src/Chapter01/Listing01.03.MultipleStatementsOneOneLine.cs index c95d5f00..357efe7a 100644 --- a/src/Chapter01/Listing01.03.MultipleStatementsOneOneLine.cs +++ b/src/Chapter01/Listing01.03.MultipleStatementsOneOneLine.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_03; @@ -7,7 +7,7 @@ public class HelloWorld public static void Main() { #region INCLUDE - Console.WriteLine("ÉÏ"); Console.WriteLine("ÏÂ"); + Console.WriteLine("上"); Console.WriteLine("下"); #endregion INCLUDE } } diff --git a/src/Chapter01/Listing01.04.MultipleStatementsOnSeparateLines.cs b/src/Chapter01/Listing01.04.MultipleStatementsOnSeparateLines.cs index d293614d..b9c6fc4f 100644 --- a/src/Chapter01/Listing01.04.MultipleStatementsOnSeparateLines.cs +++ b/src/Chapter01/Listing01.04.MultipleStatementsOnSeparateLines.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_04; @@ -7,9 +7,9 @@ public class HelloWorld public static void Main() { #region INCLUDE - Console.WriteLine("ÉÏ"); - Console.WriteLine("ÖÐ"); - Console.WriteLine("ÏÂ"); + Console.WriteLine("上"); + Console.WriteLine("中"); + Console.WriteLine("下"); #endregion INCLUDE } } diff --git a/src/Chapter01/Listing01.05.SplittingAStatementAcrossMultipleLines.cs b/src/Chapter01/Listing01.05.SplittingAStatementAcrossMultipleLines.cs index 5b7f76a3..6e0cdca6 100644 --- a/src/Chapter01/Listing01.05.SplittingAStatementAcrossMultipleLines.cs +++ b/src/Chapter01/Listing01.05.SplittingAStatementAcrossMultipleLines.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_05; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_05; public class HelloWorld { @@ -6,7 +6,7 @@ public static void Main() { #region INCLUDE Console.WriteLine( - "Äãºã¬ÎҽÐInigo Montoya¡£"); + "你好,我叫Inigo Montoya。"); #endregion INCLUDE } } diff --git a/src/Chapter01/Listing01.06.HelloWorldInC#.cs b/src/Chapter01/Listing01.06.HelloWorldInC#.cs index 505a9c52..60c064e4 100644 --- a/src/Chapter01/Listing01.06.HelloWorldInC#.cs +++ b/src/Chapter01/Listing01.06.HelloWorldInC#.cs @@ -1,11 +1,11 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_06; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_06; #region INCLUDE public class Program { public static void Main() { - System.Console.WriteLine("Äãºã¬ÎҽÐInigo Montoya¡£"); + System.Console.WriteLine("你好,我叫Inigo Montoya。"); } } #endregion INCLUDE diff --git a/src/Chapter01/Listing01.10.NoIndentationFormatting.cs b/src/Chapter01/Listing01.10.NoIndentationFormatting.cs index 0a115740..5caf03a6 100644 --- a/src/Chapter01/Listing01.10.NoIndentationFormatting.cs +++ b/src/Chapter01/Listing01.10.NoIndentationFormatting.cs @@ -1,11 +1,11 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_10; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_10; #region INCLUDE public class HelloWorld { public static void Main() { -Console.WriteLine("Äãºã¬Inigo Montoya¡£"); +Console.WriteLine("你好,Inigo Montoya。"); } } #endregion INCLUDE diff --git a/src/Chapter01/Listing01.11.RemovingWhitespace.cs b/src/Chapter01/Listing01.11.RemovingWhitespace.cs index 3bc44909..e1bec124 100644 --- a/src/Chapter01/Listing01.11.RemovingWhitespace.cs +++ b/src/Chapter01/Listing01.11.RemovingWhitespace.cs @@ -1,6 +1,6 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_11; #region INCLUDE public class HelloWorld{public static void Main() -{Console.WriteLine("Äãºã¬Inigo Montoya¡£");}} +{Console.WriteLine("你好,Inigo Montoya。");}} #endregion INCLUDE diff --git a/src/Chapter01/Listing01.13.DeclaringTwoVariablesWithinOneStatement.cs b/src/Chapter01/Listing01.13.DeclaringTwoVariablesWithinOneStatement.cs index 5c513f86..7a7ed611 100644 --- a/src/Chapter01/Listing01.13.DeclaringTwoVariablesWithinOneStatement.cs +++ b/src/Chapter01/Listing01.13.DeclaringTwoVariablesWithinOneStatement.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_13; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_13; public class HelloWorld { @@ -8,8 +8,8 @@ public static void Main() string message1, message2; #endregion INCLUDE - message1 = "Äãºã¬ÎҽÐInigo Montoya¡£" ; - message2 = "ÄãɱËÀÁËÎҵĸ¸Ç×...."; + message1 = "你好,我叫Inigo Montoya。" ; + message2 = "你杀死了我的父亲...."; Console.WriteLine(message1); Console.WriteLine(message2); diff --git a/src/Chapter01/Listing01.14.ChangingTheValueOfAVariable.cs b/src/Chapter01/Listing01.14.ChangingTheValueOfAVariable.cs index ab5cfb32..5d0f4723 100644 --- a/src/Chapter01/Listing01.14.ChangingTheValueOfAVariable.cs +++ b/src/Chapter01/Listing01.14.ChangingTheValueOfAVariable.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_14; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_14; #region INCLUDE public class StormingTheCastle @@ -6,14 +6,14 @@ public class StormingTheCastle public static void Main() { string valerie; - string miracleMax = "Óä¿ìµØϮ»÷¹ű¤°ɣ¡"; + string miracleMax = "愉快地袭击古堡吧!"; - valerie = "Äã¾õµÿÉÒÔÂð?"; + valerie = "你觉得可以吗?"; Console.WriteLine(miracleMax); Console.WriteLine(valerie); - miracleMax = "ÕâÐèҪÆ漣¡£"; + miracleMax = "这需要奇迹。"; Console.WriteLine(miracleMax); } } diff --git a/src/Chapter01/Listing01.15.AssignmentReturningAValueThatCanBeassignedAgain.cs b/src/Chapter01/Listing01.15.AssignmentReturningAValueThatCanBeassignedAgain.cs index d51d4071..9026a073 100644 --- a/src/Chapter01/Listing01.15.AssignmentReturningAValueThatCanBeassignedAgain.cs +++ b/src/Chapter01/Listing01.15.AssignmentReturningAValueThatCanBeassignedAgain.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_15; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_15; #region INCLUDE public class StormingTheCastle @@ -7,7 +7,7 @@ public static void Main() { // ... string requirements, miracleMax; - requirements = miracleMax = "ÕâÐèҪÆ漣¡£"; + requirements = miracleMax = "这需要奇迹。"; #region EXCLUDE Console.WriteLine(miracleMax); #endregion EXCLUDE diff --git a/src/Chapter01/Listing01.16.UsingSystemConsoleReadLine.cs b/src/Chapter01/Listing01.16.UsingSystemConsoleReadLine.cs index 1f458c4d..03817753 100644 --- a/src/Chapter01/Listing01.16.UsingSystemConsoleReadLine.cs +++ b/src/Chapter01/Listing01.16.UsingSystemConsoleReadLine.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_16; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_16; #region INCLUDE public class HeyYou @@ -8,12 +8,12 @@ public static void Main() string firstName; string lastName; - Console.WriteLine("º٣¬Ä㣡"); + Console.WriteLine("嘿,你!"); - Console.Write("ÇëÊäÈëÄãµÄÃû×Ö: "); + Console.Write("请输入你的名字: "); firstName = Console.ReadLine(); - Console.Write("ÇëÊäÈëÄãµÄÐÕÊÏ: "); + Console.Write("请输入你的姓氏: "); lastName = Console.ReadLine(); } } diff --git a/src/Chapter01/Listing01.18.FormattingUsingStringInterpolation.cs b/src/Chapter01/Listing01.18.FormattingUsingStringInterpolation.cs index 0eeb8b10..338569f0 100644 --- a/src/Chapter01/Listing01.18.FormattingUsingStringInterpolation.cs +++ b/src/Chapter01/Listing01.18.FormattingUsingStringInterpolation.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_18; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_18; #region INCLUDE public class HeyYou @@ -8,16 +8,16 @@ public static void Main() string firstName; string lastName; - Console.WriteLine("º٣¬Ä㣡"); + Console.WriteLine("嘿,你!"); - Console.Write("ÇëÊäÈëÄãµÄÃû×Ö: "); + Console.Write("请输入你的名字: "); firstName = Console.ReadLine(); - Console.Write("ÇëÊäÈëÄãµÄÐÕÊÏ: "); + Console.Write("请输入你的姓氏: "); lastName = Console.ReadLine(); Console.WriteLine( - $"ÄãµÄȫÃûÊÇ{firstName} {lastName}¡£"); + $"你的全名是{firstName} {lastName}。"); } } diff --git a/src/Chapter01/Listing01.19.FormattingUsingCompositeFormatting.cs b/src/Chapter01/Listing01.19.FormattingUsingCompositeFormatting.cs index 643d0609..491c9544 100644 --- a/src/Chapter01/Listing01.19.FormattingUsingCompositeFormatting.cs +++ b/src/Chapter01/Listing01.19.FormattingUsingCompositeFormatting.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_19; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_19; #region INCLUDE public class HeyYou @@ -8,16 +8,16 @@ public static void Main() string firstName; string lastName; - Console.WriteLine("º٣¬Ä㣡"); + Console.WriteLine("嘿,你!"); - Console.Write("ÇëÊäÈëÄãµÄÃû×Ö: "); + Console.Write("请输入你的名字: "); firstName = Console.ReadLine(); - Console.Write("ÇëÊäÈëÄãµÄÐÕÊÏ: "); + Console.Write("请输入你的姓氏: "); lastName = Console.ReadLine(); Console.WriteLine( - "ÄãµÄȫÃûÊÇ{0} {1}¡£", firstName, lastName); + "你的全名是{0} {1}。", firstName, lastName); } } diff --git a/src/Chapter01/Listing01.20.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs b/src/Chapter01/Listing01.20.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs index d41855c5..a6c95798 100644 --- a/src/Chapter01/Listing01.20.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs +++ b/src/Chapter01/Listing01.20.SwappingTheIndexedPlaceholdersAndCorrespondingVariables.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_20; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_20; public class Program { @@ -7,16 +7,16 @@ public static void Main() string firstName; string lastName; - Console.WriteLine("º٣¬Ä㣡"); + Console.WriteLine("嘿,你!"); - Console.Write("ÇëÊäÈëÄãµÄÃû×Ö: "); + Console.Write("请输入你的名字: "); firstName = Console.ReadLine(); - Console.Write("ÇëÊäÈëÄãµÄÐÕÊÏ: "); + Console.Write("请输入你的姓氏: "); lastName = Console.ReadLine(); #region INCLUDE - Console.WriteLine("ÄãµÄȫÃûÊÇ{1}, {0}¡£", firstName, lastName); + Console.WriteLine("你的全名是{1}, {0}。", firstName, lastName); #endregion INCLUDE } } diff --git a/src/Chapter01/TopLevelStatementWrapperForListing01.01.cs b/src/Chapter01/TopLevelStatementWrapperForListing01.01.cs index 1aca26d7..40576440 100644 --- a/src/Chapter01/TopLevelStatementWrapperForListing01.01.cs +++ b/src/Chapter01/TopLevelStatementWrapperForListing01.01.cs @@ -1,4 +1,4 @@ -// See https://aka.ms/new-console-template for more information +// See https://aka.ms/new-console-template for more information // this file redirects debug break points to Listing01.01.HelloWorldInC#.cs // allowing for the appearance that the top-level statement file of Listing01.01.HelloWorldInC#.cs is what is being ran. namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter01.Listing01_01; @@ -10,6 +10,6 @@ public static void Main() // the #line directive reroutes the debugger's line mapper from this file to "Listing01.01.HelloWorldInC#.cs" // see https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives#error-and-warning-information #line (3,1) - (3,55) 13 "Listing01.01.HelloWorldInC#.cs" - Console.WriteLine("Äãºã¬ÎҽÐInigo Montoya¡£"); + Console.WriteLine("你好,我叫Inigo Montoya。"); } -} \ No newline at end of file +} diff --git a/src/Chapter02.Tests/Listing02.10.Tests.cs b/src/Chapter02.Tests/Listing02.10.Tests.cs index 3744c409..8c1e05e4 100644 --- a/src/Chapter02.Tests/Listing02.10.Tests.cs +++ b/src/Chapter02.Tests/Listing02.10.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_10.Tests; [TestClass] @@ -7,7 +7,7 @@ public class Comparison [TestMethod] public void Main_WriteBooleanStatements() { - const string expected = "Help Requested: True"; + const string expected = "是否请求帮助: True"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter02.Tests/Listing02.13.Tests.cs b/src/Chapter02.Tests/Listing02.13.Tests.cs index 36d41ca7..98ef55b4 100644 --- a/src/Chapter02.Tests/Listing02.13.Tests.cs +++ b/src/Chapter02.Tests/Listing02.13.Tests.cs @@ -1,4 +1,4 @@ -using IntelliTect.TestTools.Console; +using IntelliTect.TestTools.Console; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_13.Tests; @@ -8,7 +8,7 @@ public class DuelOfWitsTests [TestMethod] public void Main_WriteDizzyQuote() { - const string expected = "\"Truly, you have a dizzying intellect.\"\n\"Wait 'til I get going!\"\n"; + const string expected = "\"真的,你有令人混乱的智慧。\"\n\"等我做选择吧!\"\n"; ConsoleAssert.Expect(expected, (Action)DuelOfWits.Main, NormalizeOptions.None); } diff --git a/src/Chapter02.Tests/Listing02.14.Tests.cs b/src/Chapter02.Tests/Listing02.14.Tests.cs index 4267c211..d1b7607e 100644 --- a/src/Chapter02.Tests/Listing02.14.Tests.cs +++ b/src/Chapter02.Tests/Listing02.14.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_14.Tests; [TestClass] @@ -7,13 +7,13 @@ public class TriangleTests [TestMethod] public void Main_WriteTriangle() { - const string expected = @"Begin + const string expected = @"开始 /\ / \ / \ / \ /________\ -End"; +结束"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Triangle.Main); diff --git a/src/Chapter02.Tests/Listing02.15.Tests.cs b/src/Chapter02.Tests/Listing02.15.Tests.cs index 2afcd114..f28ced67 100644 --- a/src/Chapter02.Tests/Listing02.15.Tests.cs +++ b/src/Chapter02.Tests/Listing02.15.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_15.Tests; [TestClass] @@ -10,11 +10,10 @@ public void Main_CorrectOutput() string firstName = "Inigo"; string lastName = "Montoya"; - string expected = @$"Enter your first name: -<<{firstName} ->>Enter your last name: -<<{lastName} ->>Your full name is {firstName} {lastName}."; + string expected = @$"嘿,你! +请输入你的名字: <<{firstName} +>>请输入你的姓氏: <<{lastName} +>>你的全名是{firstName} {lastName}。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, diff --git a/src/Chapter02.Tests/Listing02.16.Tests.cs b/src/Chapter02.Tests/Listing02.16.Tests.cs index c844af65..01607bec 100644 --- a/src/Chapter02.Tests/Listing02.16.Tests.cs +++ b/src/Chapter02.Tests/Listing02.16.Tests.cs @@ -1,4 +1,4 @@ -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_16.Tests; @@ -11,11 +11,10 @@ public void Main_CorrectOutput() string firstName = "Inigo"; string lastName = "Montoya"; - string expected = @$"Enter your first name: -<<{firstName} ->>Enter your last name: -<<{lastName} ->>Your full name is: {firstName} {lastName}"; + string expected = @$"嘿,你! +请输入你的名字: <<{firstName} +>>请输入你的姓氏: <<{lastName} +>>你的全名是: {firstName} {lastName}。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, diff --git a/src/Chapter02.Tests/Listing02.17.Tests.cs b/src/Chapter02.Tests/Listing02.17.Tests.cs index ac4fb516..d548ec8e 100644 --- a/src/Chapter02.Tests/Listing02.17.Tests.cs +++ b/src/Chapter02.Tests/Listing02.17.Tests.cs @@ -1,4 +1,4 @@ -using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_17.Tests; @@ -11,12 +11,11 @@ public void Main_CorrectOutput() string firstName = "Inigo"; string lastName = "Montoya"; - string expected = @$"Enter your first name: -<<{firstName} ->>Enter your last name: -<<{lastName} ->>Your full name is: -{firstName} {lastName}"; + string expected = @$"嘿,你! +请输入你的名字: <<{firstName} +>>请输入你的姓氏: <<{lastName} +>>你的全名是: +{firstName} {lastName}。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, Program.Main); diff --git a/src/Chapter02.Tests/Listing02.18.Tests.cs b/src/Chapter02.Tests/Listing02.18.Tests.cs index 28c8987c..9b686392 100644 --- a/src/Chapter02.Tests/Listing02.18.Tests.cs +++ b/src/Chapter02.Tests/Listing02.18.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_18.Tests; [TestClass] @@ -7,7 +7,7 @@ public class SingleRawLiteralTests [TestMethod] public void Main_OutputsQuote() { - const string expected = """Mama said, "Life was just a box of chocolates..." """; + const string expected = """妈妈说过,"生活就像一盒巧克力..." """; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter02.Tests/Listing02.19.Tests.cs b/src/Chapter02.Tests/Listing02.19.Tests.cs index bc2d2544..f3e7bb84 100644 --- a/src/Chapter02.Tests/Listing02.19.Tests.cs +++ b/src/Chapter02.Tests/Listing02.19.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_19.Tests; [TestClass] @@ -10,11 +10,9 @@ public void Main_CorrectOutput() const string firstName = "Inigo"; const string lastName = "Montoya"; - const string expected = $@"Enter your first name: -<<{firstName} ->>Enter your last name: -<<{lastName} ->>Hello, I'm {firstName}. {firstName} {lastName}"; + const string expected = $@"请输入你的名字: <<{firstName} +>>请输入你的姓氏: <<{lastName} +>>你好,我叫{firstName}。{firstName} {lastName}。"; string result = IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, Program.Main); diff --git a/src/Chapter02.Tests/Listing02.20.Tests.cs b/src/Chapter02.Tests/Listing02.20.Tests.cs index 3522ec3e..1c3fc1f2 100644 --- a/src/Chapter02.Tests/Listing02.20.Tests.cs +++ b/src/Chapter02.Tests/Listing02.20.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_20.Tests; [TestClass] @@ -7,22 +7,22 @@ public class TriangleTests [TestMethod] public void Main_WriteTriangle() { - const string expected = @"Begin - ____ - / /\ - / / \ - / / /\ - / / / \ - / / /\ \ - / / / \ \ - / / /\ \ \ - / / / \ \ \ - /___/___/____\ \ \ - / {mobius} \ \ \ -/________________\ \ \ -\ \ \ / - \_________________\___\/ -End"; + const string expected = @"开始 + ____ + / /\ + / / \ + / / /\ + / / / \ + / / /\ \ + / / / \ \ + / / /\ \ \ + / / / \ \ \ + /___/___/____\ \ \ + / {莫比乌斯} \ \ \ + /________________\ \ \ + \ \ \ / + \_________________\___\/ +结束"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Triangle.Main); diff --git a/src/Chapter02.Tests/Listing02.22.Tests.cs b/src/Chapter02.Tests/Listing02.22.Tests.cs index f0b42305..4a223341 100644 --- a/src/Chapter02.Tests/Listing02.22.Tests.cs +++ b/src/Chapter02.Tests/Listing02.22.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_22.Tests; [TestClass] @@ -8,8 +8,8 @@ public class PalindromeLengthTests public void Main_InputRacecar_OutputPalindromeSevenChars() { const string expected = -@"Enter a palindrome: <>The palindrome ""racecar"" is 7 characters."; +@"输入一句回文: <>回文""racecar""共有 7个字。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, PalindromeLength.Main); diff --git a/src/Chapter02.Tests/Listing02.23.Tests.cs b/src/Chapter02.Tests/Listing02.23.Tests.cs index a1bdb415..418a776d 100644 --- a/src/Chapter02.Tests/Listing02.23.Tests.cs +++ b/src/Chapter02.Tests/Listing02.23.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_23.Tests; [TestClass] @@ -8,7 +8,7 @@ public class UppercaseTests public void Main_InputLorem_OutputNotCapitalized() { const string expected = -@"Enter text: <>Lorem"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter02.Tests/Listing02.24.Tests.cs b/src/Chapter02.Tests/Listing02.24.Tests.cs index 25bd0f19..39e82619 100644 --- a/src/Chapter02.Tests/Listing02.24.Tests.cs +++ b/src/Chapter02.Tests/Listing02.24.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_24.Tests; [TestClass] @@ -8,7 +8,7 @@ public class UppercaseTests public void Main_InputLorem_OutputIsCapitalized() { const string expected = -@"Enter text: <>LOREM"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter02.Tests/Listing02.25.Tests.cs b/src/Chapter02.Tests/Listing02.25.Tests.cs index 6b5bea4f..30eae04e 100644 --- a/src/Chapter02.Tests/Listing02.25.Tests.cs +++ b/src/Chapter02.Tests/Listing02.25.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_25.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void Main_WriteOverflowExample() { - const string expected = "The age is: "; + const string expected = "年龄是: "; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter02.Tests/Listing02.35.Tests.cs b/src/Chapter02.Tests/Listing02.35.Tests.cs index a1db5c25..545e91f0 100644 --- a/src/Chapter02.Tests/Listing02.35.Tests.cs +++ b/src/Chapter02.Tests/Listing02.35.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_35.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_TryParseStringValidNumber_CorrectlyParsed() { const string expected = - @"Enter a number: <<42>>"; + @"输入一个数字: <<42>>"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); @@ -18,8 +18,8 @@ public void Main_TryParseStringValidNumber_CorrectlyParsed() public void Main_TryParseStringNonNumber_IncorrectInput() { const string expected = -@"Enter a number: <>The text entered was not a valid number."; +@"输入一个数字: <>输入的文本不是一个有效的数字。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter02.Tests/Listing02.36.Tests.cs b/src/Chapter02.Tests/Listing02.36.Tests.cs index 4354a7af..c7372e92 100644 --- a/src/Chapter02.Tests/Listing02.36.Tests.cs +++ b/src/Chapter02.Tests/Listing02.36.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_36.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void Main_UsingTryParseWithInlineOut_Pi() { - string expected = $"Enter a number: <<{System.Math.PI}>>input was parsed successfully to {System.Math.PI}.>>{Environment.NewLine}'number' currently has the value: { System.Math.PI }"; + string expected = $"输入一个数字: <<{System.Math.PI}>>输入被成功解析成数字: {System.Math.PI}.>>{Environment.NewLine}'number'目前的值是: { System.Math.PI }"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); @@ -17,8 +17,8 @@ public void Main_UsingTryParseWithInlineOut_Pi() [TestMethod] public void Main_UsingTryParseWithInlineOut_Pie() { - string expected = @$"Enter a number: <>The text entered was not a valid number. -'number' currently has the value: { default(int) }"; + string expected = @$"输入一个数字: <>输入的文本不是一个有效的数字。 +'number'目前的值是: { default(int) }"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter02/Listing02.08.ExamplesOfAHexadecimalFormatSpecifier.cs b/src/Chapter02/Listing02.08.ExamplesOfAHexadecimalFormatSpecifier.cs index fac65b87..0f71e88b 100644 --- a/src/Chapter02/Listing02.08.ExamplesOfAHexadecimalFormatSpecifier.cs +++ b/src/Chapter02/Listing02.08.ExamplesOfAHexadecimalFormatSpecifier.cs @@ -1,12 +1,12 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_08; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_08; public class Program { public static void Main() { #region INCLUDE - //ÏÔʾ"0x2A" + //显示"0x2A" Console.WriteLine($"0x{42:X}"); #endregion INCLUDE } -} \ No newline at end of file +} diff --git a/src/Chapter02/Listing02.10.CaseInsensitiveComparisonOfTwoStrings.cs b/src/Chapter02/Listing02.10.CaseInsensitiveComparisonOfTwoStrings.cs index 77e5a32e..a3b50fc3 100644 --- a/src/Chapter02/Listing02.10.CaseInsensitiveComparisonOfTwoStrings.cs +++ b/src/Chapter02/Listing02.10.CaseInsensitiveComparisonOfTwoStrings.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_10; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_10; public class Program { @@ -10,8 +10,8 @@ public static void Main() // ... int comparison = string.Compare(option, "/Help", ignoreCase); bool isHelpRequested = (comparison == 0); - // ÏÔʾ: ÊǷñÇëÇó°ïÖú: True - Console.WriteLine($"ÊǷñÇëÇó°ïÖú: {isHelpRequested}"); + // 显示: 是否请求帮助: True + Console.WriteLine($"是否请求帮助: {isHelpRequested}"); #endregion INCLUDE } diff --git a/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs b/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs index c43e8fb1..1d94c8b4 100644 --- a/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs +++ b/src/Chapter02/Listing02.14.DisplayingATriangleUsingAVerbatimStringLiteral.cs @@ -1,17 +1,17 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_14; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_14; public class Triangle { public static void Main() { #region INCLUDE - Console.Write(@"¿ªʼ + Console.Write(@"开始 /\ / \ / \ / \ /________\ -½áÊø"); +结束"); #endregion INCLUDE } -} \ No newline at end of file +} diff --git a/src/Chapter02/Listing02.27.OverflowingAnIntegerValue.cs b/src/Chapter02/Listing02.27.OverflowingAnIntegerValue.cs index 3a65b5ea..e2eccd17 100644 --- a/src/Chapter02/Listing02.27.OverflowingAnIntegerValue.cs +++ b/src/Chapter02/Listing02.27.OverflowingAnIntegerValue.cs @@ -1,11 +1,11 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_27; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_27; public class Program { public static void Main() { #region INCLUDE - // int.MaxValueµÈÓÚ2147483647 + // int.MaxValue等于2147483647 int n = int.MaxValue; n = n + 1; Console.WriteLine(n); diff --git a/src/Chapter02/Listing02.28.ACheckedBlockExample.cs b/src/Chapter02/Listing02.28.ACheckedBlockExample.cs index cc7f8482..c3862411 100644 --- a/src/Chapter02/Listing02.28.ACheckedBlockExample.cs +++ b/src/Chapter02/Listing02.28.ACheckedBlockExample.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_28; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_28; public class Program { @@ -9,7 +9,7 @@ public static void Main() checked { #endregion HIGHLIGHT - // int.MaxValueµÈÓÚ2147483647 + // int.MaxValue等于2147483647 int n = int.MaxValue; n = n + 1; Console.WriteLine(n); diff --git a/src/Chapter02/Listing02.29.AnUncheckedBlockExample.cs b/src/Chapter02/Listing02.29.AnUncheckedBlockExample.cs index 5a5d4d31..59b5ef6f 100644 --- a/src/Chapter02/Listing02.29.AnUncheckedBlockExample.cs +++ b/src/Chapter02/Listing02.29.AnUncheckedBlockExample.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_29; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_29; public class Program { @@ -7,7 +7,7 @@ public static void Main() #region INCLUDE unchecked { - // int.MaxValueµÈÓÚ2147483647 + // int.MaxValue等于2147483647 int n = int.MaxValue; n = n + 1; Console.WriteLine(n); diff --git a/src/Chapter02/Listing02.34.UsingToStringToConvertToAString.cs b/src/Chapter02/Listing02.34.UsingToStringToConvertToAString.cs index 31698b01..a5a1e318 100644 --- a/src/Chapter02/Listing02.34.UsingToStringToConvertToAString.cs +++ b/src/Chapter02/Listing02.34.UsingToStringToConvertToAString.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_34; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter02.Listing02_34; public class Program { @@ -7,7 +7,7 @@ public static void Main() #region INCLUDE bool boolean = true; string text = boolean.ToString(); - // ÏÔʾ"True" + // 显示"True" Console.WriteLine(text); #endregion INCLUDE } diff --git a/src/Chapter03.Tests/Listing03.01.Tests.cs b/src/Chapter03.Tests/Listing03.01.Tests.cs index cc932e0f..3d339727 100644 --- a/src/Chapter03.Tests/Listing03.01.Tests.cs +++ b/src/Chapter03.Tests/Listing03.01.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_01.Tests; [TestClass] @@ -9,7 +9,7 @@ public void Main_GivenArgs_NumberDoubles() { string[] args = { "arg0", "arg1" }; string expected = - $"\'number\' doubled is { args[0].Length * 2 }."; + $"你在命令行提供的第一个参数包括{args[0].Length}个字符/字。{Environment.NewLine}\'number\'的两倍是{args[0].Length * 2}。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, ()=>Program.Main(args)); @@ -20,7 +20,7 @@ public void Main_GivenValidString_MakeUppercase() { string[] args = System.Array.Empty(); const string expected = - "\'number\' requires a value and cannot be null"; + "需要为\'number\'提供一个值,不允许为null。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, () => Program.Main(args)); diff --git a/src/Chapter03.Tests/Listing03.03.Tests.cs b/src/Chapter03.Tests/Listing03.03.Tests.cs index 5b1d3584..8d5098b7 100644 --- a/src/Chapter03.Tests/Listing03.03.Tests.cs +++ b/src/Chapter03.Tests/Listing03.03.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_03.Tests; [TestClass] @@ -8,7 +8,7 @@ public class UppercaseTests public void Main_GivenValidString_MakeUppercase() { const string expected = -@"Enter text: <>TEST"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter03.Tests/Listing03.05.Tests.cs b/src/Chapter03.Tests/Listing03.05.Tests.cs index 969cf20f..e11450f5 100644 --- a/src/Chapter03.Tests/Listing03.05.Tests.cs +++ b/src/Chapter03.Tests/Listing03.05.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_05.Tests; @@ -9,8 +9,8 @@ public class ProgramTests public void Main_WriteInventions() { const string expected = -@"Bifocals (1784) -Phonograph (1877)"; +@"双焦点眼镜 (1784) +留声机 (1877)"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter03.Tests/Listing03.23.Tests.cs b/src/Chapter03.Tests/Listing03.23.Tests.cs index c8912e33..9f956212 100644 --- a/src/Chapter03.Tests/Listing03.23.Tests.cs +++ b/src/Chapter03.Tests/Listing03.23.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_23.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_GetCountOnArray_ReturnArrayLength() { const string expected = - "There are 9 languages in the array."; + "数组中有9种语言。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter03.Tests/Listing03.26.Tests.cs b/src/Chapter03.Tests/Listing03.26.Tests.cs index c066604e..e22b1db5 100644 --- a/src/Chapter03.Tests/Listing03.26.Tests.cs +++ b/src/Chapter03.Tests/Listing03.26.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_26.Tests; [TestClass] @@ -8,13 +8,13 @@ public class ProgramTests public void Main_GetLengthOfDimensionOf3DArray_ReturnsLength() { const string expected = -@" 0..3: C#, COBOL, Java +@" 0..3: C#, COBOL, Java ^3..^0: Python, Lisp, JavaScript 3..^3: C++, TypeScript, Swift - ..^6: C#, COBOL, Java - 6..: Python, Lisp, JavaScript - ..: C#, COBOL, Java, C++, TypeScript, Swift, Python, Lisp, JavaScript - ..: C#, COBOL, Java, C++, TypeScript, Swift, Python, Lisp, JavaScript"; + ..^6: C#, COBOL, Java + 6..: Python, Lisp, JavaScript + ..: C#, COBOL, Java, C++, TypeScript, Swift, Python, Lisp, JavaScript + 0..^0: C#, COBOL, Java, C++, TypeScript, Swift, Python, Lisp, JavaScript"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter03.Tests/Listing03.27.Tests.cs b/src/Chapter03.Tests/Listing03.27.Tests.cs index 80c9f75e..8127e0cc 100644 --- a/src/Chapter03.Tests/Listing03.27.Tests.cs +++ b/src/Chapter03.Tests/Listing03.27.Tests.cs @@ -1,4 +1,4 @@ -using IntelliTect.TestTools.Console; +using IntelliTect.TestTools.Console; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_27.Tests; @@ -8,17 +8,13 @@ public class ProgrammingLanguagesTests [TestMethod] public void Main_AssertConsoleOutput_MatchesExpected() { - var expected = - """ - The wave of the future, COBOL, is at index 2. - - First Element Last Element - ------------- ------------ - C# TypeScript - TypeScript C# - - After clearing, the array size is: 9 - """; + string expected = $"未来的浪潮,COBOL,位于索引2。{Environment.NewLine}{Environment.NewLine}" + + $"{"第一个元素",-26}\t{"最后一个元素",-26}{Environment.NewLine}" + + $"{"--------------",-26}\t{"--------------",-26}{Environment.NewLine}" + + $"{"C#",-26}\t{"TypeScript",-26}{Environment.NewLine}" + + $"{"TypeScript",-26}\t{"C#",-26}{Environment.NewLine}" + + $"{string.Empty,-26}\t{string.Empty,-26}{Environment.NewLine}" + + "Clear后,数组大小是: 9"; ConsoleAssert.Expect( expected, ProgrammingLanguages.Main); diff --git a/src/Chapter03.Tests/Listing03.31.Tests.cs b/src/Chapter03.Tests/Listing03.31.Tests.cs index bf4a3fc7..22b7e498 100644 --- a/src/Chapter03.Tests/Listing03.31.Tests.cs +++ b/src/Chapter03.Tests/Listing03.31.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_31.Tests; [TestClass] @@ -8,8 +8,8 @@ public class PalindromeTests public void Main_InputValidPalindrome_IdentifiedAsPalindrome() { const string expected = -@"Enter a palindrome: <>""kayak"" is a palindrome."; +@"输入一句回文: <>""kayak""是回文。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Palindrome.Main); @@ -19,8 +19,8 @@ public void Main_InputValidPalindrome_IdentifiedAsPalindrome() public void Main_InputInvalidPalindrome_NotIdentifiedAsPalindrome() { const string expected = -@"Enter a palindrome: <>""test"" is NOT a palindrome."; +@"输入一句回文: <>""test""不是回文。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Palindrome.Main); diff --git a/src/Chapter03/Listing03.05.ImplicitLocalVariablesWithAnonymousTypes.cs b/src/Chapter03/Listing03.05.ImplicitLocalVariablesWithAnonymousTypes.cs index 4f87fc2c..d94bcc60 100644 --- a/src/Chapter03/Listing03.05.ImplicitLocalVariablesWithAnonymousTypes.cs +++ b/src/Chapter03/Listing03.05.ImplicitLocalVariablesWithAnonymousTypes.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_05; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_05; public class Program { @@ -6,10 +6,10 @@ public static void Main() { #region INCLUDE var patent1 = - new { Title = "˫½¹µãÑ۾µ", + new { Title = "双焦点眼镜", YearOfPublication = "1784" }; var patent2 = - new { Title = "ÁôÉù»ú", + new { Title = "留声机", YearOfPublication = "1877" }; Console.WriteLine( diff --git a/src/Chapter03/Listing03.25.UsingLengthMinus1InTheArrayIndex.cs b/src/Chapter03/Listing03.25.UsingLengthMinus1InTheArrayIndex.cs index bc86df74..92548488 100644 --- a/src/Chapter03/Listing03.25.UsingLengthMinus1InTheArrayIndex.cs +++ b/src/Chapter03/Listing03.25.UsingLengthMinus1InTheArrayIndex.cs @@ -1,4 +1,4 @@ -// ˵Ã÷ : Demonstrating how to use the length to index the last item in the array. +// 说明 : Demonstrating how to use the length to index the last item in the array. #pragma warning disable IDE0056 // Use index operator namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_25; diff --git a/src/Chapter03/Listing03.28.RetrievingAParticularDimensionsSize.cs b/src/Chapter03/Listing03.28.RetrievingAParticularDimensionsSize.cs index 9c09cf1f..653f1faa 100644 --- a/src/Chapter03/Listing03.28.RetrievingAParticularDimensionsSize.cs +++ b/src/Chapter03/Listing03.28.RetrievingAParticularDimensionsSize.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_28; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_28; public class Program { @@ -7,8 +7,8 @@ public static void Main() #region INCLUDE bool[, ,] cells; cells = new bool[2, 3, 3]; - Console.WriteLine(cells.GetLength(0)); // ÏÔʾ2 - Console.WriteLine(cells.Rank); // ÏÔʾ3 + Console.WriteLine(cells.GetLength(0)); // 显示2 + Console.WriteLine(cells.Rank); // 显示3 #endregion INCLUDE } } diff --git a/src/Chapter04.Tests/Listing04.02.Negative.Tests.cs b/src/Chapter04.Tests/Listing04.02.Negative.Tests.cs index b2f2578f..bc55e1f2 100644 --- a/src/Chapter04.Tests/Listing04.02.Negative.Tests.cs +++ b/src/Chapter04.Tests/Listing04.02.Negative.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_02.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - string expected = $@"{-72748555131730M}"; + string expected = $@"{-33940505930933M}"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter04.Tests/Listing04.03.BinaryOperators.Tests.cs b/src/Chapter04.Tests/Listing04.03.BinaryOperators.Tests.cs index 99025fe2..35ed38fe 100644 --- a/src/Chapter04.Tests/Listing04.03.BinaryOperators.Tests.cs +++ b/src/Chapter04.Tests/Listing04.03.BinaryOperators.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_03.Tests; [TestClass] @@ -7,9 +7,9 @@ public class DivisionTests [TestMethod] public void MainTest() { - const string expected = @"Enter the numerator: <<42 ->>Enter the denominator: <<5 ->>42 / 5 = 8 with remainder 2"; + const string expected = @"输入分子: <<42 +>>输入分母: <<5 +>>42 / 5 = 商8余2。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Division.Main); diff --git a/src/Chapter04.Tests/Listing04.04.Tests.cs b/src/Chapter04.Tests/Listing04.04.Tests.cs index c40b6617..e230c6ec 100644 --- a/src/Chapter04.Tests/Listing04.04.Tests.cs +++ b/src/Chapter04.Tests/Listing04.04.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_04.Tests; [TestClass] @@ -8,8 +8,8 @@ public class FortyTwoTests public void Main_AdditionOperatorWithNonNumericType_StringConcatenated() { const string expected = """ - The original Tacoma Bridge in Washington - was brought down by a 42 mile/hour wind. + 华盛顿州原来的塔科马大桥 + 被风速为67公里/小时的大风摧毁。 """; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter04.Tests/Listing04.07.UnexpectedInequality.Tests.cs b/src/Chapter04.Tests/Listing04.07.UnexpectedInequality.Tests.cs index 0d7fdcf1..e142029a 100644 --- a/src/Chapter04.Tests/Listing04.07.UnexpectedInequality.Tests.cs +++ b/src/Chapter04.Tests/Listing04.07.UnexpectedInequality.Tests.cs @@ -1,4 +1,4 @@ -using AddisonWesley.Michaelis.EssentialCSharp.Shared; +using AddisonWesley.Michaelis.EssentialCSharp.Shared; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_07.Tests; @@ -9,22 +9,22 @@ public class ProgramTests public void MainTest() { string netCoreApp3expected = -$@"{4.2D} != {4.2000002861023D} -{4.2} != {4.20000028610229} -(float){4.2F}M != {4.2F}F -{4.20000028610229} != {4.2} -{4.2F}F != {4.2D}D -{4.19999980926514D} != {4.2D} -{4.2F}F != {4.2D}D"; +$@"{4.2D} != {4.2000002861023D} - True +{4.2} != {4.20000028610229} - True +(float){4.2F}M != {4.2F}F - True +{4.20000028610229} != {4.2} - True +{4.2F}F != {4.2D}D - True +{4.19999980926514D} != {4.2D} - True +{4.2F}F != {4.2D}D - True"; string expected = - $@"{4.2D} != {4.2000002861023D} -{4.2} != {4.200000286102295} -(float){4.2F}M != {4.2000003F}F -{4.200000286102295} != {4.2} -{4.2000003F}F != {4.2}D -{4.199999809265137D} != {4.2D} -{4.2F}F != {4.2D}D"; + $@"{4.2D} != {4.2000002861023D} - True +{4.2} != {4.200000286102295} - True +(float){4.2F}M != {4.2000003F}F - True +{4.200000286102295} != {4.2} - True +{4.2000003F}F != {4.2}D - True +{4.199999809265137D} != {4.2D} - True +{4.2F}F != {4.2D}D - True"; string netCoreVersion = NetCore.GetNetCoreVersion(); if (string.Compare(netCoreVersion, "3") < 0) diff --git a/src/Chapter04.Tests/Listing04.16.Tests.cs b/src/Chapter04.Tests/Listing04.16.Tests.cs index 58ea1d64..2cc9ff45 100644 --- a/src/Chapter04.Tests/Listing04.16.Tests.cs +++ b/src/Chapter04.Tests/Listing04.16.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_16.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_PostIncrementInteger_ResultNotIncremented() { const string expected = - @"result = 123 and count = 124"; + @"result = 123,count = 124"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter04.Tests/Listing04.17.Tests.cs b/src/Chapter04.Tests/Listing04.17.Tests.cs index 1cdad622..0e5bbd4a 100644 --- a/src/Chapter04.Tests/Listing04.17.Tests.cs +++ b/src/Chapter04.Tests/Listing04.17.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_17.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_PreIncrementInteger_ResultIsIncremented() { const string expected = - @"result = 124 and count = 124"; + @"result = 124,count = 124"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter04.Tests/Listing04.20.Tests.cs b/src/Chapter04.Tests/Listing04.20.Tests.cs index 04c26467..0fe6ecf7 100644 --- a/src/Chapter04.Tests/Listing04.20.Tests.cs +++ b/src/Chapter04.Tests/Listing04.20.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_20.Tests; [TestClass] @@ -8,8 +8,8 @@ public class FortyTwoTests public void Main_AdditionOperatorWithNonNumericType_StringConcatenated() { const string expected = -@"The original Tacoma Bridge in Washington -was brought down by a 42 mile/hour wind."; +@"华盛顿州原来的塔科马大桥 +被风速为67公里/小时的大风摧毁。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, FortyTwo.Main); diff --git a/src/Chapter04.Tests/Listing04.21.Tests.cs b/src/Chapter04.Tests/Listing04.21.Tests.cs index beeb0922..ac071284 100644 --- a/src/Chapter04.Tests/Listing04.21.Tests.cs +++ b/src/Chapter04.Tests/Listing04.21.Tests.cs @@ -1,4 +1,4 @@ -using IntelliTect.TestTools.Console; +using IntelliTect.TestTools.Console; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_21.Tests; @@ -12,7 +12,7 @@ public void Main_Enter1TryToPlayAgainstComputer_ComputerPathSelected() 1 - 人机对战 2 - 双人对战 请选择:<<1 - >>Play against computer selected. + >>人机对战。 """; ConsoleAssert.Expect( @@ -26,7 +26,7 @@ public void Main_Enter2TryToPlayAgainstOtherPerson_TwoPlayerPathSelected() @"1 - 人机对战 2 - 双人对战 请选择:<<2 ->>Play against another player."; +>>双人对战。"; ConsoleAssert.Expect( expected, TicTacToe.Main); @@ -39,7 +39,7 @@ public void Main_EnterOther_TwoPlayerPathSelected() @"1 - 人机对战 2 - 双人对战 请选择:<<9 ->>Play against another player."; +>>双人对战。"; ConsoleAssert.Expect( expected, TicTacToe.Main); diff --git a/src/Chapter04.Tests/Listing04.22.Tests.cs b/src/Chapter04.Tests/Listing04.22.Tests.cs index 6e71b44d..5ed398d0 100644 --- a/src/Chapter04.Tests/Listing04.22.Tests.cs +++ b/src/Chapter04.Tests/Listing04.22.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_22.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void MainTest() { const string expected = -@"<<9>>What is the maximum number of turns in tic-tac-toe? (Enter 0 to exit.): Correct, tic-tac-toe has a maximum of 9 turns."; +@"<<9>>井字棋最多能走多少步? (输入0退出): 正确,井字棋最多只能走9步。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, TicTacToeTrivia.Main); diff --git a/src/Chapter04.Tests/Listing04.23.Tests.cs b/src/Chapter04.Tests/Listing04.23.Tests.cs index 289a2fe8..d1b979d0 100644 --- a/src/Chapter04.Tests/Listing04.23.Tests.cs +++ b/src/Chapter04.Tests/Listing04.23.Tests.cs @@ -1,4 +1,4 @@ -using IntelliTect.TestTools.Console; +using IntelliTect.TestTools.Console; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_23.Tests; @@ -9,7 +9,7 @@ public class ProgramTests public void Main_InputOfNegative1_Exit() { const string expected = - @"Exiting..."; + @"退出..."; ConsoleAssert.Expect( expected, ()=>Program.Main("-1")); @@ -19,7 +19,7 @@ public void Main_InputOfNegative1_Exit() public void Main_Input10_AnswerTooHigh() { const string expected = - @"Tic-tac-toe has less than 10 maximum turns."; + @"井字棋最大轮数小于10"; ConsoleAssert.Expect( expected, ()=>Program.Main("10")); @@ -29,7 +29,7 @@ public void Main_Input10_AnswerTooHigh() public void Main_Input5_AnswerTooLow() { const string expected = - @"Tic-tac-toe has more than 5 maximum turns."; + @"井字棋最大轮数大于5"; ConsoleAssert.Expect( expected, ()=>Program.Main("5")); @@ -39,7 +39,7 @@ public void Main_Input5_AnswerTooLow() public void Main_Input9_CorrectAnswer() { const string expected = - @"Correct, tic-tac-toe has a maximum of 9 turns."; + @"正确,井字棋最多只能走9轮。"; ConsoleAssert.Expect( expected, ()=>Program.Main("9")); diff --git a/src/Chapter04.Tests/Listing04.24.Tests.cs b/src/Chapter04.Tests/Listing04.24.Tests.cs index cfd1b5f2..cefe1949 100644 --- a/src/Chapter04.Tests/Listing04.24.Tests.cs +++ b/src/Chapter04.Tests/Listing04.24.Tests.cs @@ -1,4 +1,4 @@ -using IntelliTect.TestTools.Console; +using IntelliTect.TestTools.Console; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_24.Tests; @@ -6,13 +6,13 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_24.Tests; public class ProgramTests { [TestMethod] - public void Main_Input8_ExitProgram() + public void Main_Input0_ExitProgram() { const string expected = - "Exiting"; + "退出"; ConsoleAssert.Expect( - expected, ()=>Program.Main("8")); + expected, ()=>Program.Main("0")); } [TestMethod] diff --git a/src/Chapter04.Tests/Listing04.25.Tests.cs b/src/Chapter04.Tests/Listing04.25.Tests.cs index 91ac8818..8f2c379b 100644 --- a/src/Chapter04.Tests/Listing04.25.Tests.cs +++ b/src/Chapter04.Tests/Listing04.25.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_25.Tests; [TestClass] @@ -8,8 +8,8 @@ public class ProgramTests public void MainTest() { string expected = -$@"Enter the radius of the circle: <<3 ->>The area of the circle is: {28.27}"; +$@"输入圆的半径: <<3 +>>这个圆的面积是: {28.27}"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, CircleAreaCalculator.Main); } diff --git a/src/Chapter04.Tests/Listing04.26.Tests.cs b/src/Chapter04.Tests/Listing04.26.Tests.cs index 3eb72113..d394782d 100644 --- a/src/Chapter04.Tests/Listing04.26.Tests.cs +++ b/src/Chapter04.Tests/Listing04.26.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_26.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void MainTest() { string expected = -$@"The area of the circle is: {0.00M}"; +$@"圆的面积是: {0.00M}"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter04.Tests/Listing04.27.Tests.cs b/src/Chapter04.Tests/Listing04.27.Tests.cs index 97de88ac..d4b3fb9a 100644 --- a/src/Chapter04.Tests/Listing04.27.Tests.cs +++ b/src/Chapter04.Tests/Listing04.27.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_27.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void MainTest() { string expected = -$@"The area of the circle is: {0.00M}"; +$@"圆的面积是: {0.00M}"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter04.Tests/Listing04.29.Tests.cs b/src/Chapter04.Tests/Listing04.29.Tests.cs index e47f6bed..a702fdcd 100644 --- a/src/Chapter04.Tests/Listing04.29.Tests.cs +++ b/src/Chapter04.Tests/Listing04.29.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_29.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_Input5_BooleanConditionHit() { const string expected = - @"Tic-tac-toe has more than 5 maximum turns."; + @"井字棋最大步数大于5"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter04.Tests/Listing04.32.Tests.cs b/src/Chapter04.Tests/Listing04.32.Tests.cs index 3e8cad4c..8b0d951a 100644 --- a/src/Chapter04.Tests/Listing04.32.Tests.cs +++ b/src/Chapter04.Tests/Listing04.32.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_32.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_InputIsEmpty_PlayerQuitConditionHit() { const string expected = - @"Player Inigo quit!!"; + @"玩家Inigo退出!!"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, ()=>Program.Main("","Inigo")); @@ -18,7 +18,7 @@ public void Main_InputIsEmpty_PlayerQuitConditionHit() public void Main_InputIsQuit_PlayerQuitConditionHit() { const string expected = - @"Player Inigo quit!!"; + @"玩家Inigo退出!!"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, () => Program.Main("quit", "Inigo")); diff --git a/src/Chapter04.Tests/Listing04.33.Tests.cs b/src/Chapter04.Tests/Listing04.33.Tests.cs index 6464dd66..39fad9a1 100644 --- a/src/Chapter04.Tests/Listing04.33.Tests.cs +++ b/src/Chapter04.Tests/Listing04.33.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_33.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_Enter33ForHourOfDay_TimeInvalid() { const string expected = - @"The time you entered is invalid."; + @"你输入了无效的时间。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, ()=>Program.Main("33")); @@ -18,7 +18,7 @@ public void Main_Enter33ForHourOfDay_TimeInvalid() public void Main_EnterNegative1ForHourOfDay_TimeInvalid() { const string expected = - @"The time you entered is invalid."; + @"你输入了无效的时间。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, () => Program.Main("-1")); diff --git a/src/Chapter04.Tests/Listing04.34.Tests.cs b/src/Chapter04.Tests/Listing04.34.Tests.cs index 83ebbb48..c7005c8e 100644 --- a/src/Chapter04.Tests/Listing04.34.Tests.cs +++ b/src/Chapter04.Tests/Listing04.34.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_34.Tests; [TestClass] @@ -31,7 +31,7 @@ public void Main_Enter5ForHourOfDay_AndConditionFails() public void Main_Enter22ForHourOfDay_AndConditionSatisfied() { const string expected = - @"Hi-Ho, Hi-Ho, it's off to work we go."; + @"嗨哟,嗨哟,我们去工作了。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, () => Program.Main("22")); diff --git a/src/Chapter04.Tests/Listing04.38.Tests.cs b/src/Chapter04.Tests/Listing04.38.Tests.cs index f334f1f7..df634868 100644 --- a/src/Chapter04.Tests/Listing04.38.Tests.cs +++ b/src/Chapter04.Tests/Listing04.38.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_38.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void GivenSegmentsIsNull() { const string expected = - @"There were no segments to combine."; + @"没有更多区段可以合并了。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, ()=>Program.Main(null!)); @@ -18,7 +18,7 @@ public void GivenSegmentsIsNull() public void GivenSegmentsEmpty() { const string expected = - @"There were no segments to combine."; + @"没有更多区段可以合并了。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, () => Program.Main(Array.Empty())); diff --git a/src/Chapter04.Tests/Listing04.40.Tests.cs b/src/Chapter04.Tests/Listing04.40.Tests.cs index e9038d57..b035d4b0 100644 --- a/src/Chapter04.Tests/Listing04.40.Tests.cs +++ b/src/Chapter04.Tests/Listing04.40.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_40.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_Negative7RightShiftBitwiseBy2() { const string expected = - @"x = -2."; + @"x = -2。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter04.Tests/Listing04.42.Tests.cs b/src/Chapter04.Tests/Listing04.42.Tests.cs index 691e25be..8a6da716 100644 --- a/src/Chapter04.Tests/Listing04.42.Tests.cs +++ b/src/Chapter04.Tests/Listing04.42.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_42.Tests; [TestClass] @@ -9,7 +9,7 @@ public void MainTest() { int integer = new System.Random().Next(); string expected = - $@"Enter an integer: <<{integer}>>{System.Convert.ToString(integer, 2).PadLeft(64,'0')}"; + $@"输入一个整数: <<{integer}>>{System.Convert.ToString(integer, 2).PadLeft(64,'0')}"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, BinaryConverter.Main); diff --git a/src/Chapter04.Tests/Listing04.44.Tests.cs b/src/Chapter04.Tests/Listing04.44.Tests.cs index 1fa07d47..46ccddbb 100644 --- a/src/Chapter04.Tests/Listing04.44.Tests.cs +++ b/src/Chapter04.Tests/Listing04.44.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_44.Tests; [TestClass] @@ -8,8 +8,8 @@ public class FibonacciCalculatorTests public void Main_Enter0_Write1() { const string expected = -@"Enter a positive integer:<<0 ->>The Fibonacci number following this is 1"; +@"输入一个正整数:<<0 +>>下一个斐波那契数是1"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, FibonacciCalculator.Main); @@ -19,8 +19,8 @@ public void Main_Enter0_Write1() public void Main_Enter1_Write1() // returns next number in sequence GREATER than input { const string expected = -@"Enter a positive integer:<<1 ->>The Fibonacci number following this is 2"; +@"输入一个正整数:<<1 +>>下一个斐波那契数是2"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, FibonacciCalculator.Main); @@ -30,8 +30,8 @@ public void Main_Enter1_Write1() // returns next number in sequence GREATER than public void Main_Enter21_Write34() { const string expected = -@"Enter a positive integer:<<21 ->>The Fibonacci number following this is 34"; +@"输入一个正整数:<<21 +>>下一个斐波那契数是34"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, FibonacciCalculator.Main); diff --git a/src/Chapter04.Tests/Listing04.46.Tests.cs b/src/Chapter04.Tests/Listing04.46.Tests.cs index 3937b8c2..47485550 100644 --- a/src/Chapter04.Tests/Listing04.46.Tests.cs +++ b/src/Chapter04.Tests/Listing04.46.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_46.Tests; [TestClass] @@ -8,7 +8,7 @@ public class BinaryConverterTests public void Main_Enter0_WriteBinaryEquivalent() { const string expected = - @"Enter an integer: <<0 + @"输入一个整数: <<0 >>0000000000000000000000000000000000000000000000000000000000000000"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( @@ -19,7 +19,7 @@ public void Main_Enter0_WriteBinaryEquivalent() public void Main_Enter1_WriteBinaryEquivalent() { const string expected = -@"Enter an integer: <<1 +@"输入一个整数: <<1 >>0000000000000000000000000000000000000000000000000000000000000001"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( @@ -30,7 +30,7 @@ public void Main_Enter1_WriteBinaryEquivalent() public void Main_Enter20_WriteBinaryEquivalent() { const string expected = - @"Enter an integer: <<20 + @"输入一个整数: <<20 >>0000000000000000000000000000000000000000000000000000000000010100"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter04.Tests/Listing04.48.Tests.cs b/src/Chapter04.Tests/Listing04.48.Tests.cs index 7eb194d2..289bdf20 100644 --- a/src/Chapter04.Tests/Listing04.48.Tests.cs +++ b/src/Chapter04.Tests/Listing04.48.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_48.Tests; [TestClass] @@ -8,7 +8,7 @@ public class TicTacToeTests public void Main_DetermineRemainingMoves_WriteRemainingMoves() { const string expected = - @"The available moves are as follows: 1 2 3 4 5 6 7 8 9 "; + @"可能的落子如下所示: 1 2 3 4 5 6 7 8 9 "; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, TicTacToe.Main); diff --git a/src/Chapter04.Tests/Listing04.51.Tests.cs b/src/Chapter04.Tests/Listing04.51.Tests.cs index 63fcd683..bf64bd60 100644 --- a/src/Chapter04.Tests/Listing04.51.Tests.cs +++ b/src/Chapter04.Tests/Listing04.51.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_51.Tests; [TestClass] @@ -8,7 +8,7 @@ public class TicTacToeTests public void Main_BreakOnPlayerWinning_Player1Winner() { const string expected = - @"Player 1 was the winner"; + @"玩家1是赢家。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, TicTacToe.Main); diff --git a/src/Chapter04.Tests/Listing04.53.Tests.cs b/src/Chapter04.Tests/Listing04.53.Tests.cs index d90c2341..a867dd61 100644 --- a/src/Chapter04.Tests/Listing04.53.Tests.cs +++ b/src/Chapter04.Tests/Listing04.53.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_53.Tests; [TestClass] @@ -8,8 +8,8 @@ public class EmailDomainTests public void Main_EnterValidEmailWithDomain_WriteDomain() { const string expected = -@"Enter an email address: <>The email domain is: domain.com"; +@"输入一个电子邮件地址: <>该地址的域是: domain.com"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, EmailDomain.Main); @@ -19,8 +19,8 @@ public void Main_EnterValidEmailWithDomain_WriteDomain() public void Main_EnterInvalidEmailWithoutDomain_WriteBlank() { const string expected = -@"Enter an email address: <>The email domain is: "; +@"输入一个电子邮件地址: <>该地址的域是: "; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, EmailDomain.Main); diff --git a/src/Chapter04.Tests/Listing04.54.Tests.cs b/src/Chapter04.Tests/Listing04.54.Tests.cs index cc51bc9c..37449533 100644 --- a/src/Chapter04.Tests/Listing04.54.Tests.cs +++ b/src/Chapter04.Tests/Listing04.54.Tests.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_54.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_54.Tests; [TestClass] public class EmailDomainTests @@ -7,9 +7,8 @@ public class EmailDomainTests public void Main_EnterValidEmailWithDomain_WriteDomain() { const string expected = -@"Enter an email address: -<>The email domain is: domain.com"; +@"输入一个电子邮件地址: <>该地址的域是: domain.com"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, EmailDomain.Main); @@ -19,9 +18,8 @@ public void Main_EnterValidEmailWithDomain_WriteDomain() public void Main_EnterInvalidEmailWithoutDomain_WriteBlank() { const string expected = -@"Enter an email address: -<>The email domain is: "; +@"输入一个电子邮件地址: <>该地址的域是: "; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, EmailDomain.Main); diff --git a/src/Chapter04.Tests/Listing04.55.Tests.cs b/src/Chapter04.Tests/Listing04.55.Tests.cs index efdd2993..7328580d 100644 --- a/src/Chapter04.Tests/Listing04.55.Tests.cs +++ b/src/Chapter04.Tests/Listing04.55.Tests.cs @@ -1,4 +1,4 @@ -using IntelliTect.TestTools.Console; +using IntelliTect.TestTools.Console; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_55.Tests; @@ -15,14 +15,14 @@ public void Main_out_NoOutput() [TestMethod] public void Main_f_isFiltered() { - string expected = "Filtering..."; + string expected = "正在筛选..."; ConsoleAssert.Expect(expected, () => GoToStatements.Main(["/f"])); } [TestMethod] public void Main_f_out_isFiltered() { - string expected = "Filtering..."; + string expected = "正在筛选..."; ConsoleAssert.Expect(expected, () => GoToStatements.Main(["/f", "/out"])); } } diff --git a/src/Chapter04/Listing04.05.CharConcatenation.cs b/src/Chapter04/Listing04.05.CharConcatenation.cs index 725cb33d..065bbdd0 100644 --- a/src/Chapter04/Listing04.05.CharConcatenation.cs +++ b/src/Chapter04/Listing04.05.CharConcatenation.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_05; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_05; public class Program { @@ -7,7 +7,7 @@ public static void Main() #region INCLUDE int n = '3' + '4'; char c = (char)n; - Console.WriteLine(c); // Êä³ö'g' + Console.WriteLine(c); // 输出'g' #endregion INCLUDE } } diff --git a/src/Chapter04/Listing04.08.DivisionByZero.cs b/src/Chapter04/Listing04.08.DivisionByZero.cs index bbabd7af..dbbb6b45 100644 --- a/src/Chapter04/Listing04.08.DivisionByZero.cs +++ b/src/Chapter04/Listing04.08.DivisionByZero.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_08; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_08; public class Program { @@ -6,7 +6,7 @@ public static void Main() { #region INCLUDE float n = 0f; - // ÏÔʾ£ºNaN + // 显示:NaN Console.WriteLine(n / 0); #endregion INCLUDE } diff --git a/src/Chapter04/Listing04.10.Increment.cs b/src/Chapter04/Listing04.10.Increment.cs index 3e4b8b7c..154a910e 100644 --- a/src/Chapter04/Listing04.10.Increment.cs +++ b/src/Chapter04/Listing04.10.Increment.cs @@ -1,4 +1,4 @@ -// ˵Ã÷ : Demonstrating the without += just prior showing += +// 说明 : Demonstrating the without += just prior showing += #pragma warning disable IDE0054 // Use compound assignment namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_10; diff --git a/src/Chapter04/Listing04.13.UnaryIncrement.cs b/src/Chapter04/Listing04.13.UnaryIncrement.cs index 8abc09ab..5ce6af1c 100644 --- a/src/Chapter04/Listing04.13.UnaryIncrement.cs +++ b/src/Chapter04/Listing04.13.UnaryIncrement.cs @@ -1,4 +1,4 @@ -// ˵Ã÷ : Demonstrating the equivalent operators +// 说明 : Demonstrating the equivalent operators #pragma warning disable IDE0054 // Use compound assignment namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_13; diff --git a/src/Chapter04/Listing04.14.UnaryDecrement.cs b/src/Chapter04/Listing04.14.UnaryDecrement.cs index 039980e3..06e2234a 100644 --- a/src/Chapter04/Listing04.14.UnaryDecrement.cs +++ b/src/Chapter04/Listing04.14.UnaryDecrement.cs @@ -1,4 +1,4 @@ -// ˵Ã÷ : Demonstrating equivalent operators. +// 说明 : Demonstrating equivalent operators. #pragma warning disable IDE0054 // Use compound assignment namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_14; diff --git a/src/Chapter04/Listing04.16.PostIncrement.cs b/src/Chapter04/Listing04.16.PostIncrement.cs index ab24b34a..80b5b741 100644 --- a/src/Chapter04/Listing04.16.PostIncrement.cs +++ b/src/Chapter04/Listing04.16.PostIncrement.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_16; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_16; public class Program { @@ -8,7 +8,7 @@ public static void Main() int count = 123; int result; result = count++; - Console.WriteLine($"result = {result}£¬count = {count}"); + Console.WriteLine($"result = {result},count = {count}"); #endregion INCLUDE } } diff --git a/src/Chapter04/Listing04.17.PreIncrement.cs b/src/Chapter04/Listing04.17.PreIncrement.cs index b9c49b50..eeb84242 100644 --- a/src/Chapter04/Listing04.17.PreIncrement.cs +++ b/src/Chapter04/Listing04.17.PreIncrement.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_17; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_17; public class Program { @@ -10,7 +10,7 @@ public static void Main() #region HIGHLIGHT result = ++count; #endregion HIGHLIGHT - Console.WriteLine($"result = {result}£¬count = {count}"); + Console.WriteLine($"result = {result},count = {count}"); #endregion INCLUDE } } diff --git a/src/Chapter04/Listing04.24.NoCodeBlock.cs b/src/Chapter04/Listing04.24.NoCodeBlock.cs index 044e78b1..3589b483 100644 --- a/src/Chapter04/Listing04.24.NoCodeBlock.cs +++ b/src/Chapter04/Listing04.24.NoCodeBlock.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_24; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_24; public class Program { @@ -9,7 +9,7 @@ public static void Main(params string[] args) #region INCLUDE if (input <=0) #region HIGHLIGHT - Console.WriteLine("Í˳ö"); + Console.WriteLine("退出"); #endregion HIGHLIGHT #endregion INCLUDE } diff --git a/src/Chapter04/Listing04.32.EqualityOperator.cs b/src/Chapter04/Listing04.32.EqualityOperator.cs index 44f7dc9c..6d990eec 100644 --- a/src/Chapter04/Listing04.32.EqualityOperator.cs +++ b/src/Chapter04/Listing04.32.EqualityOperator.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_32; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_32; public class Program { @@ -9,7 +9,7 @@ public static void Main(params string[] args) #region INCLUDE if (input.Length == 0 || input == "quit") { - Console.WriteLine($"Íæ¼Ò{currentPlayer}Í˳ö!!"); + Console.WriteLine($"玩家{currentPlayer}退出!!"); } #endregion INCLUDE } diff --git a/src/Chapter04/Listing04.35.LogicalNegationOperator.cs b/src/Chapter04/Listing04.35.LogicalNegationOperator.cs index 067498c9..6c6d04dd 100644 --- a/src/Chapter04/Listing04.35.LogicalNegationOperator.cs +++ b/src/Chapter04/Listing04.35.LogicalNegationOperator.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_35; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_35; public class Program { @@ -9,7 +9,7 @@ public static void Main() #region HIGHLIGHT bool result = !valid; #endregion HIGHLIGHT - // ÏÔʾ"result = True" + // 显示"result = True" Console.WriteLine($"result = { result }"); #endregion INCLUDE } diff --git a/src/Chapter04/Listing04.39.NullConditionalOperatorWithIndexOperator.cs b/src/Chapter04/Listing04.39.NullConditionalOperatorWithIndexOperator.cs index 6e556e2c..6264f55d 100644 --- a/src/Chapter04/Listing04.39.NullConditionalOperatorWithIndexOperator.cs +++ b/src/Chapter04/Listing04.39.NullConditionalOperatorWithIndexOperator.cs @@ -1,4 +1,4 @@ -// ˵Ã÷ : Intentionally demonstrating legacy syntax. +// 说明 : Intentionally demonstrating legacy syntax. #pragma warning disable IDE1005 // Delegate invocation can be simplified. using System.ComponentModel; @@ -12,7 +12,7 @@ public class Person public int BirthYear { get { return _BirthYear; } - set + set { #region INCLUDE EventHandler propertyChanged = @@ -24,7 +24,7 @@ public int BirthYear } #endregion INCLUDE - _BirthYear = value; + _BirthYear = value; } } diff --git a/src/Chapter04/Listing04.40.RightShiftOperator.cs b/src/Chapter04/Listing04.40.RightShiftOperator.cs index 9101ed97..4ab8594f 100644 --- a/src/Chapter04/Listing04.40.RightShiftOperator.cs +++ b/src/Chapter04/Listing04.40.RightShiftOperator.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_40; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter04.Listing04_40; public class Program { @@ -6,10 +6,10 @@ public static void Main() { #region INCLUDE int x; - x = (-7 >> 2); // 11111111111111111111111111111001±ä³É + x = (-7 >> 2); // 11111111111111111111111111111001变成 // 11111111111111111111111111111110 - // Êä³ö"x = -2¡£" - Console.WriteLine($"x = {x}¡£"); + // 输出"x = -2。" + Console.WriteLine($"x = {x}。"); #endregion INCLUDE } } diff --git a/src/Chapter05.Tests/Listing05.02.SimpleMethodCall.Tests.cs b/src/Chapter05.Tests/Listing05.02.SimpleMethodCall.Tests.cs index 29e5f48c..6097c315 100644 --- a/src/Chapter05.Tests/Listing05.02.SimpleMethodCall.Tests.cs +++ b/src/Chapter05.Tests/Listing05.02.SimpleMethodCall.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_02.Tests; [TestClass] @@ -8,10 +8,10 @@ public class HeyYouTests public void Main_MethodCalls_MethodsCalledSuccessfully() { const string expected = -@"Hey you! -Enter your first name: <>Enter your last name: <>Your full name is Inigo Montoya."; +@"嘿,你! +请输入你的名字: <>请输入你的姓氏: <>你的全名是Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, HeyYou.Main); diff --git a/src/Chapter05.Tests/Listing05.03.PassingAMethodReturnAsAParameterToAnotherMethodCall.Tests.cs b/src/Chapter05.Tests/Listing05.03.PassingAMethodReturnAsAParameterToAnotherMethodCall.Tests.cs index 1dd06101..0a6c3e44 100644 --- a/src/Chapter05.Tests/Listing05.03.PassingAMethodReturnAsAParameterToAnotherMethodCall.Tests.cs +++ b/src/Chapter05.Tests/Listing05.03.PassingAMethodReturnAsAParameterToAnotherMethodCall.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_03.Tests; [TestClass] @@ -8,8 +8,8 @@ public class ProgramTests public void Main_InputInigo_WriteHelloInigo() { const string expected = - @"Enter your first name: <>Hello Inigo!"; + @"请输入你的名字: <>你好,Inigo!"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter05.Tests/Listing05.04.DeclaringAMethod.Tests.cs b/src/Chapter05.Tests/Listing05.04.DeclaringAMethod.Tests.cs index 23326922..60642c8b 100644 --- a/src/Chapter05.Tests/Listing05.04.DeclaringAMethod.Tests.cs +++ b/src/Chapter05.Tests/Listing05.04.DeclaringAMethod.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_04.Tests; [TestClass] @@ -8,10 +8,10 @@ public class ProgramTests public void Main_InputInigoMontoya_WriteFullName() { string view = -@"Hey you! -Enter your first name: <>Enter your last name: <>Hello Inigo Montoya! Your initials are I. M."; +@"嘿,你! +请输入你的名字: <>请输入你的姓氏: <>你好,Inigo Montoya!你的姓名缩写是I. M"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(view, () => diff --git a/src/Chapter05.Tests/Listing05.06.ReturningMultipleValuesViaTuple.Tests.cs b/src/Chapter05.Tests/Listing05.06.ReturningMultipleValuesViaTuple.Tests.cs index 865a7164..f68be65d 100644 --- a/src/Chapter05.Tests/Listing05.06.ReturningMultipleValuesViaTuple.Tests.cs +++ b/src/Chapter05.Tests/Listing05.06.ReturningMultipleValuesViaTuple.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_06.Tests; [TestClass] @@ -8,9 +8,9 @@ public class ProgramTests public void Main_InputInigoMontoya_WriteFullName() { string view = -@"Enter your first name: <>Enter your last name: <>Hello Inigo Montoya!"; +@"请输入你的名字: <>请输入你的姓氏: <>你好,Inigo Montoya!"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(view, () => diff --git a/src/Chapter05.Tests/Listing05.07.DeclaringALocalFunction.Tests.cs b/src/Chapter05.Tests/Listing05.07.DeclaringALocalFunction.Tests.cs index e5e0b333..bd69b753 100644 --- a/src/Chapter05.Tests/Listing05.07.DeclaringALocalFunction.Tests.cs +++ b/src/Chapter05.Tests/Listing05.07.DeclaringALocalFunction.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_07.Tests; [TestClass] @@ -8,9 +8,9 @@ public class HeyYouTests public void Main_Tests() { const string expected = -@"First Name: <>Last Name: <>Email Address: <>姓氏: <>电子邮件地址: <>Inigo Montoya "; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter05.Tests/Listing05.08.Tests.cs b/src/Chapter05.Tests/Listing05.08.Tests.cs index 010b469d..9d74773b 100644 --- a/src/Chapter05.Tests/Listing05.08.Tests.cs +++ b/src/Chapter05.Tests/Listing05.08.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_08.Tests; [TestClass] @@ -6,7 +6,7 @@ public class ProgramTests { public const string Initial = "T"; public static string Expected = $""" - Enter your full name (e.g. Inigo T. Montoya): <<{Inigo} {Initial}. {Montoya} + 输入你的全名 (例:Inigo T. Montoya): <<{Inigo} {Initial}. {Montoya} >> FirstName: {Inigo} Initial: {Initial} diff --git a/src/Chapter05.Tests/Listing05.10.StringBuilderImplicitUsingStatements.Tests.cs b/src/Chapter05.Tests/Listing05.10.StringBuilderImplicitUsingStatements.Tests.cs index 1a915323..e429c84d 100644 --- a/src/Chapter05.Tests/Listing05.10.StringBuilderImplicitUsingStatements.Tests.cs +++ b/src/Chapter05.Tests/Listing05.10.StringBuilderImplicitUsingStatements.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_10.Tests; [TestClass] @@ -7,15 +7,10 @@ public class ProgramTests [TestMethod] public void Main_InputInigoMontoya_WriteFullName() { - string view = """ - Enter your first name: <> - Enter your middle initial: <> - Enter your last name: <> - Hello Inigo T. Montoya! - """; + const string view = @"请输入你的名字: <>请输入你的中间名首字母: <>请输入你的姓氏: <>你好,Inigo T. Montoya!"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(view, Program.Main); diff --git a/src/Chapter05.Tests/Listing05.12.SpecifyingTheUsingDirectiveInsideANamespaceDeclaration.Tests.cs b/src/Chapter05.Tests/Listing05.12.SpecifyingTheUsingDirectiveInsideANamespaceDeclaration.Tests.cs index 8058d13c..18b7ecef 100644 --- a/src/Chapter05.Tests/Listing05.12.SpecifyingTheUsingDirectiveInsideANamespaceDeclaration.Tests.cs +++ b/src/Chapter05.Tests/Listing05.12.SpecifyingTheUsingDirectiveInsideANamespaceDeclaration.Tests.cs @@ -1,14 +1,12 @@ - -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_12.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_12.Tests; [TestClass] public class ProgramTests { - [TestMethod] - public void Main_UsingToAvoidFullyQualifying_MethodCalledAsExpected() + public void Main_UsingInsideNamespace_WritesChineseGreeting() { - IntelliTect.TestTools.Console.ConsoleAssert.Expect( - Listing05_08.Tests.ProgramTests.Expected, Program.Main); + const string expected = "你好,我的名字是Inigo Montoya。"; + IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, Program.Main); } } diff --git a/src/Chapter05.Tests/Listing05.13.UsingStaticDirective.Tests.cs b/src/Chapter05.Tests/Listing05.13.UsingStaticDirective.Tests.cs index 8f3a5075..bc375bd7 100644 --- a/src/Chapter05.Tests/Listing05.13.UsingStaticDirective.Tests.cs +++ b/src/Chapter05.Tests/Listing05.13.UsingStaticDirective.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_13.Tests; [TestClass] @@ -8,10 +8,10 @@ public class HeyYouTests public void Main_StaticUsing_MethodsCalledNormally() { const string expected = -@"Hey you! -Enter your first name: <>Enter your last name: <>Your full name is Inigo Montoya."; +@"嘿,你! +请输入你的名字: <>请输入你的姓氏: <>你的全名是Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, HeyYou.Main); diff --git a/src/Chapter05.Tests/Listing05.16.PassingCommandLineArgumentsToMain.Tests.cs b/src/Chapter05.Tests/Listing05.16.PassingCommandLineArgumentsToMain.Tests.cs index 01a1b52b..29515f94 100644 --- a/src/Chapter05.Tests/Listing05.16.PassingCommandLineArgumentsToMain.Tests.cs +++ b/src/Chapter05.Tests/Listing05.16.PassingCommandLineArgumentsToMain.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_16.Tests; [TestClass] @@ -9,8 +9,8 @@ public void Main_NoArgs_ExpectErrors() { string[] args = Array.Empty(); string expected = """ - ERROR: You must specify the URL and the file name - Usage: Downloader.exe + 错误: 必须指定URL和文件名 + 用法: Downloader.exe <文件名> """; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, @@ -27,7 +27,7 @@ public void Main_IntelliTectIndexHtmlArgs_DownloadFile() { string fileName = "about"; string[] args = { "http://IntelliTect.com", fileName }; - string expected = $"Downloaded '{fileName}' from '{ args[0]}'."; + string expected = $"已从'{args[0]}'下载'{fileName}'。"; int? result = null; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter05.Tests/Listing05.18.PassingVariablesByReference.Tests.cs b/src/Chapter05.Tests/Listing05.18.PassingVariablesByReference.Tests.cs index 714ae14b..8968634c 100644 --- a/src/Chapter05.Tests/Listing05.18.PassingVariablesByReference.Tests.cs +++ b/src/Chapter05.Tests/Listing05.18.PassingVariablesByReference.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_18.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void Main_WriteSwappedVariables() { - string view = @"first = ""goodbye"", second = ""hello"""; + string view = @"first = ""再见"", second = ""你好"""; IntelliTect.TestTools.Console.ConsoleAssert.Expect(view, () => diff --git a/src/Chapter05.Tests/Listing05.19.PassingVariablesOutOnly.Tests.cs b/src/Chapter05.Tests/Listing05.19.PassingVariablesOutOnly.Tests.cs index eb1074ba..9cf3da44 100644 --- a/src/Chapter05.Tests/Listing05.19.PassingVariablesOutOnly.Tests.cs +++ b/src/Chapter05.Tests/Listing05.19.PassingVariablesOutOnly.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_19.Tests; [TestClass] @@ -9,8 +9,8 @@ public void Main_InputNoPhrase_ExpectHelp() { string[] args = System.Array.Empty(); string view = -@"ConvertToPhoneNumber.exe -'_' indicates no standard phone button"; +@"用法: ConvertToPhoneNumber.exe <一个英文短语> +'_'表示无标准电话按键"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(view, () => diff --git a/src/Chapter05.Tests/Listing05.25.Tests.cs b/src/Chapter05.Tests/Listing05.25.Tests.cs index 0b8ca53d..0252a15f 100644 --- a/src/Chapter05.Tests/Listing05.25.Tests.cs +++ b/src/Chapter05.Tests/Listing05.25.Tests.cs @@ -1,4 +1,4 @@ - + using IntelliTect.TestTools.Console; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_25.Tests; @@ -9,7 +9,7 @@ public class SpecifyingParametersByNameTests [TestMethod] public void SpecifyingParametersByName_WithNamedParameters_WritesToConsole() { - const string expected = "First Name: Inigo Middle Name: Last Name: Montoya"; + const string expected = "名字: Inigo 中间名: 姓氏: Montoya"; ConsoleAssert.Expect(expected, () => SpecifyingParametersByName.Main()); } @@ -17,7 +17,7 @@ public void SpecifyingParametersByName_WithNamedParameters_WritesToConsole() [TestMethod] public void SpecifyingParametersByName_WithNamedParametersInReverseOrder_WritesToConsole() { - const string expected = "First Name: Inigo Middle Name: MiddleName Last Name: Montoya"; + const string expected = "名字: Inigo 中间名: MiddleName 姓氏: Montoya"; ConsoleAssert.Expect(expected, () => SpecifyingParametersByName.DisplayGreeting(firstName: "Inigo", middleName: "MiddleName", lastName: "Montoya")); } diff --git a/src/Chapter05.Tests/Listing05.26.ConvertingAStringToAnInt.Tests.cs b/src/Chapter05.Tests/Listing05.26.ConvertingAStringToAnInt.Tests.cs index 9a5bc9a0..186bd99e 100644 --- a/src/Chapter05.Tests/Listing05.26.ConvertingAStringToAnInt.Tests.cs +++ b/src/Chapter05.Tests/Listing05.26.ConvertingAStringToAnInt.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_26.Tests; [TestClass] @@ -8,10 +8,10 @@ public class ExceptionHandlingTests public void Main_InputNameAge_ExpectMonthCount() { string view = -@"Hey you! -Enter your first name: <>Enter your age: <<10 ->>Hi Inigo! You are 120 months old."; +@"嘿,你! +请输入你的名字: <>请输入你的年龄: <<10 +>>你好,Inigo!你有120个月大了。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(view, () => diff --git a/src/Chapter05.Tests/Listing05.27.CatchingAnException.Tests.cs b/src/Chapter05.Tests/Listing05.27.CatchingAnException.Tests.cs index f4de3042..77edf7b2 100644 --- a/src/Chapter05.Tests/Listing05.27.CatchingAnException.Tests.cs +++ b/src/Chapter05.Tests/Listing05.27.CatchingAnException.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_27.Tests; [TestClass] @@ -8,10 +8,11 @@ public class ExceptionHandlingTests public void Main_InputInvalidAge_ExpectInvalidMessage() { const string expected = -@"Enter your first name: <>Enter your age: <>The age entered, xyz, is not valid. -Goodbye Inigo"; +@"嘿,你! +请输入你的名字: <>请输入你的年龄: <>你输入的年龄'xyz'不是一个有效的整数。 +再见,Inigo。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, ExceptionHandling.Main, 1); @@ -22,10 +23,11 @@ public void Main_InputInvalidAge_ExpectInvalidMessage() public void Main_InputFifty_ExpectSixHundredMonths() { const string expected = -@"Enter your first name: <>Enter your age: <<50 ->>Hi Inigo! You are 600 months old. -Goodbye Inigo"; +@"嘿,你! +请输入你的名字: <>请输入你的年龄: <<50 +>>你好,Inigo!你有600个月大了。 +再见,Inigo。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, ExceptionHandling.Main); diff --git a/src/Chapter05.Tests/Listing05.29.GeneralCatchBlocks.Tests.cs b/src/Chapter05.Tests/Listing05.29.GeneralCatchBlocks.Tests.cs index 015d3177..9fce88f6 100644 --- a/src/Chapter05.Tests/Listing05.29.GeneralCatchBlocks.Tests.cs +++ b/src/Chapter05.Tests/Listing05.29.GeneralCatchBlocks.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_29.Tests; [TestClass] @@ -7,10 +7,10 @@ public class ProgramTests [TestMethod] public void Main_HappyPath() { - string expected = @"Enter your first name: <>Enter your age: <<42 ->>Hi Inigo! You are 504 months old. -Goodbye Inigo"; + string expected = @"请输入你的名字: <>请输入你的年龄: <<42 +>>你好,Inigo!你有504个月大了。 +再见,Inigo。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => { @@ -21,10 +21,10 @@ public void Main_HappyPath() [TestMethod] public void Main_GivenInvalidAge_ThrowException() { - string expected = @"Enter your first name: <>Enter your age: <>The age entered ,forty-two, is not valid. -Goodbye Inigo"; + string expected = @"请输入你的名字: <>请输入你的年龄: <>你输入的年龄'forty-two'不是一个有效的整数。 +再见,Inigo。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => { diff --git a/src/Chapter05.Tests/Listing05.30.ThrowingAnException.Tests.cs b/src/Chapter05.Tests/Listing05.30.ThrowingAnException.Tests.cs index ae938c6e..d801305b 100644 --- a/src/Chapter05.Tests/Listing05.30.ThrowingAnException.Tests.cs +++ b/src/Chapter05.Tests/Listing05.30.ThrowingAnException.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_30.Tests; [TestClass] @@ -8,10 +8,10 @@ public class ThrowingExceptionsTests public void Main_WriteExecutionData() { string view = -@"Begin executing -Throw exception -Unexpected error: Arbitrary exception -Shutting down..."; +@"开始执行 +抛出异常 +非预期的错误: 任意异常 +正在关闭..."; IntelliTect.TestTools.Console.ConsoleAssert.Expect(view, () => diff --git a/src/Chapter05.Tests/Listing05.34.CustomParameterValidation.Tests.cs b/src/Chapter05.Tests/Listing05.34.CustomParameterValidation.Tests.cs index 63a3de2e..5c70536a 100644 --- a/src/Chapter05.Tests/Listing05.34.CustomParameterValidation.Tests.cs +++ b/src/Chapter05.Tests/Listing05.34.CustomParameterValidation.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_34.Tests; [TestClass] @@ -9,8 +9,8 @@ public void Main_NoArgs_ExpectErrors() { string[] args = Array.Empty(); string expected = """ - ERROR: You must specify the URL and the file name - Usage: Downloader.exe + 错误: 必须指定URL和文件名 + 用法: Downloader.exe <文件名> """; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, @@ -65,7 +65,7 @@ public void Main_FirstArg_ExpectSecondNullError() public void Main_InvalidSecondArg_ExpectWhitespaceError() { string[] args = { "Inigo", " " }; - string expected = "fileName cannot be empty or only whitespace"; + string expected = "fileName不能为空或者空串"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => @@ -146,7 +146,7 @@ public void Main_InvalidSecondArg_ExpectWhitespaceError() public void Main_InvalidSecondArg_ExpectHTTPError() { string[] args = { "Inigo", "Montoya" }; - string expected = "URL must start with \'HTTPS\'."; + string expected = "URL必须以\'HTTPS\'开头。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => @@ -169,7 +169,7 @@ public void Main_IntelliTectIndexHtmlArgs_DownloadFile() { string fileName = "about"; string[] args = { "https://IntelliTect.com", fileName }; - string expected = $"Downloaded '{args[1]}' from '{args[0]}'."; + string expected = $"已从'{args[0]}'下载'{args[1]}'。"; int? result = null; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter05.Tests/Listing05.35.TryCatch.Tests.cs b/src/Chapter05.Tests/Listing05.35.TryCatch.Tests.cs index 5a81f327..9ebbe2d6 100644 --- a/src/Chapter05.Tests/Listing05.35.TryCatch.Tests.cs +++ b/src/Chapter05.Tests/Listing05.35.TryCatch.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_35.Tests; [TestClass] @@ -8,9 +8,9 @@ public class LeveragingTryParseTests public void Main_InputNameAndAge35_AgeProperlyParsed() { const string expected = -@"Enter your first name: <>Enter your age: <<36 ->>Hi Inigo! You are 432 months old."; +@"请输入你的名字: <>请输入你的年龄: <<36 +>>你好,Inigo!你有432个月大了。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, LeveragingTryParse.Main); @@ -20,9 +20,9 @@ public void Main_InputNameAndAge35_AgeProperlyParsed() public void Main_InputNameAndAgeThirtyFive_AgeNotParsed() { const string expected = -@"Enter your first name: <>Enter your age: <>The age entered, ThirtyFive, is not valid."; +@"请输入你的名字: <>请输入你的年龄: <>你输入的年龄'ThirtyFive'不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, LeveragingTryParse.Main); diff --git a/src/Chapter05/Listing05.04.DeclaringAMethod.cs b/src/Chapter05/Listing05.04.DeclaringAMethod.cs index 468ec315..35bbaead 100644 --- a/src/Chapter05/Listing05.04.DeclaringAMethod.cs +++ b/src/Chapter05/Listing05.04.DeclaringAMethod.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_04; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_04; #region INCLUDE public class IntroducingMethods @@ -10,10 +10,10 @@ public static void Main() string fullName; string initials; - Console.WriteLine("º٣¬Ä㣡"); + Console.WriteLine("嘿,你!"); - firstName = GetUserInput("ÇëÊäÈëÄãµÄÃû×Ö: "); - lastName = GetUserInput("ÇëÊäÈëÄãµÄÐÕÊÏ: "); + firstName = GetUserInput("请输入你的名字: "); + lastName = GetUserInput("请输入你的姓氏: "); fullName = GetFullName(firstName, lastName); initials = GetInitials(firstName, lastName); @@ -26,7 +26,7 @@ static string GetUserInput(string prompt) return Console.ReadLine() ?? string.Empty; } - static string GetFullName( + static string GetFullName( string firstName, string lastName) => $"{ firstName } { lastName }"; @@ -34,7 +34,7 @@ static string GetFullName( static void DisplayGreeting(string fullName, string initials) { Console.WriteLine( - $"Äãºã¬{ fullName }£¡ÄãµÄÐÕÃûËõдÊÇ{ initials }"); + $"你好,{ fullName }!你的姓名缩写是{ initials }"); return; } diff --git a/src/Chapter05/Listing05.06.ReturningMultipleValuesViaTuples.cs b/src/Chapter05/Listing05.06.ReturningMultipleValuesViaTuples.cs index fb3b0f2f..95134239 100644 --- a/src/Chapter05/Listing05.06.ReturningMultipleValuesViaTuples.cs +++ b/src/Chapter05/Listing05.06.ReturningMultipleValuesViaTuples.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_06; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_06; #region INCLUDE public class Program @@ -13,8 +13,8 @@ static string GetUserInput(string prompt) #endregion HIGHLIGHT { string firstName, lastName; - firstName = GetUserInput("ÇëÊäÈëÄãµÄÃû×Ö: "); - lastName = GetUserInput("ÇëÊäÈëÄãµÄÐÕÊÏ: "); + firstName = GetUserInput("请输入你的名字: "); + lastName = GetUserInput("请输入你的姓氏: "); return (firstName, lastName); } public static void Main() @@ -22,7 +22,7 @@ public static void Main() #region HIGHLIGHT (string First, string Last) name = GetName(); #endregion HIGHLIGHT - Console.WriteLine($"Äãºã¬{ name.First } { name.Last }£¡"); + Console.WriteLine($"你好,{ name.First } { name.Last }!"); } } #endregion INCLUDE diff --git a/src/Chapter05/Listing05.12.SpecifyingTheUsingDirectiveInsideANamespaceDeclaration.cs b/src/Chapter05/Listing05.12.SpecifyingTheUsingDirectiveInsideANamespaceDeclaration.cs index ebc02772..ca52f7d4 100644 --- a/src/Chapter05/Listing05.12.SpecifyingTheUsingDirectiveInsideANamespaceDeclaration.cs +++ b/src/Chapter05/Listing05.12.SpecifyingTheUsingDirectiveInsideANamespaceDeclaration.cs @@ -1,69 +1,25 @@ -// Disabled because not attributes have not been covered -// and the attribute is not available in .NET 6.0. -#pragma warning disable SYSLIB1045 // Convert to 'GeneratedRegexAttribute'. - -// 该代码清单存在bug,以中文版书中的为准。 -// 或者参考下面这个: -//namespace EssentialCSharp -//{ -// using System; -// class HelloWorld -// { -// static void Main() -// { -// // 因为上方的using指令,所以 -// // 不需要用System限定Console类。 -// Console.WriteLine("你好,我的名字是Inigo Montoya。"); -// } -// } -//} -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_12; - -#region INCLUDE -// The using directive imports all types from the -// specified namespace into the entire file -using System.Text.RegularExpressions; - -public class Program +// 中文版译稿代码清单5.12:在命名空间声明中使用 using 指令。 +// HelloWorld 的 public 可见性和下方 Program 包装器用于配套清单运行器。 +namespace EssentialCSharp { - public static void Main() - { - #region EXCLUDE - const string firstName = "FirstName"; - const string initial = "Initial"; - const string lastName = "LastName"; - - // Explaining regular expressions is beyond the - // scope of this book. - // See https://www.regular-expressions.info/ for - // more information. - const string pattern = $""" - (?<{firstName}>\w+)\s+((?<{initial}>\w)\.\s+)?(?<{lastName}>\w+)\s* - """; - - Console.WriteLine( - "输入你的全名:(例如Inigo T. Montoya): "); - string name = Console.ReadLine()!; - - #endregion EXCLUDE - #region HIGHLIGHT - // 因为using指令的存在,不需要用 - // System.Text.RegularExpressions限定 - // RegEx类型 - Match match = Regex.Match(name, pattern); - #endregion HIGHLIGHT - #region EXCLUDE + #region INCLUDE + using System; - if (match.Success) + public class HelloWorld + { + public static void Main() { - Console.WriteLine( - $"{firstName}: {match.Groups[firstName]}"); - Console.WriteLine( - $"{initial}: {match.Groups[initial]}"); - Console.WriteLine( - $"{lastName}: {match.Groups[lastName]}"); + // 因为上方的 using 指令,所以不需要用 System 限定 Console 类。 + Console.WriteLine("你好,我的名字是Inigo Montoya。"); } - #endregion EXCLUDE + } + #endregion INCLUDE +} + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_12 +{ + public class Program + { + public static void Main() => global::EssentialCSharp.HelloWorld.Main(); } } -#endregion INCLUDE diff --git a/src/Chapter05/Listing05.18.PassingVariablesByReference.cs b/src/Chapter05/Listing05.18.PassingVariablesByReference.cs index c687df64..2217a9e2 100644 --- a/src/Chapter05/Listing05.18.PassingVariablesByReference.cs +++ b/src/Chapter05/Listing05.18.PassingVariablesByReference.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_18; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter05.Listing05_18; #region INCLUDE public class Program @@ -6,8 +6,8 @@ public class Program public static void Main() { // ... - string first = "ÄãºÃ"; - string second = "Ôټû"; + string first = "你好"; + string second = "再见"; #region HIGHLIGHT Swap(ref first, ref second); #endregion HIGHLIGHT diff --git a/src/Chapter06.Tests/Listing06.01.Tests.cs b/src/Chapter06.Tests/Listing06.01.Tests.cs index 788f0da4..f92b857a 100644 --- a/src/Chapter06.Tests/Listing06.01.Tests.cs +++ b/src/Chapter06.Tests/Listing06.01.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_01.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"No output in this example"; + const string expected = @"本例无实际输出"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter06.Tests/Listing06.06.AccessingFields.Tests.cs b/src/Chapter06.Tests/Listing06.06.AccessingFields.Tests.cs index 1f7273fd..b2f5c4c1 100644 --- a/src/Chapter06.Tests/Listing06.06.AccessingFields.Tests.cs +++ b/src/Chapter06.Tests/Listing06.06.AccessingFields.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_06.Tests; [TestClass] @@ -12,7 +12,7 @@ public void Main_AccessingFields_WriteFieldValues() { Assert.IsNotNull(TestContext); const string expected = - @"Inigo Montoya: Ããǿ¹ý»î"; + @"Inigo Montoya: 勉强过活"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter06.Tests/Listing06.08.AccessingFieldsFromOutsideTheContainingClass.Tests.cs b/src/Chapter06.Tests/Listing06.08.AccessingFieldsFromOutsideTheContainingClass.Tests.cs index 2abe9cae..cd58f3db 100644 --- a/src/Chapter06.Tests/Listing06.08.AccessingFieldsFromOutsideTheContainingClass.Tests.cs +++ b/src/Chapter06.Tests/Listing06.08.AccessingFieldsFromOutsideTheContainingClass.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_08.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_AccessingFieldsFromOutsideClass_WriteFieldValues() { const string expected = - @"Inigo Montoya: Ããǿ¹ý»î"; + @"Inigo Montoya: 勉强过活"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter06.Tests/Listing06.11.UsingThisWithAMethod.Tests.cs b/src/Chapter06.Tests/Listing06.11.UsingThisWithAMethod.Tests.cs index f381fb40..2e476054 100644 --- a/src/Chapter06.Tests/Listing06.11.UsingThisWithAMethod.Tests.cs +++ b/src/Chapter06.Tests/Listing06.11.UsingThisWithAMethod.Tests.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_11.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_11.Tests; [TestClass] public class ProgramTests @@ -7,7 +7,7 @@ public class ProgramTests public void Main_AccessMethodWithThis_WriteMethodResult() { const string expected = - @"Name changed to 'Inigo Montoya'"; + @"姓名更改为'Inigo Montoya'"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter06.Tests/Listing06.12.Tests.cs b/src/Chapter06.Tests/Listing06.12.Tests.cs index bad5a5bb..316264f8 100644 --- a/src/Chapter06.Tests/Listing06.12.Tests.cs +++ b/src/Chapter06.Tests/Listing06.12.Tests.cs @@ -1,4 +1,4 @@ -using IntelliTect.TestTools.Console; +using IntelliTect.TestTools.Console; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_12.Tests; @@ -9,7 +9,7 @@ public class EmployeeTests public void DataStorage_ReadTrace() { const string expected = - "Writing employee (Inigo Montoya) information to file."; + "将员工(Inigo Montoya)的信息写入文件。"; Employee employee = new() { diff --git a/src/Chapter06.Tests/Listing06.14.DataRetrievalFromAFile.Tests.cs b/src/Chapter06.Tests/Listing06.14.DataRetrievalFromAFile.Tests.cs index 92f7df44..cc47ae58 100644 --- a/src/Chapter06.Tests/Listing06.14.DataRetrievalFromAFile.Tests.cs +++ b/src/Chapter06.Tests/Listing06.14.DataRetrievalFromAFile.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_14.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_WriteToFileThenRetrieveDataFromFile_WriteStoredDataToScreen() { const string expected = -@"Name changed to 'Inigo Montoya' +@"姓名更改为'Inigo Montoya' Inigo Montoya: "; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter06.Tests/Listing06.19.AutomaticallyImplementedProperties.Tests.cs b/src/Chapter06.Tests/Listing06.19.AutomaticallyImplementedProperties.Tests.cs index 3d32d37e..05d855a8 100644 --- a/src/Chapter06.Tests/Listing06.19.AutomaticallyImplementedProperties.Tests.cs +++ b/src/Chapter06.Tests/Listing06.19.AutomaticallyImplementedProperties.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_19.Tests; [TestClass] @@ -9,7 +9,7 @@ public void Main_AutoPropertySetterGetter_WriteGetterValue() { const string expected = @"Inigo -µçÄԷ¢ÉÕÓÑ"; +电脑发烧友"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs b/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs index ec273fa5..993ece65 100644 --- a/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs +++ b/src/Chapter06.Tests/Listing06.26.DefiningAConstructor.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_26.Tests; [TestClass] @@ -9,7 +9,7 @@ public class ProgramTests public void Main_UsingAConstructor_WriteFirstNameLastNameSalary() { const string expected = - @"Inigo Montoya: ̫ÉÙÁË"; + @"Inigo Montoya: 太少了"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter06.Tests/Listing06.27.CallingAConstructor.Tests.cs b/src/Chapter06.Tests/Listing06.27.CallingAConstructor.Tests.cs index fd1f8907..68ed6378 100644 --- a/src/Chapter06.Tests/Listing06.27.CallingAConstructor.Tests.cs +++ b/src/Chapter06.Tests/Listing06.27.CallingAConstructor.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void Main_UsingAConstructor_WriteFirstNameLastNameSalary() { const string expected = - @"Inigo Montoya: ̫ÉÙÁË"; + @"Inigo Montoya: 太少了"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter06.Tests/Listing06.28.Tests.cs b/src/Chapter06.Tests/Listing06.28.Tests.cs index 2a790eb3..b6477eb7 100644 --- a/src/Chapter06.Tests/Listing06.28.Tests.cs +++ b/src/Chapter06.Tests/Listing06.28.Tests.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_28.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_28.Tests; [TestClass] public class ProgramTests @@ -7,7 +7,7 @@ public class ProgramTests public void Main_UsingAConstructor_WriteFirstNameLastNameSalary() { const string expected = - "Inigo Montoya: ̫ÉÙÁË"; + "Inigo Montoya: 太少了"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter06.Tests/Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.Tests.cs b/src/Chapter06.Tests/Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.Tests.cs index 35f1b386..d5aa6a5c 100644 --- a/src/Chapter06.Tests/Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.Tests.cs +++ b/src/Chapter06.Tests/Listing06.30.CallingAnObjectInitializerWithExplicitMemberAssignment.Tests.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_30.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_30.Tests; [TestClass] public class ProgramTests @@ -7,7 +7,7 @@ public class ProgramTests public void Main_ObjectInitializerSetTitleSalary_WriteEmployeeWithTitleSalary() { const string expected = - @"Inigo Montoya (µçÄԷ¢ÉÕÓÑ): Not enough"; + @"Inigo Montoya (电脑发烧友): 不够"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter06.Tests/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs b/src/Chapter06.Tests/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs index 55ead280..38473b4f 100644 --- a/src/Chapter06.Tests/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs +++ b/src/Chapter06.Tests/Listing06.41.UsingNotNullWhenAndNotNullIfNotNullAttributes.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_41.Tests; [TestClass] @@ -8,7 +8,7 @@ public class NullabilityAttributesExaminedTests public void TryGetAsText_Given4_ReturnFour() { Assert.IsTrue(NullabilityAttributesExamined.TryGetDigitAsText('4', out string? text)); - Assert.AreEqual("four", text); + Assert.AreEqual("四", text); } @@ -21,7 +21,7 @@ public void TryGetAsText_GivenX_ReturnFalse() [TestMethod] public void TryGetAsText_GivenX4X2_ReturnFourTwo() { - Assert.AreEqual("four-two", + Assert.AreEqual("四-二", NullabilityAttributesExamined.TryGetDigitsAsText("X4X2")); Assert.AreEqual(null, diff --git a/src/Chapter06.Tests/Listing06.51.DeclaringAStaticClass.Tests.cs b/src/Chapter06.Tests/Listing06.51.DeclaringAStaticClass.Tests.cs index 43cef732..b6d36a95 100644 --- a/src/Chapter06.Tests/Listing06.51.DeclaringAStaticClass.Tests.cs +++ b/src/Chapter06.Tests/Listing06.51.DeclaringAStaticClass.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_51.Tests; [TestClass] @@ -14,8 +14,8 @@ public void MainTest_ArgsHasZeroElements_ThrowException() [TestMethod] public void MainTest() { - const string expected = @"Longest argument length = 10 -Shortest argument length = 2"; + const string expected = @"最长的实参长度 = 10 +最短的实参长度 = 2"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => { Program.Main( diff --git a/src/Chapter06.Tests/Listing06.56.DefiningANestedClass.Tests.cs b/src/Chapter06.Tests/Listing06.56.DefiningANestedClass.Tests.cs index 0ae7cc3d..b5200f11 100644 --- a/src/Chapter06.Tests/Listing06.56.DefiningANestedClass.Tests.cs +++ b/src/Chapter06.Tests/Listing06.56.DefiningANestedClass.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_56.Tests; [TestClass] @@ -15,7 +15,7 @@ public void Main_CreatesEmployee() }; const string expected = - @"'Creating' a new Employee."; + @"'正在创建'新员工。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, (Action)Program.Main, arguments); @@ -32,7 +32,7 @@ public void Main_UpdateEmployee_EmployeeUpdated() }; const string expected = - @"'Updating' a new Employee."; + @"'正在更新'员工。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, (Action)Program.Main, arguments); @@ -49,7 +49,7 @@ public void Main_RemovesEmployee() }; const string expected = - @"'Updating' a new Employee."; + @"'正在更新'员工。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, (Action)Program.Main, arguments); diff --git a/src/Chapter06/Listing06.03.InstantiatingAClass.cs b/src/Chapter06/Listing06.03.InstantiatingAClass.cs index a45842e0..f602b004 100644 --- a/src/Chapter06/Listing06.03.InstantiatingAClass.cs +++ b/src/Chapter06/Listing06.03.InstantiatingAClass.cs @@ -1,4 +1,4 @@ -// ˵Ã÷ : only partial implementation provided for elucidation. +// 说明 : only partial implementation provided for elucidation. #pragma warning disable IDE0060 // Remove unused parameter namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_03; diff --git a/src/Chapter06/Listing06.27.CallingAConstructor.cs b/src/Chapter06/Listing06.27.CallingAConstructor.cs index 9ce03a5f..103b6c04 100644 --- a/src/Chapter06/Listing06.27.CallingAConstructor.cs +++ b/src/Chapter06/Listing06.27.CallingAConstructor.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_27; using Listing06_30; @@ -11,7 +11,7 @@ public static void Main() #region HIGHLIGHT employee = new("Inigo", "Montoya"); #endregion HIGHLIGHT - employee.Salary = "̫ÉÙÁË"; + employee.Salary = "太少了"; Console.WriteLine( "{0} {1}: {2}", diff --git a/src/Chapter06/Listing06.45.DeclaringAStaticField.cs b/src/Chapter06/Listing06.45.DeclaringAStaticField.cs index 1c76e0a4..87e67877 100644 --- a/src/Chapter06/Listing06.45.DeclaringAStaticField.cs +++ b/src/Chapter06/Listing06.45.DeclaringAStaticField.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_45; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter06.Listing06_45; #region INCLUDE public class Employee @@ -21,7 +21,7 @@ public Employee(string firstName, string lastName) public int Id { get; private set; } public string FirstName { get; set; } public string LastName { get; set; } - public string? Salary { get; set; } = "²»¹»"; + public string? Salary { get; set; } = "不够"; // ... } diff --git a/src/Chapter07.Tests/Listing07.17.DefiningAbstractMembers.Tests.cs b/src/Chapter07.Tests/Listing07.17.DefiningAbstractMembers.Tests.cs index ea14f31e..32494ad3 100644 --- a/src/Chapter07.Tests/Listing07.17.DefiningAbstractMembers.Tests.cs +++ b/src/Chapter07.Tests/Listing07.17.DefiningAbstractMembers.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_17.Tests; [TestClass] @@ -12,9 +12,9 @@ public void Contact_GetSummaryOverridden() Address = "111 W St City, State 11111" }; - string expected = "FirstName: Inigo" + Environment.NewLine + - "LastName: Montoya" + Environment.NewLine + - "Address: 111 W St City, State 11111" + Environment.NewLine; + string expected = "名字: Inigo" + Environment.NewLine + + "姓氏: Montoya" + Environment.NewLine + + "地址: 111 W St City, State 11111" + Environment.NewLine; Assert.AreEqual(expected, contact.GetSummary()); } @@ -26,10 +26,10 @@ public void Appointment_GetSummaryOverridden() "Soccer tournament", "111 W St City, State 11111", new DateTime(2008, 7, 19), new DateTime(2008, 7, 18)); - string expected = "Subject: Soccer tournament" + Environment.NewLine + - $"Start: {appointment.StartDateTime}" + Environment.NewLine + - $"End: {appointment.EndDateTime}" + Environment.NewLine + - "Location: 111 W St City, State 11111"; + string expected = "主题: Soccer tournament" + Environment.NewLine + + $"开始时间: {appointment.StartDateTime}" + Environment.NewLine + + $"结束时间: {appointment.EndDateTime}" + Environment.NewLine + + "地点: 111 W St City, State 11111"; Assert.AreEqual(expected, appointment.GetSummary()); } diff --git a/src/Chapter07.Tests/Listing07.18.UsingPolymorphismToListThePdaItems.Tests.cs b/src/Chapter07.Tests/Listing07.18.UsingPolymorphismToListThePdaItems.Tests.cs index 343a0820..6249fa45 100644 --- a/src/Chapter07.Tests/Listing07.18.UsingPolymorphismToListThePdaItems.Tests.cs +++ b/src/Chapter07.Tests/Listing07.18.UsingPolymorphismToListThePdaItems.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_18.Tests; [TestClass] @@ -12,19 +12,19 @@ public void Main_WriteMultiplePdaItemToScreen() string expected = $@"________ -FirstName: Sherlock -LastName: Holmes -Address: 221B Baker Street, London, England +名字: Sherlock +姓氏: Holmes +地址: 221B Baker Street, London, England ________ -Subject: Soccer tournament -Start: {startDateTime} -End: {endDateTime} -Location: Estádio da Machava +主题: Soccer tournament +开始时间: {startDateTime} +结束时间: {endDateTime} +地点: Estádio da Machava ________ -FirstName: Anne -LastName: Frank -Address: Apt 56B, Whitehaven Mansions, Sandhurst Sq, London" + Environment.NewLine + Environment.NewLine; +名字: Anne +姓氏: Frank +地址: Apt 56B, Whitehaven Mansions, Sandhurst Sq, London" + Environment.NewLine + Environment.NewLine; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter07.Tests/Listing07.20.TypeCheckingWithIsOperator.Tests.cs b/src/Chapter07.Tests/Listing07.20.TypeCheckingWithIsOperator.Tests.cs index 9c95a94b..3829b274 100644 --- a/src/Chapter07.Tests/Listing07.20.TypeCheckingWithIsOperator.Tests.cs +++ b/src/Chapter07.Tests/Listing07.20.TypeCheckingWithIsOperator.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_20.Tests; [TestClass] @@ -8,8 +8,8 @@ public class ProgramTests public void Main_GivenEmployeeID_PersonAndEmployee() { const string expected = """ - Id corresponds to a Person object: Inigo Montoya. - Id (46041779-79D5-4268-BCD9-25BF61F8B4F6) is also an Employee object. + Id对应于一个Person对象: Inigo Montoya。 + Id(46041779-79D5-4268-BCD9-25BF61F8B4F6)也是一个Employee对象。 """; IntelliTect.TestTools.Console.ConsoleAssert.Expect( @@ -21,7 +21,7 @@ public void Main_GivenEmployeeID_PersonAndEmployee() [TestMethod] public void Main_GivenPerson_Person() { - const string expected = "Id corresponds to a Person object: Inigo Montoya."; + const string expected = "Id对应于一个Person对象: Inigo Montoya。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, @@ -40,7 +40,7 @@ public void Main_GivenNull_Null() public void Main_GivenUnknownId_NotPersonOrEmployee() { Guid guid = Guid.NewGuid(); - string expected = "Id was unknown so null was returned."; + string expected = $"Id'{guid}'不是一个Employee或Person对象。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, diff --git a/src/Chapter07.Tests/Listing07.23.Tests.cs b/src/Chapter07.Tests/Listing07.23.Tests.cs index 0922db3c..8bda3399 100644 --- a/src/Chapter07.Tests/Listing07.23.Tests.cs +++ b/src/Chapter07.Tests/Listing07.23.Tests.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_23.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_23.Tests; [TestClass] public class SolsticeHelperTests @@ -38,14 +38,14 @@ public void TryGetSolstice_21DayWrongMonth_ReturnsFalse() public void TryGetSolstice_21DayRightMonth_ReturnsTrueWinterSolstice() { Assert.IsTrue(SolsticeHelper.TryGetSolstice(new DateTime(2023, 12, 21), out string? solstice)); - Assert.AreEqual("Winter Solstice", solstice); + Assert.AreEqual("冬至", solstice); } [TestMethod] public void TryGetSolstice_20DayRightMonth_ReturnsTrueSummerSolstice() { Assert.IsTrue(SolsticeHelper.TryGetSolstice(new DateTime(2024, 6, 21), out string? solstice)); - Assert.AreEqual("Summer Solstice", solstice); + Assert.AreEqual("夏至", solstice); } [TestMethod] diff --git a/src/Chapter07.Tests/Listing07.24.Tests.cs b/src/Chapter07.Tests/Listing07.24.Tests.cs index f1507123..251b842d 100644 --- a/src/Chapter07.Tests/Listing07.24.Tests.cs +++ b/src/Chapter07.Tests/Listing07.24.Tests.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_24.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_24.Tests; [TestClass] public class PeriodsOfTheDayTests @@ -18,25 +18,25 @@ public void IsDeveloperWorkHours_ValidNonWorkingHours_ReturnsFalse() [TestMethod] public void GetPeriodOfDay_Dawn_ReturnsDawn() { - Assert.AreEqual("Dawn", PeriodsOfTheDay.GetPeriodOfDay(5)); + Assert.AreEqual("黎明", PeriodsOfTheDay.GetPeriodOfDay(5)); } [TestMethod] public void GetPeriodOfDay_Morning_ReturnsMorning() { - Assert.AreEqual("Morning", PeriodsOfTheDay.GetPeriodOfDay(6)); + Assert.AreEqual("上午", PeriodsOfTheDay.GetPeriodOfDay(6)); } [TestMethod] public void GetPeriodOfDay_Afternoon_ReturnsAfternoon() { - Assert.AreEqual("Afternoon", PeriodsOfTheDay.GetPeriodOfDay(13)); + Assert.AreEqual("下午", PeriodsOfTheDay.GetPeriodOfDay(13)); } [TestMethod] public void GetPeriodOfDay_Evening_ReturnsEvening() { - Assert.AreEqual("Evening", PeriodsOfTheDay.GetPeriodOfDay(18)); + Assert.AreEqual("晚上", PeriodsOfTheDay.GetPeriodOfDay(18)); } [TestMethod] diff --git a/src/Chapter07.Tests/Listing07.29.PositionalPatternMatching.Tests.cs b/src/Chapter07.Tests/Listing07.29.PositionalPatternMatching.Tests.cs index 9e47b40c..89380e4e 100644 --- a/src/Chapter07.Tests/Listing07.29.PositionalPatternMatching.Tests.cs +++ b/src/Chapter07.Tests/Listing07.29.PositionalPatternMatching.Tests.cs @@ -1,4 +1,4 @@ -using System.Drawing; +using System.Drawing; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_29.Tests; @@ -28,7 +28,7 @@ public void Main_EncryptFile_Success(bool isVgaVisible, int x, int y) [DataRow(0, -1, "III")] public void GetQuadrant(int x, int y, string quadrant) { - Assert.AreEqual($"Quadrant { quadrant }", PointHelper.GetQuadrant(new Point(x,y)), + Assert.AreEqual(quadrant == "I" ? "象限I" : $"象限 {quadrant}", PointHelper.GetQuadrant(new Point(x,y)), $"({ x}, {y}) is not in the expected {quadrant}."); } } diff --git a/src/Chapter07.Tests/Listing07.33.ListPatternMatching.Tests.cs b/src/Chapter07.Tests/Listing07.33.ListPatternMatching.Tests.cs index 998c9ce2..2976a221 100644 --- a/src/Chapter07.Tests/Listing07.33.ListPatternMatching.Tests.cs +++ b/src/Chapter07.Tests/Listing07.33.ListPatternMatching.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_33.Tests; @@ -17,7 +17,7 @@ public void ParseHelpCommand(string command) { command = item; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - "Command Help...", () => Program.Main(new[] { command })); + "命令帮助...", () => Program.Main(new[] { command })); } } @@ -30,7 +30,7 @@ public void ParseCatCommand(string command, string fileName) { command = $"{item}"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - $"Catalog '{fileName}'...", () => Program.Main(new[] { command, fileName })); + $"编录 '{fileName}'...", () => Program.Main(new[] { command, fileName })); } } @@ -43,7 +43,7 @@ public void ParseCopyCommand(string command, string sourceFile, string targetFil { command = $"{item}"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( - $"Copy '{sourceFile}' '{targetFile}'...", () => Program.Main(new[] { command, sourceFile, targetFile })); + $"复制 '{sourceFile}' '{targetFile}'...", () => Program.Main(new[] { command, sourceFile, targetFile })); } } diff --git a/src/Chapter07/Listing07.23.ConstantPatternWithSwitchExpression.cs b/src/Chapter07/Listing07.23.ConstantPatternWithSwitchExpression.cs index bccb21ff..ff965938 100644 --- a/src/Chapter07/Listing07.23.ConstantPatternWithSwitchExpression.cs +++ b/src/Chapter07/Listing07.23.ConstantPatternWithSwitchExpression.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_23; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_23; #region INCLUDE using System.Diagnostics.CodeAnalysis; @@ -30,8 +30,8 @@ public static bool TryGetSolstice(DateTime date, { if ((solstice = date.Month switch { - 12 => "¶¬ÖÁ", - 6 => "ÏÄÖÁ", + 12 => "冬至", + 6 => "夏至", _ => null }) is not null) return true; } diff --git a/src/Chapter08.Tests/Listing08.14.ForcingTheDesirableRunEncapsulation.Tests.cs b/src/Chapter08.Tests/Listing08.14.ForcingTheDesirableRunEncapsulation.Tests.cs index e46e976a..546a7d54 100644 --- a/src/Chapter08.Tests/Listing08.14.ForcingTheDesirableRunEncapsulation.Tests.cs +++ b/src/Chapter08.Tests/Listing08.14.ForcingTheDesirableRunEncapsulation.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter08.Listing08_14.Tests; [TestClass] @@ -7,15 +7,15 @@ public class ProgramTests [TestMethod] public void Main() { - string expected = @"Invoking ((IExecuteProcessActivity)activity).Run()... + string expected = @"正在调用((IExecuteProcessActivity)activity).Run()... IWorkflowActivity.Start()... ExecuteProcessActivity.RedirectStandardInOut()... ExecuteProcessActivity.IExecuteProcessActivity.ExecuteProcess()... IExecuteProcessActivity.RestoreStandardInOut()... IWorkflowActivity.Stop()... -Invoking activity.Run()... -Executing non-polymorphic Run() with process 'dotnet'."; +正在调用activity.Run()... +正在用进程'dotnet'执行非多态性的Run()。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter09.Tests/Listing09.25.SubtleBoxAndUnboxInstructions.Tests.cs b/src/Chapter09.Tests/Listing09.25.SubtleBoxAndUnboxInstructions.Tests.cs index 3776a162..ef7b09e5 100644 --- a/src/Chapter09.Tests/Listing09.25.SubtleBoxAndUnboxInstructions.Tests.cs +++ b/src/Chapter09.Tests/Listing09.25.SubtleBoxAndUnboxInstructions.Tests.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_25.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_25.Tests; [TestClass] public class ProgramTests @@ -16,7 +16,7 @@ public void AddToArrayIndexWithoutCasing() [TestMethod] public void AddToArrayWithCasting() { - const string OutputFormatString = @"Enter an integer between 2 and 1000: <<{0}>>0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, "; + const string OutputFormatString = @"输入2~1000的整数,我将生成这么多个斐波那契数: <<{0}>>0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, "; string expected = string.Format(OutputFormatString, 42); diff --git a/src/Chapter09.Tests/Listing09.33.WritingEnumValueidentifierToTraceBuffers.Tests.cs b/src/Chapter09.Tests/Listing09.33.WritingEnumValueidentifierToTraceBuffers.Tests.cs index 5744d77d..5feff852 100644 --- a/src/Chapter09.Tests/Listing09.33.WritingEnumValueidentifierToTraceBuffers.Tests.cs +++ b/src/Chapter09.Tests/Listing09.33.WritingEnumValueidentifierToTraceBuffers.Tests.cs @@ -1,4 +1,4 @@ -using System.Data; +using System.Data; using System.Diagnostics; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_33.Tests; @@ -19,7 +19,7 @@ public void TraceBuffer_Output_MatchesExpected() Program.Main(); string traceOutput = stringWriter.ToString(); - string expected = $"The connection is currently Disconnecting"; + string expected = $"连接目前Disconnecting。"; Assert.IsTrue(traceOutput.Contains(expected)); } diff --git a/src/Chapter09.Tests/Listing09.38.UsingFlagsAttribute.Tests.cs b/src/Chapter09.Tests/Listing09.38.UsingFlagsAttribute.Tests.cs index 06082428..5cc5fd34 100644 --- a/src/Chapter09.Tests/Listing09.38.UsingFlagsAttribute.Tests.cs +++ b/src/Chapter09.Tests/Listing09.38.UsingFlagsAttribute.Tests.cs @@ -1,4 +1,4 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_38.Tests; @@ -9,9 +9,9 @@ public class ProgramTests public void Main_FileAttributes_UseFlagsAttribute() { string expected = (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) || RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) - ? @"""ReadOnly | Hidden"" outputs as ""ReadOnly, Hidden"" + ? @"原本输出""ReadOnly, Hidden"",替换为""ReadOnly | Hidden""。 ReadOnly, Hidden" - : @"""ReadOnly"" outputs as ""ReadOnly"" + : @"原本输出""ReadOnly"",替换为""ReadOnly""。 ReadOnly"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( diff --git a/src/Chapter09/Listing09.17.CustomEqualityImplementation.cs b/src/Chapter09/Listing09.17.CustomEqualityImplementation.cs index c1396b44..f83487d4 100644 --- a/src/Chapter09/Listing09.17.CustomEqualityImplementation.cs +++ b/src/Chapter09/Listing09.17.CustomEqualityImplementation.cs @@ -1,12 +1,12 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_17; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_17; public readonly record struct Angle( int Degrees, int Minutes, int Seconds, string? Name = null) { - // Ð޸ÄEquals()ÒԺöÂÔNameÊôÐÔ + // 修改Equals()以忽略Name属性 #region INCLUDE public bool Equals(Angle other) => (Degrees, Minutes, Seconds).Equals( (other.Degrees, other.Minutes, other.Seconds)); - #endregion INCLUDE + #endregion INCLUDE } diff --git a/src/Chapter09/Listing09.21.ImplementStronglyTypedEquals.cs b/src/Chapter09/Listing09.21.ImplementStronglyTypedEquals.cs index 619b66fb..f6446ad4 100644 --- a/src/Chapter09/Listing09.21.ImplementStronglyTypedEquals.cs +++ b/src/Chapter09/Listing09.21.ImplementStronglyTypedEquals.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_21; @@ -29,8 +29,8 @@ public override bool Equals(object? obj) public bool Equals(Foo? other) { if (other is null) return false; - // ²½Öè5 - // ·µ»Ø(this.Number, this.Name) == (other.Number, other.Name); + // 步骤5 + // 返回(this.Number, this.Name) == (other.Number, other.Name); return true; } #endregion INCLUDE diff --git a/src/Chapter09/Listing09.26.UnboxingMustBeToTheUnderlyingType.cs b/src/Chapter09/Listing09.26.UnboxingMustBeToTheUnderlyingType.cs index bd70e6c9..bf814645 100644 --- a/src/Chapter09/Listing09.26.UnboxingMustBeToTheUnderlyingType.cs +++ b/src/Chapter09/Listing09.26.UnboxingMustBeToTheUnderlyingType.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_26; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter09.Listing09_26; public class DisplayFibonacci { static void Main() @@ -12,7 +12,7 @@ static void Main() number = 42; thing = number; - // ´íÎó: InvalidCastException + // 错误: InvalidCastException // bigNumber = (double)thing; bigNumber = (double)(int)thing; // ... diff --git a/src/Chapter10.Tests/Listing10.07.LeveragingADifferentLibrary.Tests.cs b/src/Chapter10.Tests/Listing10.07.LeveragingADifferentLibrary.Tests.cs index 06af33a0..e872ac35 100644 --- a/src/Chapter10.Tests/Listing10.07.LeveragingADifferentLibrary.Tests.cs +++ b/src/Chapter10.Tests/Listing10.07.LeveragingADifferentLibrary.Tests.cs @@ -1,4 +1,4 @@ -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_07.Tests; @@ -11,9 +11,9 @@ public void Main_HospitalEmergencyCodes_DisplaysCodes() string expected = $""" info: { typeof(Program).FullName }[0] - Hospital Emergency Codes: = 'black', 'blue', 'brown', 'CBR', 'orange', 'purple', 'red', 'yellow' + 医院紧急代码: = 'black', 'blue', 'brown', 'CBR', 'orange', 'purple', 'red', 'yellow' warn: { typeof(Program).FullName }[0] - This is a test of the emergency... + 测试紧急事件... """; diff --git a/src/Chapter10.Tests/Listing10.18.RegisteringAFinalizerWithProcessExit.Tests.cs b/src/Chapter10.Tests/Listing10.18.RegisteringAFinalizerWithProcessExit.Tests.cs index 7bfed7c7..a58e9606 100644 --- a/src/Chapter10.Tests/Listing10.18.RegisteringAFinalizerWithProcessExit.Tests.cs +++ b/src/Chapter10.Tests/Listing10.18.RegisteringAFinalizerWithProcessExit.Tests.cs @@ -1,4 +1,4 @@ -using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; +using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; using System.Text.RegularExpressions; @@ -90,53 +90,53 @@ private static int RunPowerShellScript( public const string DisposeManuallyCalledExpectedOutput = """ - Main: Starting... - DoStuff: Starting... - SampleUnmanagedResource.ctor: Starting... - SampleUnmanagedResource.ctor: Creating managed stuff... - SampleUnmanagedResource.ctor: Creating unmanaged stuff... - SampleUnmanagedResource.ctor: Exiting... - Dispose: Starting... - Dispose: Disposing managed stuff... - Dispose: Disposing unmanaged stuff... - Dispose: Exiting... - DoStuff: Exiting... - Main: Exiting... + Main: 开始... + DoStuff: 开始... + SampleUnmanagedResource.ctor: 开始... + SampleUnmanagedResource.ctor: 创建托管资源... + SampleUnmanagedResource.ctor: 创建非托管资源... + SampleUnmanagedResource.ctor: 退出... + Dispose: 开始... + Dispose: 正在dispose托管资源... + Dispose: 正在dispose非托管资源... + Dispose: 退出... + DoStuff: 退出... + Main: 退出... """; public const string FinalizerRegisteredWithProcessExit = """ - Main: Starting... - DoStuff: Starting... - SampleUnmanagedResource.ctor: Starting... - SampleUnmanagedResource.ctor: Creating managed stuff... - SampleUnmanagedResource.ctor: Creating unmanaged stuff... - SampleUnmanagedResource.ctor: Exiting... - DoStuff: Exiting... - Main: Exiting... - ProcessExitHandler: Starting... - Dispose: Starting... - Dispose: Disposing managed stuff... - Dispose: Disposing unmanaged stuff... - Dispose: Exiting... - ProcessExitHandler: Exiting... + Main: 开始... + DoStuff: 开始... + SampleUnmanagedResource.ctor: 开始... + SampleUnmanagedResource.ctor: 创建托管资源... + SampleUnmanagedResource.ctor: 创建非托管资源... + SampleUnmanagedResource.ctor: 退出... + DoStuff: 退出... + Main: 退出... + ProcessExitHandler: 开始... + Dispose: 开始... + Dispose: 正在dispose托管资源... + Dispose: 正在dispose非托管资源... + Dispose: 退出... + ProcessExitHandler: 退出... """; public const string GCCalled = """ - Main: Starting... - DoStuff: Starting... - SampleUnmanagedResource.ctor: Starting... - SampleUnmanagedResource.ctor: Creating managed stuff... - SampleUnmanagedResource.ctor: Creating unmanaged stuff... - SampleUnmanagedResource.ctor: Exiting... - DoStuff: Exiting... - Finalize: Starting... - Dispose: Starting... - Dispose: Disposing unmanaged stuff... - Dispose: Exiting... - Finalize: Exiting... - Main: Exiting... + Main: 开始... + DoStuff: 开始... + SampleUnmanagedResource.ctor: 开始... + SampleUnmanagedResource.ctor: 创建托管资源... + SampleUnmanagedResource.ctor: 创建非托管资源... + SampleUnmanagedResource.ctor: 退出... + DoStuff: 退出... + Finalize: 开始... + Dispose: 开始... + Dispose: 正在dispose非托管资源... + Dispose: 退出... + Finalize: 退出... + Main: 退出... """; #if NET6_0 diff --git a/src/Chapter10.Tests/PowerShellTestUtilities.Tests.cs b/src/Chapter10.Tests/PowerShellTestUtilities.Tests.cs new file mode 100644 index 00000000..c582c940 --- /dev/null +++ b/src/Chapter10.Tests/PowerShellTestUtilities.Tests.cs @@ -0,0 +1,36 @@ +using System.Text; +using AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; + +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Tests; + +[TestClass] +public class PowerShellTestUtilitiesTests +{ + [TestMethod] + public void RunPowerShellScript_PreservesChineseOutputAndDrainsBothPipes() + { + const string greeting = "中文输出:你好,GitHub。"; + const string errorChunk = "错误流数据。"; + const int repeats = 20_000; + string scriptPath = Path.Combine(Path.GetTempPath(), $"UTF8 '{Guid.NewGuid():N}' 中文.ps1"); + try + { + File.WriteAllText(scriptPath, $""" + [Console]::WriteLine('{greeting}') + [Console]::Error.Write(('{errorChunk}' * {repeats})) + """, new UTF8Encoding(encoderShouldEmitUTF8Identifier: true)); + int exitCode = PowerShellTestUtilities.RunPowerShellScript(scriptPath, string.Empty, out string output); + Assert.AreEqual(0, exitCode); + string expectedError = string.Concat(Enumerable.Repeat(errorChunk, repeats)); + string expected = greeting + Environment.NewLine + Environment.NewLine + + "ERROR: " + Environment.NewLine + expectedError; + Assert.AreEqual(expected.Length, output.Length, "Child output was truncated or decoded incorrectly."); + Assert.IsTrue(string.Equals(expected, output, StringComparison.Ordinal), + "Chinese stdout and the stderr payload larger than the pipe buffer must be captured exactly."); + } + finally + { + File.Delete(scriptPath); + } + } +} diff --git a/src/Chapter10/Listing10.07.LeveragingADifferentLibrary.cs b/src/Chapter10/Listing10.07.LeveragingADifferentLibrary.cs index 660a5271..6b9ec7e7 100644 --- a/src/Chapter10/Listing10.07.LeveragingADifferentLibrary.cs +++ b/src/Chapter10/Listing10.07.LeveragingADifferentLibrary.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_07; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter10.Listing10_07; using Microsoft.Extensions.Logging; @@ -13,11 +13,11 @@ public static void Main(string[] args) ILogger logger = loggerFactory.CreateLogger(); - logger.LogInformation($@"ҽԺ½ô¼±´úÂë: = '{ + logger.LogInformation($@"医院紧急代码: = '{ string.Join("', '", args)}'"); // ... - logger.LogWarning("²âÊԽô¼±Ê¼þ..."); + logger.LogWarning("测试紧急事件..."); // ... } } diff --git a/src/Chapter11/Listing11.06.OverflowingAnIntegerValue.cs b/src/Chapter11/Listing11.06.OverflowingAnIntegerValue.cs index ed9ad688..cb795436 100644 --- a/src/Chapter11/Listing11.06.OverflowingAnIntegerValue.cs +++ b/src/Chapter11/Listing11.06.OverflowingAnIntegerValue.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter11.Listing11_06; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter11.Listing11_06; #region INCLUDE using System; @@ -6,7 +6,7 @@ public class Program { public static void Main() { - // int.MaxValueµÈÓÚ2147483647 + // int.MaxValue等于2147483647 int n = int.MaxValue; n = n + 1; Console.WriteLine(n); diff --git a/src/Chapter11/Listing11.07.ACheckedBlockExample.cs b/src/Chapter11/Listing11.07.ACheckedBlockExample.cs index c17edf78..ca11e367 100644 --- a/src/Chapter11/Listing11.07.ACheckedBlockExample.cs +++ b/src/Chapter11/Listing11.07.ACheckedBlockExample.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter11.Listing11_07; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter11.Listing11_07; #region INCLUDE using System; @@ -10,7 +10,7 @@ public static void Main() checked { #endregion HIGHLIGHT - // int.MaxValueµÈÓÚ2147483647 + // int.MaxValue等于2147483647 int n = int.MaxValue; n = n + 1; Console.WriteLine(n); diff --git a/src/Chapter11/Listing11.08.AnUnCheckedBlockExample.cs b/src/Chapter11/Listing11.08.AnUnCheckedBlockExample.cs index 77f89043..b46369f4 100644 --- a/src/Chapter11/Listing11.08.AnUnCheckedBlockExample.cs +++ b/src/Chapter11/Listing11.08.AnUnCheckedBlockExample.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter11.Listing11_08; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter11.Listing11_08; #region INCLUDE using System; @@ -10,7 +10,7 @@ public static void Main() unchecked { #endregion HIGHLIGHT - // int.MaxValueµÈÓÚ2147483647 + // int.MaxValue等于2147483647 int n = int.MaxValue; n = n + 1; Console.WriteLine(n); diff --git a/src/Chapter12.Tests/Listing12.15.Tests.cs b/src/Chapter12.Tests/Listing12.15.Tests.cs index 0a9058d6..795e28a1 100644 --- a/src/Chapter12.Tests/Listing12.15.Tests.cs +++ b/src/Chapter12.Tests/Listing12.15.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_15.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"1914: Shackleton leaves for South Pole on ship Endurance"; + const string expected = @"1914: 沙克尔顿乘坐“坚忍号”前往南极。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter12.Tests/Listing12.36.Tests.cs b/src/Chapter12.Tests/Listing12.36.Tests.cs index 6f8ccc9f..da309374 100644 --- a/src/Chapter12.Tests/Listing12.36.Tests.cs +++ b/src/Chapter12.Tests/Listing12.36.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_36.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - string expected = $@"490{Environment.NewLine}Fireswamp"; + string expected = $@"490{Environment.NewLine}中国"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter12.Tests/Listing12.37.Tests.cs b/src/Chapter12.Tests/Listing12.37.Tests.cs index 1faaccc4..6b8090f9 100644 --- a/src/Chapter12.Tests/Listing12.37.Tests.cs +++ b/src/Chapter12.Tests/Listing12.37.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_37.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - string expected = $@"490{Environment.NewLine}Fireswamp"; + string expected = $@"490{Environment.NewLine}中国"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter12/Listing12.07.DeclaringAGenericClassStack.cs b/src/Chapter12/Listing12.07.DeclaringAGenericClassStack.cs index 3c950bef..2869f36d 100644 --- a/src/Chapter12/Listing12.07.DeclaringAGenericClassStack.cs +++ b/src/Chapter12/Listing12.07.DeclaringAGenericClassStack.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_07; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_07; #region INCLUDE public class Stack @@ -18,7 +18,7 @@ public void Push(T data) public T Pop() { #region EXCLUDE - return InternalItems[0]; // ֻÊǾÙÀý + return InternalItems[0]; // 只是举例 #endregion EXCLUDE } } diff --git a/src/Chapter12/Listing12.15.UsingATypewithMultipleTypeParameters.cs b/src/Chapter12/Listing12.15.UsingATypewithMultipleTypeParameters.cs index ba04a4a2..218911be 100644 --- a/src/Chapter12/Listing12.15.UsingATypewithMultipleTypeParameters.cs +++ b/src/Chapter12/Listing12.15.UsingATypewithMultipleTypeParameters.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_15; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_15; using System; using Listing12_14; @@ -10,7 +10,7 @@ public static void Main() #region INCLUDE Pair historicalEvent = new(1914, - "ɳ¿˶û¶ٳË×ø¡°¼áÈ̺š±ǰÍùÄϼ«¡£"); + "沙克尔顿乘坐“坚忍号”前往南极。"); Console.WriteLine("{0}: {1}", historicalEvent.First, historicalEvent.Second); diff --git a/src/Chapter12/Listing12.34.CombiningConstraintsUsingOrRelationshipNotAllowed.cs b/src/Chapter12/Listing12.34.CombiningConstraintsUsingOrRelationshipNotAllowed.cs index d99aa32b..19184b70 100644 --- a/src/Chapter12/Listing12.34.CombiningConstraintsUsingOrRelationshipNotAllowed.cs +++ b/src/Chapter12/Listing12.34.CombiningConstraintsUsingOrRelationshipNotAllowed.cs @@ -1,8 +1,8 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_30; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter12.Listing12_30; #region INCLUDE public class BinaryTree - // ´íÎ󣺲»֧³ÖOR + // 错误:不支持OR // where T: System.IComparable || System.IFormattable { // ... diff --git a/src/Chapter13.Tests/Listing13.08.Tests.cs b/src/Chapter13.Tests/Listing13.08.Tests.cs index fa08f670..1f91e457 100644 --- a/src/Chapter13.Tests/Listing13.08.Tests.cs +++ b/src/Chapter13.Tests/Listing13.08.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_08.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Enter an integer: '' is not a valid integer."; + const string expected = @"请输入一个整数: ''不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, DelegateSample.Main); diff --git a/src/Chapter13.Tests/Listing13.11.UsingADifferentComparisonHandlerCompatibleMethod.Tests.cs b/src/Chapter13.Tests/Listing13.11.UsingADifferentComparisonHandlerCompatibleMethod.Tests.cs index 5636ec65..bb6e4459 100644 --- a/src/Chapter13.Tests/Listing13.11.UsingADifferentComparisonHandlerCompatibleMethod.Tests.cs +++ b/src/Chapter13.Tests/Listing13.11.UsingADifferentComparisonHandlerCompatibleMethod.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_11.Tests; [TestClass] @@ -8,11 +8,11 @@ public class DelegateSampleTests public void Main() { string expected = - @"Enter an integer: <<1 ->>Enter an integer: <<12 ->>Enter an integer: <<13 ->>Enter an integer: <<5 ->>Enter an integer: <<4 + @"请输入一个整数: <<1 +>>请输入一个整数: <<12 +>>请输入一个整数: <<13 +>>请输入一个整数: <<5 +>>请输入一个整数: <<4 >>1 12 13 diff --git a/src/Chapter13.Tests/Listing13.12.Tests.cs b/src/Chapter13.Tests/Listing13.12.Tests.cs index 8a7e10b8..66492d4f 100644 --- a/src/Chapter13.Tests/Listing13.12.Tests.cs +++ b/src/Chapter13.Tests/Listing13.12.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_12.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Enter an integer: '' is not a valid integer."; + const string expected = @"请输入一个整数: ''不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, DelegateSample.Main); diff --git a/src/Chapter13.Tests/Listing13.13.Tests.cs b/src/Chapter13.Tests/Listing13.13.Tests.cs index 01b84170..04c6f315 100644 --- a/src/Chapter13.Tests/Listing13.13.Tests.cs +++ b/src/Chapter13.Tests/Listing13.13.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_13.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Enter an integer: '' is not a valid integer."; + const string expected = @"请输入一个整数: ''不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter13.Tests/Listing13.16.Tests.cs b/src/Chapter13.Tests/Listing13.16.Tests.cs index 6cd1f22d..149fea8d 100644 --- a/src/Chapter13.Tests/Listing13.16.Tests.cs +++ b/src/Chapter13.Tests/Listing13.16.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_16.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Enter an integer: '' is not a valid integer."; + const string expected = @"请输入一个整数: ''不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter13.Tests/Listing13.17.Tests.cs b/src/Chapter13.Tests/Listing13.17.Tests.cs index 6feea1cd..0669ecfb 100644 --- a/src/Chapter13.Tests/Listing13.17.Tests.cs +++ b/src/Chapter13.Tests/Listing13.17.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_17.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Enter an integer: '' is not a valid integer."; + const string expected = @"请输入一个整数: ''不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter13.Tests/Listing13.19.Tests.cs b/src/Chapter13.Tests/Listing13.19.Tests.cs index fe59dd0d..cf0b03d8 100644 --- a/src/Chapter13.Tests/Listing13.19.Tests.cs +++ b/src/Chapter13.Tests/Listing13.19.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_19.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Enter an integer: '' is not a valid integer."; + const string expected = @"请输入一个整数: ''不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, DelegateSample.Main); diff --git a/src/Chapter13.Tests/Listing13.20.UsingAnOuterVariableInALambdaExpression.Tests.cs b/src/Chapter13.Tests/Listing13.20.UsingAnOuterVariableInALambdaExpression.Tests.cs index ee79b18d..d5617af0 100644 --- a/src/Chapter13.Tests/Listing13.20.UsingAnOuterVariableInALambdaExpression.Tests.cs +++ b/src/Chapter13.Tests/Listing13.20.UsingAnOuterVariableInALambdaExpression.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_20.Tests; [TestClass] @@ -8,17 +8,17 @@ public class ProgramTests public void Main() { string expected = - @"Enter an integer:<<5 ->>Enter an integer:<<1 ->>Enter an integer:<<4 ->>Enter an integer:<<2 ->>Enter an integer:<<3 + @"请输入一个整数: <<5 +>>请输入一个整数: <<1 +>>请输入一个整数: <<4 +>>请输入一个整数: <<2 +>>请输入一个整数: <<3 >>5 4 3 2 1 -Items were compared 10 times. +items被比较了10次。 "; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, diff --git a/src/Chapter13.Tests/Listing13.22.CSharpEquivalentOfCILCodeGeneratedByCompilerForOuterVariables.Tests.cs b/src/Chapter13.Tests/Listing13.22.CSharpEquivalentOfCILCodeGeneratedByCompilerForOuterVariables.Tests.cs index 7c34cadf..5d270f37 100644 --- a/src/Chapter13.Tests/Listing13.22.CSharpEquivalentOfCILCodeGeneratedByCompilerForOuterVariables.Tests.cs +++ b/src/Chapter13.Tests/Listing13.22.CSharpEquivalentOfCILCodeGeneratedByCompilerForOuterVariables.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_22.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Enter an integer: '' is not a valid integer."; + const string expected = @"请输入一个整数: ''不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter13/Listing13.26.ExamingingAnExpressionTree.cs b/src/Chapter13/Listing13.26.ExamingingAnExpressionTree.cs index 6eebdb97..94925047 100644 --- a/src/Chapter13/Listing13.26.ExamingingAnExpressionTree.cs +++ b/src/Chapter13/Listing13.26.ExamingingAnExpressionTree.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_26; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter13.Listing13_26; #region INCLUDE using System; @@ -47,7 +47,7 @@ private static void PrintSingle( private static string NodeToString(Expression expression) => expression.NodeType switch { - // ʹÓþ²̬ExpressionType + // 使用静态ExpressionType Multiply => "*", Add => "+", Divide => "/", diff --git a/src/Chapter14.Tests/Listing14.03.ConnectingThePublisherAndSubscribers.Tests.cs b/src/Chapter14.Tests/Listing14.03.ConnectingThePublisherAndSubscribers.Tests.cs index 6f05fbab..384fa612 100644 --- a/src/Chapter14.Tests/Listing14.03.ConnectingThePublisherAndSubscribers.Tests.cs +++ b/src/Chapter14.Tests/Listing14.03.ConnectingThePublisherAndSubscribers.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_03.Tests; @@ -8,7 +8,7 @@ public class ProgramTests [TestMethod] public void ConnectingPublisherAndSubscribers() { - string expected = @"Enter temperature: <<1"; + string expected = @"输入温度: <<1"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => diff --git a/src/Chapter14.Tests/Listing14.04.InvokingADelegateWithoutCheckingForNull.Tests.cs b/src/Chapter14.Tests/Listing14.04.InvokingADelegateWithoutCheckingForNull.Tests.cs index 65ffbbb8..090fe289 100644 --- a/src/Chapter14.Tests/Listing14.04.InvokingADelegateWithoutCheckingForNull.Tests.cs +++ b/src/Chapter14.Tests/Listing14.04.InvokingADelegateWithoutCheckingForNull.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_04.Tests; using Listing14_04; @@ -9,8 +9,8 @@ public class ProgramTests [TestMethod] public void InvokingDelegateWithoutCheckingForNull() { - string expected = @"Enter temperature: <<1>>Heater: On -Cooler: Off"; + string expected = @"输入温度: <<1>>加热器: On +冷却器: Off"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => diff --git a/src/Chapter14.Tests/Listing14.06.UsingthePlusEqualsAndMinusEqualsDelegateOperators.Tests.cs b/src/Chapter14.Tests/Listing14.06.UsingthePlusEqualsAndMinusEqualsDelegateOperators.Tests.cs index d8eca6b7..6144650a 100644 --- a/src/Chapter14.Tests/Listing14.06.UsingthePlusEqualsAndMinusEqualsDelegateOperators.Tests.cs +++ b/src/Chapter14.Tests/Listing14.06.UsingthePlusEqualsAndMinusEqualsDelegateOperators.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_06.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - string expected = $@"Invoke both delegates:{Environment.NewLine}Heater: Off{Environment.NewLine}Cooler: On{Environment.NewLine}Invoke only delegate2{Environment.NewLine}Cooler: Off"; + string expected = $@"同时调用两个委托:{Environment.NewLine}加热器: Off{Environment.NewLine}冷却器: On{Environment.NewLine}只调用delegate2{Environment.NewLine}冷却器: Off"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter14.Tests/Listing14.07.UsingThePlusAndMinusDelegateOperators.Tests.cs b/src/Chapter14.Tests/Listing14.07.UsingThePlusAndMinusDelegateOperators.Tests.cs index d0ac1614..2652ac43 100644 --- a/src/Chapter14.Tests/Listing14.07.UsingThePlusAndMinusDelegateOperators.Tests.cs +++ b/src/Chapter14.Tests/Listing14.07.UsingThePlusAndMinusDelegateOperators.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_07.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - string expected = $@"Combine delegates using + operator:{Environment.NewLine}Heater: Off{Environment.NewLine}Cooler: Off{Environment.NewLine}Uncombine delegates using - operator:{Environment.NewLine}Heater: Off"; + string expected = $@"使用+操作符合并委托:{Environment.NewLine}加热器: Off{Environment.NewLine}冷却器: Off{Environment.NewLine}使用-操作符取消合并委托:{Environment.NewLine}加热器: Off"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter14.Tests/Listing14.08.OnTemperatureChangedThrowingAnException.Tests.cs b/src/Chapter14.Tests/Listing14.08.OnTemperatureChangedThrowingAnException.Tests.cs index d60249d3..a4c12fb0 100644 --- a/src/Chapter14.Tests/Listing14.08.OnTemperatureChangedThrowingAnException.Tests.cs +++ b/src/Chapter14.Tests/Listing14.08.OnTemperatureChangedThrowingAnException.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_08.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Enter temperature: '' is not a valid integer."; + const string expected = @"输入温度: '' 不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter14.Tests/Listing14.09.HandlingExceptionsFromSubscribers.Tests.cs b/src/Chapter14.Tests/Listing14.09.HandlingExceptionsFromSubscribers.Tests.cs index 3785c2d7..e549564a 100644 --- a/src/Chapter14.Tests/Listing14.09.HandlingExceptionsFromSubscribers.Tests.cs +++ b/src/Chapter14.Tests/Listing14.09.HandlingExceptionsFromSubscribers.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_09.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Enter temperature: '' is not a valid integer."; + const string expected = @"输入温度: '' 不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter14.Tests/Listing14.10.UsingTheAssignmentOperationRatherThanPlusEquals.Tests.cs b/src/Chapter14.Tests/Listing14.10.UsingTheAssignmentOperationRatherThanPlusEquals.Tests.cs index 2cd39975..a1d72a4c 100644 --- a/src/Chapter14.Tests/Listing14.10.UsingTheAssignmentOperationRatherThanPlusEquals.Tests.cs +++ b/src/Chapter14.Tests/Listing14.10.UsingTheAssignmentOperationRatherThanPlusEquals.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter14.Listing14_10.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Enter temperature: '' is not a valid integer."; + const string expected = @"输入温度: '' 不是一个有效的整数。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15.Tests/Listing15.01.Tests.cs b/src/Chapter15.Tests/Listing15.01.Tests.cs index 9280cfc4..5ecd7d2e 100644 --- a/src/Chapter15.Tests/Listing15.01.Tests.cs +++ b/src/Chapter15.Tests/Listing15.01.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_01.Tests; [TestClass] @@ -7,13 +7,13 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Wealth without work -Pleasure without conscience -Knowledge without character -Commerce without morality -Science without humanity -Worship without sacrifice -Politics without principle"; + const string expected = @"没有辛劳的财富 +没有良心的享乐 +没有品格的知识 +没有道德的商业 +没有人性的科学 +没有牺牲的崇拜 +没有原则的政治"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15.Tests/Listing15.09.Tests.cs b/src/Chapter15.Tests/Listing15.09.Tests.cs index fe5081a1..60f36812 100644 --- a/src/Chapter15.Tests/Listing15.09.Tests.cs +++ b/src/Chapter15.Tests/Listing15.09.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_09.Tests; [TestClass] @@ -7,22 +7,22 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Bifocals (1784) -Phonograph (1877) -Kinetoscope (1888) -Electrical Telegraph (1837) -Flying Machine (1903) -Steam Locomotive (1815) -Droplet Deposition Apparatus (1989) -Backless Brassiere (1914) + const string expected = @"双焦点眼镜 (1784) +留声机 (1877) +活动电影机 (1888) +电报 (1837) +飞机 (1903) +蒸汽机车 (1815) +液滴沉积装置 (1989) +无背式胸罩 (1914) -Benjamin Franklin (Philadelphia, PA) -Orville Wright (Kitty Hawk, NC) -Wilbur Wright (Kitty Hawk, NC) -Samuel Morse (New York, NY) -George Stephenson (Wylam, Northumberland) -John Michaelis (Chicago, IL) -Mary Phelps Jacob (New York, NY)"; +本杰明·富兰克林 (费城, PA) +奥维尔·莱特 (基蒂霍克, NC) +威尔伯·莱特 (基蒂霍克, NC) +塞缪尔·莫尔斯 (纽约, NY) +乔治·斯蒂芬森 (怀拉姆, 诺森伯兰) +约翰·迈克利斯 (芝加哥, IL) +玛丽·菲尔普斯·雅各布 (纽约, NY)"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15.Tests/Listing15.10.FilteringWithSystem.Linq.Enumerable.Where.Tests.cs b/src/Chapter15.Tests/Listing15.10.FilteringWithSystem.Linq.Enumerable.Where.Tests.cs index a183cdad..de9fa8ac 100644 --- a/src/Chapter15.Tests/Listing15.10.FilteringWithSystem.Linq.Enumerable.Where.Tests.cs +++ b/src/Chapter15.Tests/Listing15.10.FilteringWithSystem.Linq.Enumerable.Where.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_10.Tests; [TestClass] @@ -8,10 +8,10 @@ public class ProgramTests public void FilteringWithSystem_Linq_Enumerable_Where() { string expected = -@"Phonograph (1877) -Kinetoscope (1888) -Electrical Telegraph (1837) -Steam Locomotive (1815)"; +@"留声机 (1877) +活动电影机 (1888) +电报 (1837) +蒸汽机车 (1815)"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => diff --git a/src/Chapter15.Tests/Listing15.11.Tests.cs b/src/Chapter15.Tests/Listing15.11.Tests.cs index 2f8a299a..998b3723 100644 --- a/src/Chapter15.Tests/Listing15.11.Tests.cs +++ b/src/Chapter15.Tests/Listing15.11.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_11.Tests; [TestClass] @@ -7,10 +7,10 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Phonograph (1877) -Kinetoscope (1888) -Electrical Telegraph (1837) -Steam Locomotive (1815)"; + const string expected = @"留声机 (1877) +活动电影机 (1888) +电报 (1837) +蒸汽机车 (1815)"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15.Tests/Listing15.15.Tests.cs b/src/Chapter15.Tests/Listing15.15.Tests.cs index 3ff6d2aa..4fdebaf2 100644 --- a/src/Chapter15.Tests/Listing15.15.Tests.cs +++ b/src/Chapter15.Tests/Listing15.15.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_15.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - string expected = $@"Patent Count: 8{Environment.NewLine}Patent Count in 1800s: 4"; + string expected = $@"专利数量: 8{Environment.NewLine}19世纪专利数量: 4"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15.Tests/Listing15.16.Tests.cs b/src/Chapter15.Tests/Listing15.16.Tests.cs index 815c506b..46ad1e30 100644 --- a/src/Chapter15.Tests/Listing15.16.Tests.cs +++ b/src/Chapter15.Tests/Listing15.16.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_16.Tests; [TestClass] @@ -7,25 +7,25 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"1. Patents prior to the 1900s are: - Phonograph (1877) - Kinetoscope (1888) - Electrical Telegraph (1837) - Steam Locomotive (1815) + const string expected = @"1. 20世纪之前的专利清单之一: + 留声机 (1877) + 活动电影机 (1888) + 电报 (1837) + 蒸汽机车 (1815) -2. A second listing of patents prior to the 1900s: - Phonograph (1877) - Kinetoscope (1888) - Electrical Telegraph (1837) - Steam Locomotive (1815) - There are 4 patents prior to 1900. +2. 20世纪之前的专利清单之二: + 留声机 (1877) + 活动电影机 (1888) + 电报 (1837) + 蒸汽机车 (1815) + 20世纪之前总共有4个专利。 -3. A third listing of patents prior to the 1900s: - Phonograph (1877) - Kinetoscope (1888) - Electrical Telegraph (1837) - Steam Locomotive (1815) - There are 4 patents prior to 1900."; +3. 18世纪之前的专利清单之三: + 留声机 (1877) + 活动电影机 (1888) + 电报 (1837) + 蒸汽机车 (1815) + 20世纪之前总共有4个专利。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15.Tests/Listing15.17.Tests.cs b/src/Chapter15.Tests/Listing15.17.Tests.cs index 9c5d053a..3fbfd8f1 100644 --- a/src/Chapter15.Tests/Listing15.17.Tests.cs +++ b/src/Chapter15.Tests/Listing15.17.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_17.Tests; [TestClass] @@ -7,23 +7,23 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Bifocals (1784) -Steam Locomotive (1815) -Electrical Telegraph (1837) -Phonograph (1877) -Kinetoscope (1888) -Flying Machine (1903) -Backless Brassiere (1914) -Droplet Deposition Apparatus (1989) + const string expected = @"双焦点眼镜 (1784) +蒸汽机车 (1815) +电报 (1837) +留声机 (1877) +活动电影机 (1888) +飞机 (1903) +无背式胸罩 (1914) +液滴沉积装置 (1989) -Droplet Deposition Apparatus (1989) -Backless Brassiere (1914) -Flying Machine (1903) -Kinetoscope (1888) -Phonograph (1877) -Electrical Telegraph (1837) -Steam Locomotive (1815) -Bifocals (1784)"; +液滴沉积装置 (1989) +无背式胸罩 (1914) +飞机 (1903) +活动电影机 (1888) +留声机 (1877) +电报 (1837) +蒸汽机车 (1815) +双焦点眼镜 (1784)"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15.Tests/Listing15.18.Tests.cs b/src/Chapter15.Tests/Listing15.18.Tests.cs index a87b3960..09f9c2f8 100644 --- a/src/Chapter15.Tests/Listing15.18.Tests.cs +++ b/src/Chapter15.Tests/Listing15.18.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_18.Tests; [TestClass] @@ -8,20 +8,20 @@ public class ProgramTests public void MainTest() { const string expected = @"Corporate -Human Resources -Engineering -Information Technology -Philanthropy -Marketing +人力资源 +工程 +IT +慈善 +市场 -Mark Michaelis (Chief 电脑发烧友) -Michael Stokesbary (Senior Computer Wizard) -Brian Jones (Enterprise Integration Guru) -Anne Beard (HR Director) -Pat Dever (Enterprise Architect) -Kevin Bost (Programmer Extraordinaire) -Thomas Heavey (Software Architect) -Eric Edmonds (Philanthropy Coordinator)"; +Mark Michaelis (首席电脑发烧友) +Michael Stokesbary (高级电脑巫师) +Brian Jones (企业集成大师) +Anne Beard (人力资源总监) +Pat Dever (企业架构师) +Kevin Bost (杰出程序员) +Thomas Heavey (软件架构师) +Eric Edmonds (慈善协调员)"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15.Tests/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.Tests.cs b/src/Chapter15.Tests/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.Tests.cs index 5f505700..ac78bfe9 100644 --- a/src/Chapter15.Tests/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.Tests.cs +++ b/src/Chapter15.Tests/Listing15.19.AnInnerJoinUsingSystem.Linq.Enumerable.Join.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_19.Tests; [TestClass] @@ -8,22 +8,22 @@ public class ProgramTests public void EnumerableJoinTest() { string expected = -@"Mark Michaelis (Chief µçÄԷ¢ÉÕÓÑ) +@"Mark Michaelis (首席电脑发烧友) Corporate -Michael Stokesbary (Senior Computer Wizard) - Engineering -Brian Jones (Enterprise Integration Guru) - Engineering -Anne Beard (HR Director) - Human Resources -Pat Dever (Enterprise Architect) - Information Technology -Kevin Bost (Programmer Extraordinaire) - Engineering -Thomas Heavey (Software Architect) - Engineering -Eric Edmonds (Philanthropy Coordinator) - Philanthropy"; +Michael Stokesbary (高级电脑巫师) + 工程 +Brian Jones (企业集成大师) + 工程 +Anne Beard (人力资源总监) + 人力资源 +Pat Dever (企业架构师) + IT +Kevin Bost (杰出程序员) + 工程 +Thomas Heavey (软件架构师) + 工程 +Eric Edmonds (慈善协调员) + 慈善"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => diff --git a/src/Chapter15.Tests/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.Tests.cs b/src/Chapter15.Tests/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.Tests.cs index 7ebe9d0f..9a66c1a8 100644 --- a/src/Chapter15.Tests/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.Tests.cs +++ b/src/Chapter15.Tests/Listing15.20.AnotherInnerJoinWithSystem.Linq.Enumerable.Join.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_20.Tests; [TestClass] @@ -9,21 +9,21 @@ public void EnumerableJoinTest() { string expected = @"Corporate - Mark Michaelis (Chief µçÄԷ¢ÉÕÓÑ) -Human Resources - Anne Beard (HR Director) -Engineering - Michael Stokesbary (Senior Computer Wizard) -Engineering - Brian Jones (Enterprise Integration Guru) -Engineering - Kevin Bost (Programmer Extraordinaire) -Engineering - Thomas Heavey (Software Architect) -Information Technology - Pat Dever (Enterprise Architect) -Philanthropy - Eric Edmonds (Philanthropy Coordinator)"; + Mark Michaelis (首席电脑发烧友) +人力资源 + Anne Beard (人力资源总监) +工程 + Michael Stokesbary (高级电脑巫师) +工程 + Brian Jones (企业集成大师) +工程 + Kevin Bost (杰出程序员) +工程 + Thomas Heavey (软件架构师) +IT + Pat Dever (企业架构师) +慈善 + Eric Edmonds (慈善协调员)"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => diff --git a/src/Chapter15.Tests/Listing15.21.Tests.cs b/src/Chapter15.Tests/Listing15.21.Tests.cs index b6899cbd..f013873b 100644 --- a/src/Chapter15.Tests/Listing15.21.Tests.cs +++ b/src/Chapter15.Tests/Listing15.21.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_21.Tests; [TestClass] @@ -8,23 +8,23 @@ public class ProgramTests public void MainTest() { const string expected = @" -Mark Michaelis (Chief 电脑发烧友) - Count: 1 +Mark Michaelis (首席电脑发烧友) + 计数: 1 -Michael Stokesbary (Senior Computer Wizard) -Brian Jones (Enterprise Integration Guru) -Kevin Bost (Programmer Extraordinaire) -Thomas Heavey (Software Architect) - Count: 4 +Michael Stokesbary (高级电脑巫师) +Brian Jones (企业集成大师) +Kevin Bost (杰出程序员) +Thomas Heavey (软件架构师) + 计数: 4 -Anne Beard (HR Director) - Count: 1 +Anne Beard (人力资源总监) + 计数: 1 -Pat Dever (Enterprise Architect) - Count: 1 +Pat Dever (企业架构师) + 计数: 1 -Eric Edmonds (Philanthropy Coordinator) - Count: 1"; +Eric Edmonds (慈善协调员) + 计数: 1"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15.Tests/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.Tests.cs b/src/Chapter15.Tests/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.Tests.cs index 31af9e2a..23ea9a4f 100644 --- a/src/Chapter15.Tests/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.Tests.cs +++ b/src/Chapter15.Tests/Listing15.22.CreatingAChildCollectionWithSystem.Linq.Enumerable.GroupJoin.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_22.Tests; [TestClass] @@ -9,19 +9,19 @@ public void EnumerableGroupJoinTest() { string expected = @"Corporate - Mark Michaelis (Chief µçÄԷ¢ÉÕÓÑ) -Human Resources - Anne Beard (HR Director) -Engineering - Michael Stokesbary (Senior Computer Wizard) - Brian Jones (Enterprise Integration Guru) - Kevin Bost (Programmer Extraordinaire) - Thomas Heavey (Software Architect) -Information Technology - Pat Dever (Enterprise Architect) -Philanthropy - Eric Edmonds (Philanthropy Coordinator) -Marketing"; + Mark Michaelis (首席电脑发烧友) +人力资源 + Anne Beard (人力资源总监) +工程 + Michael Stokesbary (高级电脑巫师) + Brian Jones (企业集成大师) + Kevin Bost (杰出程序员) + Thomas Heavey (软件架构师) +IT + Pat Dever (企业架构师) +慈善 + Eric Edmonds (慈善协调员) +市场"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => diff --git a/src/Chapter15.Tests/Listing15.23.Tests.cs b/src/Chapter15.Tests/Listing15.23.Tests.cs index 52f1e7c3..140ca448 100644 --- a/src/Chapter15.Tests/Listing15.23.Tests.cs +++ b/src/Chapter15.Tests/Listing15.23.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_23.Tests; [TestClass] @@ -8,19 +8,19 @@ public class ProgramTests public void MainTest() { const string expected = @"Corporate - Mark Michaelis (Chief 电脑发烧友) -Human Resources - Anne Beard (HR Director) -Engineering - Michael Stokesbary (Senior Computer Wizard) - Brian Jones (Enterprise Integration Guru) - Kevin Bost (Programmer Extraordinaire) - Thomas Heavey (Software Architect) -Information Technology - Pat Dever (Enterprise Architect) -Philanthropy - Eric Edmonds (Philanthropy Coordinator) -Marketing"; + Mark Michaelis (首席电脑发烧友) +人力资源 + Anne Beard (人力资源总监) +工程 + Michael Stokesbary (高级电脑巫师) + Brian Jones (企业集成大师) + Kevin Bost (杰出程序员) + Thomas Heavey (软件架构师) +IT + Pat Dever (企业架构师) +慈善 + Eric Edmonds (慈善协调员) +市场"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15.Tests/Listing15.25.MoreSystem.Linq.EnumerableMethodCalls.Tests.cs b/src/Chapter15.Tests/Listing15.25.MoreSystem.Linq.EnumerableMethodCalls.Tests.cs index fe8b6754..7cad2aac 100644 --- a/src/Chapter15.Tests/Listing15.25.MoreSystem.Linq.EnumerableMethodCalls.Tests.cs +++ b/src/Chapter15.Tests/Listing15.25.MoreSystem.Linq.EnumerableMethodCalls.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_25.Tests; [TestClass] @@ -8,20 +8,20 @@ public class ProgramTests public void MoreEnumerableMethodCalls() { string expected = -$@"Stuff: System.Object, 1, 3, 5, 7, 9, ""thing"", ????????-????-????-????-???????????? -Even integers: 0, 2, 4, 6, 8 -Odd integers: 1, 3, 5, 7, 9 -Union of odd and even: 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 -Union with even: 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 -Concat with odd: 0, 2, 4, 6, 8, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9 -Intersection with even: 0, 2, 4, 6, 8 -Distinct: 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 +$@"杂物: System.Object, 1, 3, 5, 7, 9, ""东西"", ????????-????-????-????-???????????? +偶数: 0, 2, 4, 6, 8 +奇数: 1, 3, 5, 7, 9 +奇数和偶数的并集: 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 +与偶数的并集: 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 +与奇数合并成超集: 0, 2, 4, 6, 8, 1, 3, 5, 7, 9, 1, 3, 5, 7, 9 +与偶数的交集: 0, 2, 4, 6, 8 +去重: 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 Collection ""SequenceEquals"" numbers.Concat(odd).Distinct()) -Reverse: 9, 7, 5, 3, 1, 8, 6, 4, 2, 0 -Average: {4.5} -Sum: 45 -Max: 9 -Min: 0"; +反转: 9, 7, 5, 3, 1, 8, 6, 4, 2, 0 +平均: {4.5} +总和: 45 +最大: 9 +最小: 0"; IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike(expected, () => diff --git a/src/Chapter15.Tests/Listing15.26.ImplicitLocalVariablesWithAnonymousTypes.Tests.cs b/src/Chapter15.Tests/Listing15.26.ImplicitLocalVariablesWithAnonymousTypes.Tests.cs index cbe16db8..4b75a5a6 100644 --- a/src/Chapter15.Tests/Listing15.26.ImplicitLocalVariablesWithAnonymousTypes.Tests.cs +++ b/src/Chapter15.Tests/Listing15.26.ImplicitLocalVariablesWithAnonymousTypes.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_26.Tests; [TestClass] @@ -7,13 +7,13 @@ public class ProgramTests [TestMethod] public void DictionaryInitialization() { - string expected = @"Bifocals (1784) -Phonograph (1877) + string expected = @"双焦点眼镜 (1784) +留声机 (1877) -{ Title = Bifocals, YearOfPublication = 1784 } -{ Title = Phonograph, YearOfPublication = 1877 } +{ Title = 双焦点眼镜, YearOfPublication = 1784 } +{ Title = 留声机, YearOfPublication = 1877 } -{ Title = Bifocals, Year = 1784 }"; +{ Title = 双焦点眼镜, Year = 1784 }"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => diff --git a/src/Chapter15.Tests/Listing15.29.Tests.cs b/src/Chapter15.Tests/Listing15.29.Tests.cs index 4a0c2bec..ce87e405 100644 --- a/src/Chapter15.Tests/Listing15.29.Tests.cs +++ b/src/Chapter15.Tests/Listing15.29.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_29.Tests; [TestClass] @@ -7,8 +7,8 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"{ TeamName = France, Players = System.String[] } -{ TeamName = Italy, Players = System.String[] }"; + const string expected = @"{ TeamName = 法国, Players = System.String[] } +{ TeamName = 意大利, Players = System.String[] }"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter15/Listing15.21.GroupingItemsTogetherUsingSystem.Linq.Enumerable.GroupBy.cs b/src/Chapter15/Listing15.21.GroupingItemsTogetherUsingSystem.Linq.Enumerable.GroupBy.cs index 2d885fda..b3d73759 100644 --- a/src/Chapter15/Listing15.21.GroupingItemsTogetherUsingSystem.Linq.Enumerable.GroupBy.cs +++ b/src/Chapter15/Listing15.21.GroupingItemsTogetherUsingSystem.Linq.Enumerable.GroupBy.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_21; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15_21; using AddisonWesley.Michaelis.EssentialCSharp.Chapter15.Listing15; #region INCLUDE @@ -25,7 +25,7 @@ public static void Main() Console.WriteLine(employee); } Console.WriteLine( - "\t¼ÆÊý: " + employeeGroup.Count()); + "\t计数: " + employeeGroup.Count()); } //... #endregion INCLUDE diff --git a/src/Chapter16.Tests/Listing16.04.Tests.cs b/src/Chapter16.Tests/Listing16.04.Tests.cs index 452269d1..5afeff18 100644 --- a/src/Chapter16.Tests/Listing16.04.Tests.cs +++ b/src/Chapter16.Tests/Listing16.04.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16_04.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void InvokingDelegateWithoutCheckingForNull() { - string expected = @"Query created. + string expected = @"已创建查询。 add* alias* ascending* async* await* by* descending* dynamic* equals* from* get* global* group* into* join* let* nameof* nonnull* on* orderby* partial* remove* select* set* value* var* when* where* yield*"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, diff --git a/src/Chapter16.Tests/Listing16.05.Tests.cs b/src/Chapter16.Tests/Listing16.05.Tests.cs index 5cb1861f..ed94ac3f 100644 --- a/src/Chapter16.Tests/Listing16.05.Tests.cs +++ b/src/Chapter16.Tests/Listing16.05.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16_05.Tests; [TestClass] @@ -8,12 +8,12 @@ public class ProgramTests public void InvokingDelegateWithoutCheckingForNull() { string expected = @"1. delegateInvocations=0 -2. Contextual keyword count=29 +2. 上下文关键字数量=29 3. delegateInvocations=29 -4. Contextual keyword count=29 +4. 上下文关键字数量=29 5. delegateInvocations=58 6. delegateInvocations=87 -7. selectionCache count=29 +7. selectionCache数量=29 8. delegateInvocations=87"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, diff --git a/src/Chapter16.Tests/Listing16.10.Tests.cs b/src/Chapter16.Tests/Listing16.10.Tests.cs index 0693cf3a..1f0eb8d5 100644 --- a/src/Chapter16.Tests/Listing16.10.Tests.cs +++ b/src/Chapter16.Tests/Listing16.10.Tests.cs @@ -1,4 +1,4 @@ -using AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16.Tests; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16.Tests; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16_10.Tests; @@ -9,9 +9,9 @@ public class ProgramTests public void InvokingDelegateWithoutCheckingForNull() { string expected = $@" -Keywords: +关键字: { CSharpExpectedData.ExpectedKeywords } -Contextual Keywords: +上下文关键字: { CSharpExpectedData.ExpectedContextualKeywords }"; diff --git a/src/Chapter16.Tests/Listing16.11.Tests.cs b/src/Chapter16.Tests/Listing16.11.Tests.cs index c7550dc5..9867c175 100644 --- a/src/Chapter16.Tests/Listing16.11.Tests.cs +++ b/src/Chapter16.Tests/Listing16.11.Tests.cs @@ -1,4 +1,4 @@ -using AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16.Tests; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16.Tests; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16_11.Tests; @@ -13,9 +13,9 @@ public void SelectingFollowingGroupClause_UsingTuple() public static void SelectingFollowingGroupClause(Action _) { string expected = $@" -Keywords: +关键字: { CSharpExpectedData.ExpectedKeywords } -Contextual Keywords: +上下文关键字: { CSharpExpectedData.ExpectedContextualKeywords }"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, diff --git a/src/Chapter16.Tests/Listing16.12.Tests.cs b/src/Chapter16.Tests/Listing16.12.Tests.cs index 04b3599c..925b6f8a 100644 --- a/src/Chapter16.Tests/Listing16.12.Tests.cs +++ b/src/Chapter16.Tests/Listing16.12.Tests.cs @@ -1,4 +1,4 @@ -using AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16.Tests; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16.Tests; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter16.Listing16_12.Tests; @@ -14,9 +14,9 @@ public void SelectingFollowingGroupClause_UsingTuple() public static void SelectingFollowingGroupClause(Action _) { string expected = $@" -Keywords: +关键字: { CSharpExpectedData.ExpectedKeywords } -Contextual Keywords: +上下文关键字: { CSharpExpectedData.ExpectedContextualKeywords }"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, diff --git a/src/Chapter17.Tests/Listing17.01.UsingList.Tests.cs b/src/Chapter17.Tests/Listing17.01.UsingList.Tests.cs index b76962e6..6056c1c8 100644 --- a/src/Chapter17.Tests/Listing17.01.UsingList.Tests.cs +++ b/src/Chapter17.Tests/Listing17.01.UsingList.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_01.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void UsingListOfT() { const string expected = - "In alphabetical order Bashful is the first dwarf while Sneezy is the last."; + "按字母顺序,Bashful是第一个小矮人,而Sneezy是最后一个。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter17/Listing17.18.UsingForeachWithBinaryTree.cs b/src/Chapter17/Listing17.18.UsingForeachWithBinaryTree.cs index ba7db4b1..afafea30 100644 --- a/src/Chapter17/Listing17.18.UsingForeachWithBinaryTree.cs +++ b/src/Chapter17/Listing17.18.UsingForeachWithBinaryTree.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_18; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_18; using System; using Listing17_15; @@ -9,21 +9,21 @@ public class Program public static void Main() { #region INCLUDE - // JFK(¿ÏÄáµÏ)¼Ò×å×åÆ× + // JFK(肯尼迪)家族族谱 var jfkFamilyTree = new BinaryTree( "John Fitzgerald Kennedy") { SubItems = new Pair>( new BinaryTree("Joseph Patrick Kennedy") { - // ×游ĸ£¨¸¸Ç×ÄDZߣ© + // 祖父母(父亲那边) SubItems = new Pair>( new BinaryTree("Patrick Joseph Kennedy"), new BinaryTree("Mary Augusta Hickey")) }, new BinaryTree("Rose Elizabeth Fitzgerald") { - // Íâ×游ĸ£¨ĸÇ×ÄDZß + // 外祖父母(母亲那边 SubItems = new Pair>( new BinaryTree("John Francis Fitzgerald"), new BinaryTree("Mary Josephine Hannon")) diff --git a/src/Chapter17/Listing17.20.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs b/src/Chapter17/Listing17.20.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs index 7d71cba4..ab718d24 100644 --- a/src/Chapter17/Listing17.20.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs +++ b/src/Chapter17/Listing17.20.CSharpEquivalentOfCompilerGeneratedCodeForIterators.cs @@ -1,4 +1,4 @@ -using AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_11; +using AddisonWesley.Michaelis.EssentialCSharp.Chapter17.Listing17_11; #region INCLUDE using System; using System.Collections; @@ -34,7 +34,7 @@ public T this[PairItem index] { throw new NotImplementedException( string.Format( - "ÉÐδʵÏÖ{0}ö¾Ù", + "尚未实现{0}枚举", index.ToString())); } result = Second; diff --git a/src/Chapter18.Tests/Listing18.03.Tests.cs b/src/Chapter18.Tests/Listing18.03.Tests.cs index 1f91407a..e3210dc6 100644 --- a/src/Chapter18.Tests/Listing18.03.Tests.cs +++ b/src/Chapter18.Tests/Listing18.03.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_03.Tests; [TestClass] @@ -19,7 +19,7 @@ public void Main_WithNoParameters_DisplaysHelp() [TestMethod] public void Main_NormalCompression_Succes() { - string expected = @"Running testhost.dll /Out:output.dat /Priority:High"; + string expected = @"正在运行testhost.dll /Out:output.dat /Priority:High"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => { @@ -30,7 +30,7 @@ public void Main_NormalCompression_Succes() [TestMethod] public void Main_InvalidCompression_Succes() { - string expected = @"The option 'Invalid' is invalid for 'Priority' + string expected = @"选项'Invalid'对'Priority'无效。 Compress.exe /Out:< 文件名 > /Help /Priority:RealTime | High | AboveNormal | Normal | BelowNormal | Idle"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => diff --git a/src/Chapter18.Tests/Listing18.05.Tests.cs b/src/Chapter18.Tests/Listing18.05.Tests.cs index 1a632fb6..54f6c56f 100644 --- a/src/Chapter18.Tests/Listing18.05.Tests.cs +++ b/src/Chapter18.Tests/Listing18.05.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_05.Tests; [TestClass] @@ -7,10 +7,10 @@ public class ProgramTests [TestMethod] public void Main_WithNoParameters_DisplaysHelp() { - string expected = @"True -True -False -True"; + string expected = @"System.Nullable<>是否包含泛型参数:True +System.Nullable<>是否泛型类型:True +System.Nullable是否包含泛型参数:False +System.Nullable是否泛型类型:True"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => { diff --git a/src/Chapter18.Tests/Listing18.06.Tests.cs b/src/Chapter18.Tests/Listing18.06.Tests.cs index e2bc645a..f5a34631 100644 --- a/src/Chapter18.Tests/Listing18.06.Tests.cs +++ b/src/Chapter18.Tests/Listing18.06.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_06.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Type parameter: System.Int32"; + const string expected = @"类型参数: System.Int32"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter18.Tests/Listing18.24.UsingConditionalAttributeToEliminateACall.Tests.cs b/src/Chapter18.Tests/Listing18.24.UsingConditionalAttributeToEliminateACall.Tests.cs index 3fe4f1c3..06b4784e 100644 --- a/src/Chapter18.Tests/Listing18.24.UsingConditionalAttributeToEliminateACall.Tests.cs +++ b/src/Chapter18.Tests/Listing18.24.UsingConditionalAttributeToEliminateACall.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_24.Tests; [TestClass] @@ -7,9 +7,9 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Begin... -MethodA() executing... -End..."; + const string expected = @"开始... +MethodA()正在执行... +结束..."; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter18.Tests/Listing18.29.DynamicProgrammingUsingReflection.Tests.cs b/src/Chapter18.Tests/Listing18.29.DynamicProgrammingUsingReflection.Tests.cs index 61235953..3c76f43b 100644 --- a/src/Chapter18.Tests/Listing18.29.DynamicProgrammingUsingReflection.Tests.cs +++ b/src/Chapter18.Tests/Listing18.29.DynamicProgrammingUsingReflection.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter18.Listing18_29.Tests; [TestClass] @@ -8,7 +8,7 @@ public class ProgramTests public void MainTest() { string expected = $@"Hello! My name is Inigo Montoya -{140.6} makes for a long triathlon."; +{140.6}英里,这是长途铁人三项的总里程。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter18/Chapter18.csproj b/src/Chapter18/Chapter18.csproj index 77b6c716..c68b63fa 100644 --- a/src/Chapter18/Chapter18.csproj +++ b/src/Chapter18/Chapter18.csproj @@ -1,11 +1,11 @@ - + 18 $(ExpectedWarnings),CS0612 - + $(IgnoredWarnings),CA1018 diff --git a/src/Chapter19.Tests/Listing19.03.Test.cs b/src/Chapter19.Tests/Listing19.03.Test.cs index 7ced3c5b..322c9e08 100644 --- a/src/Chapter19.Tests/Listing19.03.Test.cs +++ b/src/Chapter19.Tests/Listing19.03.Test.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_03.Tests; [TestClass] @@ -7,12 +7,12 @@ public class ProgramTests [TestMethod] public void ObservingUnhandledExceptionsWithContinueWith() { - string expected = @"Before -Starting... -Continuing A... -Continuing {0}... -Continuing {1}... -Finished!"; + string expected = @"开始之前 +开始... +继续A... +继续{0}... +继续{1}... +结束!"; string actual = IntelliTect.TestTools.Console.ConsoleAssert.Execute(expected, () => { diff --git a/src/Chapter19.Tests/Listing19.04.Test.cs b/src/Chapter19.Tests/Listing19.04.Test.cs index c36718a8..a4852a76 100644 --- a/src/Chapter19.Tests/Listing19.04.Test.cs +++ b/src/Chapter19.Tests/Listing19.04.Test.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_04.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void ObservingUnhandledExceptionsWithContinueWith() { - string expected = "Task State: Completed"; + string expected = "任务状态: Completed"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => diff --git a/src/Chapter19.Tests/Listing19.05.Tests.cs b/src/Chapter19.Tests/Listing19.05.Tests.cs index 746aba61..af5d9e56 100644 --- a/src/Chapter19.Tests/Listing19.05.Tests.cs +++ b/src/Chapter19.Tests/Listing19.05.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_05.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void ObservingUnhandledExceptionsWithContinueWith() { - string expected = "ERROR: Operation is not valid due to the current state of the object."; + string expected = "错误: Operation is not valid due to the current state of the object."; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => diff --git a/src/Chapter19.Tests/Listing19.06.Tests.cs b/src/Chapter19.Tests/Listing19.06.Tests.cs index 3290d4d9..8ac695e9 100644 --- a/src/Chapter19.Tests/Listing19.06.Tests.cs +++ b/src/Chapter19.Tests/Listing19.06.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_06.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"ERROR: Operation is not valid due to the current state of the object."; + const string expected = @"错误: Operation is not valid due to the current state of the object."; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter19.Tests/Listing19.07.Tests.cs b/src/Chapter19.Tests/Listing19.07.Tests.cs index 009c3a23..6041c60f 100644 --- a/src/Chapter19.Tests/Listing19.07.Tests.cs +++ b/src/Chapter19.Tests/Listing19.07.Tests.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_07.Tests; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter19.Listing19_07.Tests; [TestClass] public class ProgramTests @@ -7,12 +7,12 @@ public class ProgramTests public void ValueTaskAsyncReturnTest() { string expected = -@"Sleeping for 2000 ms -Throwing exception. -Event handler starting -Sleeping for 4000 ms -Awake -Finally block running."; +@"睡眠2000毫秒 +抛出异常。 +正在启动事件处理程序. +睡眠4000毫秒 +唤醒 +正在运行finally块。"; string output = IntelliTect.TestTools.Console.ConsoleAssert.Execute(string.Empty, Program.Main).TrimEnd(); diff --git a/src/Chapter20.Tests/BaseProgramTests.cs b/src/Chapter20.Tests/BaseProgramTests.cs index 26621902..038b5f52 100644 --- a/src/Chapter20.Tests/BaseProgramTests.cs +++ b/src/Chapter20.Tests/BaseProgramTests.cs @@ -1,4 +1,4 @@ -using System.Diagnostics.CodeAnalysis; +using System.Diagnostics.CodeAnalysis; using System.Net; using System.Runtime.ExceptionServices; using System.Runtime.InteropServices; @@ -32,13 +32,9 @@ public void Main_FindText_VerifyOccurrenceCount(string findText, string countPat { string url = DefaultUrl; string expected = - @$"Searching for '{Regex.Escape(findText) - }' at URL '{ - Regex.Escape(url) - }'\.\s+Downloading\.{{3,}}\s+Searching\.{{3,}}\s+'{ - Regex.Escape(findText)}' appears {countPattern} times at URL '{ - Regex.Escape(url) - }'\.\s+"; + $@"从网址'{Regex.Escape(url)}'搜索'{Regex.Escape(findText)}'。\s+" + + $@"正在下载\.{{3,}}\s+正在搜索\.{{3,}}\s+" + + $@"'{Regex.Escape(findText)}'在网址'{Regex.Escape(url)}'出现了{countPattern}次。\s+"; string actual = IntelliTect.TestTools.Console.ConsoleAssert.Execute("", () => ProgramWrapper.Main(new string[] { findText }).Wait()); @@ -50,7 +46,7 @@ public void Main_FindText_VerifyOccurrenceCount(string findText, string countPat [TestMethod] public void Main_PassEmptyArray_ThrowException() { - string expected = "ERROR: No findText argument specified."; + string expected = "错误:没有输入要搜索的文本。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect(expected, () => { diff --git a/src/Chapter20.Tests/Listing20.09.ImplementingCustomAsynchronousMethod.Tests.cs b/src/Chapter20.Tests/Listing20.09.ImplementingCustomAsynchronousMethod.Tests.cs index 0a5b8571..92047947 100644 --- a/src/Chapter20.Tests/Listing20.09.ImplementingCustomAsynchronousMethod.Tests.cs +++ b/src/Chapter20.Tests/Listing20.09.ImplementingCustomAsynchronousMethod.Tests.cs @@ -1,4 +1,4 @@ -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_09.Tests; @@ -8,12 +8,12 @@ public class ProgramTests [TestMethod] public void AsyncVoidReturnTest() { - string expected = $@"Invoking Task.Run...(Thread ID: *) -Running task... (Thread ID: *) -Post notification invoked...(Thread ID: *)* -Throwing expected exception....(Thread ID: *) -System.Exception: Expected Exception - *(Thread ID: *)"; + string expected = $@"正在调用Task.Run...(线程ID: *) +正在运行任务... (线程ID: *) +已调用Post通知...(线程ID: *)* +正在抛出预期的异常....(线程ID: *) +已抛出预期的异常System.Exception: 预期的异常 + *。(线程ID: *)"; string output = IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike( expected, @@ -27,8 +27,8 @@ Throwing expected exception....(Thread ID: *) Console.WriteLine(output); - // Verify that only the 'Running task...' thread id (the second line), is unique - MatchCollection matches = Regex.Matches(output, @"\(Thread ID: (\d)+\)"); + // Verify that only the '正在运行任务...' thread id (the second line), is unique + MatchCollection matches = Regex.Matches(output, @"\(线程ID: (\d)+\)"); int firstThreadId = int.Parse(matches[0].Groups[1].Value); int secondThreadId = int.Parse(matches[1].Groups[1].Value); int? expectedThreadId; diff --git a/src/Chapter21.Tests/Listing21.04.Tests.cs b/src/Chapter21.Tests/Listing21.04.Tests.cs index 5a90ebf5..c7ab145b 100644 --- a/src/Chapter21.Tests/Listing21.04.Tests.cs +++ b/src/Chapter21.Tests/Listing21.04.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter21.Listing21_04.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"ERROR: AggregateException: + const string expected = @"错误: AggregateException: UnauthorizedAccessException - Attempted to perform an unauthorized operation.*"; IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike( diff --git a/src/Chapter21/Listing21.04.UnhandledExceptionsParallelIterations.cs b/src/Chapter21/Listing21.04.UnhandledExceptionsParallelIterations.cs index 548952fc..ffa14ead 100644 --- a/src/Chapter21/Listing21.04.UnhandledExceptionsParallelIterations.cs +++ b/src/Chapter21/Listing21.04.UnhandledExceptionsParallelIterations.cs @@ -1,4 +1,4 @@ -namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter21.Listing21_04; +namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter21.Listing21_04; #region INCLUDE using System; @@ -34,7 +34,7 @@ static void EncryptFiles( #endregion HIGHLIGHT { Console.WriteLine( - "´íÎó: {0}:", + "错误: {0}:", exception.GetType().Name); foreach(Exception item in #region HIGHLIGHT diff --git a/src/Chapter22.Tests/Listing22.01.UnsychronizedState.Tests.cs b/src/Chapter22.Tests/Listing22.01.UnsychronizedState.Tests.cs index 5c3f4055..bb987643 100644 --- a/src/Chapter22.Tests/Listing22.01.UnsychronizedState.Tests.cs +++ b/src/Chapter22.Tests/Listing22.01.UnsychronizedState.Tests.cs @@ -1,4 +1,4 @@ -using System.Text.RegularExpressions; +using System.Text.RegularExpressions; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_01.Tests; @@ -38,7 +38,7 @@ public static bool IsIncrementDecrementNotAtomic( public static void VerifyOutputIncrementAndDecrement(Func main) { int? result = null; - string expected = $"Increment and decrementing \\d+ times...{Environment.NewLine}Count = (?\\d*)"; + string expected = $"递增和递减\\d+次...{Environment.NewLine}Count = (?-?\\d+)"; string output = IntelliTect.TestTools.Console.ConsoleAssert.Execute("", () => { diff --git a/src/Chapter22.Tests/Listing22.09.Tests.cs b/src/Chapter22.Tests/Listing22.09.Tests.cs index 7fef746d..7b944767 100644 --- a/src/Chapter22.Tests/Listing22.09.Tests.cs +++ b/src/Chapter22.Tests/Listing22.09.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_09.Tests; [TestClass] @@ -7,7 +7,7 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"ENTER to shut down"; + const string expected = @"按Enter键关闭。"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter22.Tests/Listing22.10.Tests.cs b/src/Chapter22.Tests/Listing22.10.Tests.cs index 88025e55..bfa84879 100644 --- a/src/Chapter22.Tests/Listing22.10.Tests.cs +++ b/src/Chapter22.Tests/Listing22.10.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_10.Tests; [TestClass] @@ -7,13 +7,13 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Application started.... -Starting task.... -DoWork() started.... - Waiting while thread executes... -DoWork() ending.... -Thread completed -Application shutting down...."; + const string expected = @"应用程序已启动... +正在启动任务... +DoWork()已启动.... +在线程执行期间等待... +DoWork()正在结束.... +线程已结束 +应用程序关闭..."; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter22.Tests/Listing22.11.Tests.cs b/src/Chapter22.Tests/Listing22.11.Tests.cs index 0a390dae..22e16560 100644 --- a/src/Chapter22.Tests/Listing22.11.Tests.cs +++ b/src/Chapter22.Tests/Listing22.11.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_11.Tests; [TestClass] @@ -7,8 +7,8 @@ public class ProgramTests [TestMethod] public void MainTest() { - string expected = $@"Decrement Count = {-32767.01134} -Main Count = {32767.01134}"; + string expected = $@"Decrement中的Count = {-32767.01134} +Main中的Count = {32767.01134}"; IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); diff --git a/src/Chapter22.Tests/Listing22.12.Tests.cs b/src/Chapter22.Tests/Listing22.12.Tests.cs index f049e9bb..10da4be9 100644 --- a/src/Chapter22.Tests/Listing22.12.Tests.cs +++ b/src/Chapter22.Tests/Listing22.12.Tests.cs @@ -1,4 +1,4 @@ - + namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter22.Listing22_12.Tests; [TestClass] @@ -7,8 +7,8 @@ public class ProgramTests [TestMethod] public void MainTest() { - const string expected = @"Decrement Count = * -Main Count = *"; + const string expected = @"Decrement中的Count = * +Main中的Count = *"; IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike( expected, Program.Main); diff --git a/src/Chapter23.Tests/Listing23.20.DesignatingABlockForUnsafeCode.Tests.cs b/src/Chapter23.Tests/Listing23.20.DesignatingABlockForUnsafeCode.Tests.cs index a770f6d8..6deb8913 100644 --- a/src/Chapter23.Tests/Listing23.20.DesignatingABlockForUnsafeCode.Tests.cs +++ b/src/Chapter23.Tests/Listing23.20.DesignatingABlockForUnsafeCode.Tests.cs @@ -1,4 +1,4 @@ -using System.Runtime.InteropServices; +using System.Runtime.InteropServices; namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter23.Listing23_20.Tests; #if NET8_0_OR_GREATER @@ -8,10 +8,10 @@ public class Listing21_20_Tests [TestMethod] public void GetProcessorIdReturnsCorrectValue() { - string expected = @"Processor Id: *"; + string expected = @"处理器ID: *"; if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { - expected = "This sample is only valid for Windows"; + expected = "本例只适用于Windows平台"; } IntelliTect.TestTools.Console.ConsoleAssert.ExpectLike(expected, () => diff --git a/src/Shared/Tests/PowerShellTestUtilities.cs b/src/Shared/Tests/PowerShellTestUtilities.cs index 35b9390d..569bdbaa 100644 --- a/src/Shared/Tests/PowerShellTestUtilities.cs +++ b/src/Shared/Tests/PowerShellTestUtilities.cs @@ -1,5 +1,6 @@ using System.Runtime.InteropServices; using System.Diagnostics; +using System.Text; namespace AddisonWesley.Michaelis.EssentialCSharp.Shared.Tests; @@ -57,16 +58,42 @@ public static int RunPowerShellScript(string scriptPath, string arguments, out s using var powerShell = new Process(); powerShell.StartInfo.RedirectStandardOutput = true; powerShell.StartInfo.RedirectStandardError = true; + powerShell.StartInfo.RedirectStandardInput = true; + powerShell.StartInfo.StandardOutputEncoding = Encoding.UTF8; + powerShell.StartInfo.StandardErrorEncoding = Encoding.UTF8; + powerShell.StartInfo.UseShellExecute = false; powerShell.StartInfo.FileName = PowerShellCommand; - powerShell.StartInfo.Arguments = $"-noprofile -command \"{scriptPath} {arguments}\""; + powerShell.StartInfo.ArgumentList.Add("-NoProfile"); + powerShell.StartInfo.ArgumentList.Add("-NonInteractive"); + powerShell.StartInfo.ArgumentList.Add("-Command"); + string escapedScriptPath = scriptPath.Replace("'", "''"); + powerShell.StartInfo.ArgumentList.Add( + "[Console]::OutputEncoding = [System.Text.UTF8Encoding]::new($false); " + + "$OutputEncoding = [Console]::OutputEncoding; " + + $"& '{escapedScriptPath}' {arguments}"); powerShell.Start(); - psOutput = powerShell.StandardOutput.ReadToEnd(); - string errorOutput = powerShell.StandardError.ReadToEnd(); + powerShell.StandardInput.Close(); + // Drain both pipes while the child is running. Waiting on stdout first + // can deadlock when a compiler or cleanup command fills stderr. + Task outputTask = powerShell.StandardOutput.ReadToEndAsync(); + Task errorTask = powerShell.StandardError.ReadToEndAsync(); + bool exited = powerShell.WaitForExit((int)TimeSpan.FromMinutes(3).TotalMilliseconds); + if (!exited) + { + powerShell.Kill(entireProcessTree: true); + powerShell.WaitForExit(); + } + psOutput = outputTask.GetAwaiter().GetResult(); + string errorOutput = errorTask.GetAwaiter().GetResult(); if (errorOutput.Length > 0) { psOutput += $"{Environment.NewLine}ERROR: {Environment.NewLine}{errorOutput}"; } - powerShell.WaitForExit(); + if (!exited) + { + throw new TimeoutException($"PowerShell script '{scriptPath}' did not finish within three minutes." + + Environment.NewLine + psOutput); + } return powerShell.ExitCode; }