-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add Some Missing Tests from Chapter 7 (#605)
Contributes to #12
- Loading branch information
1 parent
de8ca1f
commit 3b045c1
Showing
11 changed files
with
211 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_23.Tests; | ||
|
||
[TestClass] | ||
public class SolsticeHelperTests | ||
{ | ||
[TestMethod] | ||
public void IsSolstice_21DayWrongMonth_ReturnsFalse() | ||
{ | ||
Assert.IsFalse(SolsticeHelper.IsSolstice(new DateTime(2019, 1, 21))); | ||
} | ||
|
||
[TestMethod] | ||
public void IsSolstice_21DayRightMonth_ReturnsTrue() | ||
{ | ||
Assert.IsTrue(SolsticeHelper.IsSolstice(new DateTime(2023, 12, 21))); | ||
} | ||
|
||
[TestMethod] | ||
public void IsSolstice_20DayRightMonth_ReturnsTrue() | ||
{ | ||
Assert.IsTrue(SolsticeHelper.IsSolstice(new DateTime(2024, 6, 21))); | ||
} | ||
|
||
[TestMethod] | ||
public void IsSolstice_WrongDayRightMonth_ReturnsFalse() | ||
{ | ||
Assert.IsFalse(SolsticeHelper.IsSolstice(new DateTime(2024, 6, 15))); | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetSolstice_21DayWrongMonth_ReturnsFalse() | ||
{ | ||
Assert.IsFalse(SolsticeHelper.TryGetSolstice(new DateTime(2019, 1, 21), out string? solstice)); | ||
Assert.IsNull(solstice); | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetSolstice_21DayRightMonth_ReturnsTrueWinterSolstice() | ||
{ | ||
Assert.IsTrue(SolsticeHelper.TryGetSolstice(new DateTime(2023, 12, 21), out string? solstice)); | ||
Assert.AreEqual("Winter Solstice", solstice); | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetSolstice_20DayRightMonth_ReturnsTrueSummerSolstice() | ||
{ | ||
Assert.IsTrue(SolsticeHelper.TryGetSolstice(new DateTime(2024, 6, 21), out string? solstice)); | ||
Assert.AreEqual("Summer Solstice", solstice); | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetSolstice_WrongDayRightMonth_ReturnsFalse() | ||
{ | ||
Assert.IsFalse(SolsticeHelper.TryGetSolstice(new DateTime(2024, 6, 15), out string? solstice)); | ||
Assert.IsNull(solstice); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_24.Tests; | ||
|
||
[TestClass] | ||
public class PeriodsOfTheDayTests | ||
{ | ||
[TestMethod] | ||
public void IsDeveloperWorkHours_ValidWorkingHours_ReturnsTrue() | ||
{ | ||
Assert.IsTrue(PeriodsOfTheDay.IsDeveloperWorkHours(12)); | ||
} | ||
|
||
[TestMethod] | ||
public void IsDeveloperWorkHours_ValidNonWorkingHours_ReturnsFalse() | ||
{ | ||
Assert.IsFalse(PeriodsOfTheDay.IsDeveloperWorkHours(3)); | ||
} | ||
|
||
[TestMethod] | ||
public void GetPeriodOfDay_Dawn_ReturnsDawn() | ||
{ | ||
Assert.AreEqual("Dawn", PeriodsOfTheDay.GetPeriodOfDay(5)); | ||
} | ||
|
||
[TestMethod] | ||
public void GetPeriodOfDay_Morning_ReturnsMorning() | ||
{ | ||
Assert.AreEqual("Morning", PeriodsOfTheDay.GetPeriodOfDay(6)); | ||
} | ||
|
||
[TestMethod] | ||
public void GetPeriodOfDay_Afternoon_ReturnsAfternoon() | ||
{ | ||
Assert.AreEqual("Afternoon", PeriodsOfTheDay.GetPeriodOfDay(13)); | ||
} | ||
|
||
[TestMethod] | ||
public void GetPeriodOfDay_Evening_ReturnsEvening() | ||
{ | ||
Assert.AreEqual("Evening", PeriodsOfTheDay.GetPeriodOfDay(18)); | ||
} | ||
|
||
[TestMethod] | ||
public void GetPeriodOfDay_InvalidHour_ReturnsInvalid() | ||
{ | ||
Assert.ThrowsException<ArgumentOutOfRangeException>(() => PeriodsOfTheDay.GetPeriodOfDay(25)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_25.Tests; | ||
|
||
[TestClass] | ||
public class LogicalPatternMatchingTests | ||
{ | ||
[TestMethod] | ||
public void IsStandardWorkHours() | ||
{ | ||
TimeOnly time = new(8, 0, 0); | ||
Assert.IsFalse(PeriodsOfTheDay.IsStandardWorkHours(time)); | ||
time = new(9, 1, 0); | ||
Assert.IsTrue(PeriodsOfTheDay.IsStandardWorkHours(time)); | ||
time = new(12, 0, 0); | ||
Assert.IsFalse(PeriodsOfTheDay.IsStandardWorkHours(time)); | ||
time = new(13, 1, 0); | ||
Assert.IsTrue(PeriodsOfTheDay.IsStandardWorkHours(time)); | ||
time = new(16, 59, 0); | ||
Assert.IsTrue(PeriodsOfTheDay.IsStandardWorkHours(time)); | ||
time = new(17, 0, 0); | ||
Assert.IsFalse(PeriodsOfTheDay.IsStandardWorkHours(time)); | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetPhoneButton() | ||
{ | ||
Assert.IsTrue(PeriodsOfTheDay.TryGetPhoneButton('a', out char? button)); | ||
Assert.AreEqual('2', button); | ||
Assert.IsTrue(PeriodsOfTheDay.TryGetPhoneButton('z', out button)); | ||
Assert.AreEqual('9', button); | ||
Assert.IsTrue(PeriodsOfTheDay.TryGetPhoneButton('+', out button)); | ||
Assert.AreEqual('0', button); | ||
Assert.IsFalse(PeriodsOfTheDay.TryGetPhoneButton('=', out button)); | ||
Assert.IsNull(button); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_26.Tests; | ||
|
||
[TestClass] | ||
public class ParenthesizedPatternsTests | ||
{ | ||
[TestMethod] | ||
public void IsOutsideOfStandardWorkHours() | ||
{ | ||
TimeOnly time = new(8, 0, 0); | ||
Assert.IsTrue(new PeriodsOfTheDay().IsOutsideOfStandardWorkHours(time)); | ||
time = new(9, 1, 0); | ||
Assert.IsFalse(new PeriodsOfTheDay().IsOutsideOfStandardWorkHours(time)); | ||
time = new(12, 0, 0); | ||
Assert.IsTrue(new PeriodsOfTheDay().IsOutsideOfStandardWorkHours(time)); | ||
time = new(13, 1, 0); | ||
Assert.IsFalse(new PeriodsOfTheDay().IsOutsideOfStandardWorkHours(time)); | ||
time = new(16, 59, 0); | ||
Assert.IsFalse(new PeriodsOfTheDay().IsOutsideOfStandardWorkHours(time)); | ||
time = new(17, 0, 0); | ||
Assert.IsTrue(new PeriodsOfTheDay().IsOutsideOfStandardWorkHours(time)); | ||
} | ||
|
||
[TestMethod] | ||
public void TryGetPhoneButton() | ||
{ | ||
Assert.IsTrue(PeriodsOfTheDay.TryGetPhoneButton('a', out char? button)); | ||
Assert.AreEqual('2', button); | ||
Assert.IsTrue(PeriodsOfTheDay.TryGetPhoneButton('z', out button)); | ||
Assert.AreEqual('9', button); | ||
Assert.IsTrue(PeriodsOfTheDay.TryGetPhoneButton('+', out button)); | ||
Assert.AreEqual('0', button); | ||
Assert.IsFalse(PeriodsOfTheDay.TryGetPhoneButton('=', out button)); | ||
Assert.IsNull(button); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using IntelliTect.TestTools.Console; | ||
|
||
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter07.Listing07_34.Tests; | ||
|
||
[TestClass] | ||
public class DataConversionUsingTheAsOperatorTests | ||
{ | ||
[TestMethod] | ||
public void Load() | ||
{ | ||
Contact contact = new("Inigo Montoya"); | ||
PdaItem pdaItem = contact; | ||
Assert.AreEqual(contact, Contact.Load(pdaItem)); | ||
} | ||
[TestMethod] | ||
[ExpectedException(typeof(ArgumentException))] | ||
public void Load_InvalidType() | ||
{ | ||
PdaItem pdaItem = new PdaItem(); | ||
Contact.Load(pdaItem); | ||
} | ||
[TestMethod] | ||
public void LoadValidType_TestOutput() | ||
{ | ||
Contact contact = new("Inigo Montoya"); | ||
PdaItem pdaItem = contact; | ||
ConsoleAssert.Expect( | ||
"ObjectKey: 00000000-0000-0000-0000-000000000000", | ||
() => Contact.Load(pdaItem)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,4 +22,3 @@ public static TimeOnly GetTime(object input) | |
} | ||
#endregion INCLUDE | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,4 @@ DateTimeOffset datetimeOffset | |
$"Invalid type - {input.GetType().FullName}"), | ||
}; | ||
#endregion INCLUDE | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters