Fixed failing tests due to ValueTask return (which is not supported)
MODIFY
src/Chapter20.Tests/Listing20.01.Tests.cs
src/Chapter20.Tests/Listing20.01.Tests.cs
using AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Tests;
using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System;
using System.Threading.Tasks;
namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_01.Tests

MODIFY
src/Chapter20.Tests/Listing20.02.Tests.cs
src/Chapter20.Tests/Listing20.02.Tests.cs
@@ -17,13 +17,6 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_02.Tests
Task.Run(() => Program.Main(args)));
}
- protected override void AssertMainException(string messagePrefix, Exception exception)
- {
- Assert.AreEqual<Type>(typeof(AggregateException), exception.GetType()); // Testing type first (even though the cast will also verify)
-
- AssertAggregateExceptionType(messagePrefix, (AggregateException)exception);
- }
-
protected override string DefaultUrl { get; } = Program.DefaultUrl;
}
}

MODIFY
src/Chapter20.Tests/Listing20.03.Tests.cs
src/Chapter20.Tests/Listing20.03.Tests.cs
@@ -9,6 +9,11 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_03.Tests
[TestClass]
public class ProgramTests : BaseProgramTests
{
+ //public ProgramTests()
+ //{
+ // ClassInitialize(TestContext);
+ //}
+
[ClassInitialize]
public static void ClassInitialize(TestContext _)
{
@@ -17,18 +22,9 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_03.Tests
Task.Run(() => Program.Main(args)));
}
- override protected void AssertMainException(string messagePrefix, Exception exception)
- {
- Assert.IsTrue(
- // Handle exceptions rethrown in Listing 19.14
- IntelliTect.TestTools.Console.StringExtensions.IsLike(exception.Message, "Rethrowing...*") &&
- IntelliTect.TestTools.Console.StringExtensions.IsLike(exception?.InnerException?.Message, messagePrefix)
- );
- }
-
- protected override void AssertFindTextInWebUriException(string messagePrefix, Exception exception)
+ protected override void AssertMainException(string messagePrefix,Exception exception)
{
- AssertAggregateExceptionType(messagePrefix, (AggregateException)exception);
+ base.AssertMainException(messagePrefix, (AggregateException)exception);
}
protected override string DefaultUrl { get; } = Program.DefaultUrl;

MODIFY
src/Chapter20.Tests/Listing20.04.Tests.cs
src/Chapter20.Tests/Listing20.04.Tests.cs
@@ -11,16 +11,14 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter20.Listing20_03
[ClassInitialize]
static public void ClassInitialize(TestContext _)
{
- //ProgramWrapper = new ProgramWrapper(
- // (string[] args)=> Program.Main(args),
- // (findText, urls, progress) => Program.FindTextInWebUriAsync(findText, urls.First(), progress));
+ ProgramWrapper = new ProgramWrapper(
+ (string[] args)=> Program.Main(args));
}
-
protected override void AssertMainException(string messagePrefix, Exception exception)
{
- Assert.AreEqual<Type>(typeof(AggregateException), exception.GetType()); // Testing type first (even though the cast will also verify)
- AssertAggregateExceptionType(messagePrefix, (AggregateException)exception);
+ System.Net.WebException webException = (System.Net.WebException)((AggregateException)exception).Flatten().InnerException!;
+ AssertWebExceptionType(messagePrefix, webException);
}
protected override string DefaultUrl => Program.DefaultUrl;

Fixed failing tests due to ValueTask return (which is not supported)