Skip to content

Fix Chapter 20 ignored tests #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/Branch v9.0.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ jobs:
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --no-restore --verbosity detailed
run: dotnet test --no-build --no-restore --verbosity normal
36 changes: 21 additions & 15 deletions src/Chapter20.Tests/BaseProgramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,9 @@ protected static void AssertWebExceptionType(string messagePrefix, WebException
{
bool isLike = IntelliTect.TestTools.Console.StringExtensions.IsLike(
exception.Message, messagePrefix);
string notLikeMessage = $"Messages are unexpectedly different:\n\texpected: {messagePrefix}\n\tActual: {exception.Message}";
string notLikeMessage = $"Messages are unexpectedly different on {Environment.OSVersion}:\n\texpected: {messagePrefix}\n\tActual: {exception.Message}\n\t OSInformation: {RuntimeInformation.OSDescription}";

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Assert.IsTrue(isLike, notLikeMessage);
}
else
{
Assert.Inconclusive(notLikeMessage);
}
Assert.IsTrue(isLike, notLikeMessage);
}

protected static void AssertAggregateExceptionType(string messagePrefix, AggregateException aggregateException)
Expand Down Expand Up @@ -148,19 +141,33 @@ async public Task Main_GivenNullUri_ThrowException()

[TestMethod]
[DataRow("Bad Uri", "Could not find file *")]
[DataRow("https://bad uri", "The filename, directory name, or volume label syntax is incorrect. *")]
[DataRow("https://thisisanotherbadurlthatpresumablyldoesnotexist.notexist", "No such host is known.*")]
[DataRow("https://bad uri", "The filename, directory name, or volume label syntax is incorrect. *", "Could not find a part of the path*", "Could not find a part of the path*")]
[DataRow("https://thisisanotherbadurlthatpresumablyldoesnotexist.notexist", "No such host is known.*", "nodename nor servname provided, or not known*", "Name or service not known*")]
[ExpectedException(typeof(WebException))]
async public Task Main_GivenBadUri_ThrowException(string uri, string messagePrefix)
async public Task Main_GivenBadUri_ThrowException(string uri, string defaultMessagePrefix, string? messagePrefixOSX = null, string? messagePrefixLinux = null)
{
messagePrefixOSX ??= defaultMessagePrefix;
messagePrefixLinux ??= defaultMessagePrefix;

try
{
await ProgramWrapper.Main(new string[] { "irrelevant", uri });
Assert.Fail("Expected exception was not thrown.");
}
catch (Exception exception)
{
AssertMainException(messagePrefix, exception);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
AssertMainException(defaultMessagePrefix, exception);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
AssertMainException(messagePrefixOSX, exception);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
AssertMainException(messagePrefixLinux, exception);
}
if (exception is AggregateException aggregateException)
{
// Innerexception expected to be WebException.
Expand All @@ -180,5 +187,4 @@ async public Task Main_GivenBadUri_ThrowException(string uri, string messagePref
}
}
}

}
}