Renamed CompilerAssert to CompilerAssertOld with minor edits.
MODIFY
src/Chapter03.Tests/Listing03.02.DereferencingAnUnassignedVariable.Tests.cs
src/Chapter03.Tests/Listing03.02.DereferencingAnUnassignedVariable.Tests.cs
@@ -14,7 +14,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_02.Tests
[TestMethod]
public async Task UnassignedVariableThrowsError()
{
- _ = await CompilerAssert.ExpectErrorsInFileAsync(
+ _ = await CompilerAssertOld.ExpectErrorsInFileAsync(
"Listing03.02.DereferencingAnUnassignedVariable.cs",
new CompileError("CS0165", "Use of unassigned local variable 'text'"));
}

MODIFY
src/Chapter03.Tests/Table03.03.Tests.cs
src/Chapter03.Tests/Table03.03.Tests.cs
@@ -26,7 +26,7 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Table03_03.Tests
/* 9. */ [DataRow(nameof(CommonArayCodingErrors.MultiDimensionalArrayWithInconsistentSize), "CS0847")]
public async Task ParseAndCompile(string targetMethod, params string[] errorIds)
{
- await CompilerAssert.Compile2Async("Table03.03.CommonArrayCodingErrors.cs", errorIds, targetMethod);
+ await CompilerAssertOld.Compile2Async("Table03.03.CommonArrayCodingErrors.cs", errorIds, targetMethod);
}
// 6.

MODIFY
src/Shared/CompilerAssert.cs
src/Shared/CompilerAssert.cs
@@ -82,23 +82,16 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared
CompileError lhs, CompileError rhs) =>
!lhs.Equals(rhs);
}
- static public class CompilerAssert
+ static public class CompilerAssertOld
{
-
- private static readonly CSharpCompilationOptions DefaultCompilationOptions =
- new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
- .WithOverflowChecks(true).WithOptimizationLevel(OptimizationLevel.Release);
- //.WithUsings(DefaultNamespaces);
-
-
public static async Task Compile2Async(
string fileName,
string[] errorIds,
- string? targetMethod) => await Compile2Async(
+ string? targetMethod) => await CompileAsync(
new string[] { fileName }, errorIds, targetMethod);
- public static async Task Compile2Async(string[] fileNames, string[] errorIds, string? targetMethod = null)
+ public static async Task CompileAsync(string[] fileNames, string[] errorIds, string? targetMethod = null)
{
string code = string.Empty;
List<SyntaxTree> syntaxTrees = new();
@@ -176,10 +169,10 @@ namespace AddisonWesley.Michaelis.EssentialCSharp.Shared
(string result, string item) =>
result += $"\n{item}");
- return ExpectErrorsAsync(sourceCode, diagnostics);
+ return ExpectErrors(sourceCode, diagnostics);
}
- public static CompileError[] ExpectErrorsAsync(
+ public static CompileError[] ExpectErrors(
string sourceCode, params CompileError[] diagnostics)
{
ArgumentNullException.ThrowIfNull(diagnostics);

Renamed CompilerAssert to CompilerAssertOld with minor edits.