Skip to content

Commit 5a730d9

Browse files
Fix Chapter05 network tests to handle DNS blocking and broader network exceptions
Co-authored-by: BenjaminMichaelis <[email protected]>
1 parent a42b791 commit 5a730d9

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/Chapter05.Tests/Listing05.15.PassingCommandLineArgumentsToMain.Tests.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,23 @@ public void Main_IntelliTectIndexHtmlArgs_DownloadFile()
3333
IntelliTect.TestTools.Console.ConsoleAssert.Expect(
3434
expected, () => result = Program.Main(args));
3535
}
36-
catch (AggregateException exception) when (exception.InnerException is System.Net.Http.HttpRequestException)
36+
catch (AggregateException exception) when (
37+
exception.InnerException is System.Net.Http.HttpRequestException ||
38+
exception.InnerException is System.Net.Sockets.SocketException ||
39+
exception.InnerException is TaskCanceledException ||
40+
exception.InnerException is System.Net.NetworkInformation.NetworkInformationException)
41+
{
42+
Assert.Inconclusive("Unable to download the file. Check your internet connection.");
43+
}
44+
catch (System.Net.Http.HttpRequestException)
45+
{
46+
Assert.Inconclusive("Unable to download the file. Check your internet connection.");
47+
}
48+
catch (System.Net.Sockets.SocketException)
49+
{
50+
Assert.Inconclusive("Unable to download the file. Check your internet connection.");
51+
}
52+
catch (TaskCanceledException)
3753
{
3854
Assert.Inconclusive("Unable to download the file. Check your internet connection.");
3955
}
@@ -48,7 +64,23 @@ public void Main_GoodArgs_DownloadFile()
4864
{
4965
Assert.AreEqual(0, Program.Main(args));
5066
}
51-
catch (AggregateException exception) when (exception.InnerException is System.Net.Http.HttpRequestException)
67+
catch (AggregateException exception) when (
68+
exception.InnerException is System.Net.Http.HttpRequestException ||
69+
exception.InnerException is System.Net.Sockets.SocketException ||
70+
exception.InnerException is TaskCanceledException ||
71+
exception.InnerException is System.Net.NetworkInformation.NetworkInformationException)
72+
{
73+
Assert.Inconclusive("Unable to download the file. Check your Internet connection.");
74+
}
75+
catch (System.Net.Http.HttpRequestException)
76+
{
77+
Assert.Inconclusive("Unable to download the file. Check your Internet connection.");
78+
}
79+
catch (System.Net.Sockets.SocketException)
80+
{
81+
Assert.Inconclusive("Unable to download the file. Check your Internet connection.");
82+
}
83+
catch (TaskCanceledException)
5284
{
5385
Assert.Inconclusive("Unable to download the file. Check your Internet connection.");
5486
}

src/Chapter05.Tests/Listing05.33.CustomParameterValidation.Tests.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,23 @@ public void Main_IntelliTectIndexHtmlArgs_DownloadFile()
175175
IntelliTect.TestTools.Console.ConsoleAssert.Expect(
176176
expected, () => result = Program.Main(args));
177177
}
178-
catch (AggregateException exception) when (exception.InnerException is System.Net.Http.HttpRequestException)
178+
catch (AggregateException exception) when (
179+
exception.InnerException is System.Net.Http.HttpRequestException ||
180+
exception.InnerException is System.Net.Sockets.SocketException ||
181+
exception.InnerException is TaskCanceledException ||
182+
exception.InnerException is System.Net.NetworkInformation.NetworkInformationException)
183+
{
184+
Assert.Inconclusive("Unable to download the file. Check your internet connection.");
185+
}
186+
catch (System.Net.Http.HttpRequestException)
187+
{
188+
Assert.Inconclusive("Unable to download the file. Check your internet connection.");
189+
}
190+
catch (System.Net.Sockets.SocketException)
191+
{
192+
Assert.Inconclusive("Unable to download the file. Check your internet connection.");
193+
}
194+
catch (TaskCanceledException)
179195
{
180196
Assert.Inconclusive("Unable to download the file. Check your internet connection.");
181197
}

0 commit comments

Comments
 (0)