Skip to content

Commit

Permalink
Merge pull request #142 from IntelliTect/UpdateChapter03Listings
Browse files Browse the repository at this point in the history
Updated Listing 03.01
  • Loading branch information
BenjaminMichaelis authored Jan 21, 2021
2 parents c01b53e + 58acdc1 commit 9202bc9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/Chapter03.Tests/Listing03.01.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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));
}
}
}
12 changes: 9 additions & 3 deletions src/Chapter03/Listing03.01.CheckingForNull.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }.");
}

}
Expand Down

0 comments on commit 9202bc9

Please sign in to comment.