From 4ed37c76032ad3d6d12821d9c45bb2a0b8cc9f2a Mon Sep 17 00:00:00 2001 From: Benjamin Michaelis Date: Thu, 1 Feb 2024 16:10:22 -0800 Subject: [PATCH] Update Listing07.24.RelationalPatternWithIsOperator.cs --- src/Chapter07.Tests/Listing07.24.Tests.cs | 6 +++++- .../Listing07.24.RelationalPatternWithIsOperator.cs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Chapter07.Tests/Listing07.24.Tests.cs b/src/Chapter07.Tests/Listing07.24.Tests.cs index f1507123..121ef61d 100644 --- a/src/Chapter07.Tests/Listing07.24.Tests.cs +++ b/src/Chapter07.Tests/Listing07.24.Tests.cs @@ -42,6 +42,10 @@ public void GetPeriodOfDay_Evening_ReturnsEvening() [TestMethod] public void GetPeriodOfDay_InvalidHour_ReturnsInvalid() { - Assert.ThrowsException(() => PeriodsOfTheDay.GetPeriodOfDay(25)); + int invalidHour = 25; + + var exceptionThrown = Assert.ThrowsException(() => + PeriodsOfTheDay.GetPeriodOfDay(invalidHour)); + Assert.IsTrue(exceptionThrown.Message.StartsWith($"The hour of the day specified ({invalidHour}) is invalid.")); } } diff --git a/src/Chapter07/Listing07.24.RelationalPatternWithIsOperator.cs b/src/Chapter07/Listing07.24.RelationalPatternWithIsOperator.cs index 43b7d477..1d84e9a1 100644 --- a/src/Chapter07/Listing07.24.RelationalPatternWithIsOperator.cs +++ b/src/Chapter07/Listing07.24.RelationalPatternWithIsOperator.cs @@ -17,7 +17,7 @@ public static string GetPeriodOfDay(int hourOfTheDay) => < 18 => "Afternoon", < 24 => "Evening", int hour => throw new ArgumentOutOfRangeException(nameof(hourOfTheDay), - $"The hour of the day specified is invalid.") + $"The hour of the day specified ({hour}) is invalid.") }; #endregion INCLUDE }