Updated Listing 03.01
ADD
src/Chapter03.Tests/Listing03.01.Tests.cs
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_01.Tests
+{
+ [TestClass]
+ public class UppercaseTests
+ {
+ [TestMethod]
+ public void Main_GivenArgs_NumberDoubles()
+ {
+ string[] args = { "arg0", "arg1" };
+ string expected =
+ $"\'number\' doubled is { args[0].Length * 2 }.";
+
+ IntelliTect.TestTools.Console.ConsoleAssert.Expect(
+ expected, ()=>Program.Main(args));
+ }
+
+ [TestMethod]
+ public void Main_GivenValidString_MakeUppercase()
+ {
+ string[] args = { };
+ const string expected =
+ "\'number\' requires a value and cannot be null";
+
+ IntelliTect.TestTools.Console.ConsoleAssert.Expect(
+ expected, () => Program.Main(args));
+ }
+ }
+}
\ No newline at end of file

MODIFY
src/Chapter03/Listing03.01.CheckingForNull.cs
src/Chapter03/Listing03.01.CheckingForNull.cs
@@ -2,19 +2,25 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_01
{
public class Program
{
- public static void Main()
+ public static void Main(string[] args)
{
int? number = null;
+
// ...
+ if(args.Length>0)
+ {
+ number = args[0].Length;
+ }
+
if (number is null)
{
System.Console.WriteLine(
- $"{ nameof(number) } requires a value and cannot be null");
+ "'number' requires a value and cannot be null");
}
else
{
System.Console.WriteLine(
- $"{ nameof(number) } is of type { number.GetType() }.");
+ $"'number' doubled is { number * 2 }.");
}
}

Updated Listing 03.01