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
Changes from 1 commit
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
Next Next commit
Fix Chapter 20 ignored tests
  • Loading branch information
BenjaminMichaelis authored Dec 27, 2021
commit d91f06ba4845c5e2f5dbac0de45cf520a0efdacb
31 changes: 16 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,28 @@ 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*")]
[DataRow("https://thisisanotherbadurlthatpresumablyldoesnotexist.notexist", "No such host is known.*", "nodename nor servname provided, or 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? messagePrefixLinux = null)
{
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) || RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
AssertMainException(messagePrefixLinux, exception);
}
if (exception is AggregateException aggregateException)
{
// Innerexception expected to be WebException.
Expand All @@ -180,5 +182,4 @@ async public Task Main_GivenBadUri_ThrowException(string uri, string messagePref
}
}
}

}
}