Added text to describe enabling null.
MODIFY
src/Chapter03.Tests/Chapter03.Tests.csproj
src/Chapter03.Tests/Chapter03.Tests.csproj
<ChapterNumber>03</ChapterNumber>
</PropertyGroup>
<Import Project="..\ChapterTests.props" />
+ <ItemGroup>
+ <Compile Include="..\Shared\CompilerAssert.cs" Link="CompilerAssert.cs" />
+ </ItemGroup>
+ <ItemGroup>
+ <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="3.3.1" />
+ <PackageReference Include="Microsoft.CodeAnalysis.Scripting.Common" Version="3.3.1" />
+ </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Chapter03\Chapter03.csproj" />
</ItemGroup>

ADD
src/Chapter03.Tests/Listing03.01B.Tests.cs
+using AddisonWesley.Michaelis.EssentialCSharp.Shared;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+using System.Threading.Tasks;
+
+namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_01B.Tests
+{
+ [TestClass]
+ public class UppercaseTests
+ {
+ public TestContext? TestContext { get; set; }
+
+ [TestMethod]
+ async public Task UnassignedVariableThrowsError()
+ {
+ CompileError[] compileErrors = await CompilerAssert.ExpectErrorsInFileAsync(
+ "Listing03.01B.DereferencingAnUnassignedVariable.cs",
+ new CompileError("CS0165: Use of unassigned local variable 'text'"));
+ }
+ }
+}
\ No newline at end of file

MODIFY
src/Chapter03/Chapter03.csproj
src/Chapter03/Chapter03.csproj
<Link>Program.cs</Link>
</Compile>
</ItemGroup>
+ <ItemGroup>
+ <None Include="Listing03.01B.DereferencingAnUnassignedVariable.cs">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </None>
+ <None Include="Listing03.01C.csproj" />
+ </ItemGroup>
</Project>

MODIFY
src/Chapter03/Listing03.01B.DereferencingAnUnassignedVariable.cs
src/Chapter03/Listing03.01B.DereferencingAnUnassignedVariable.cs
-namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_01B
-{
+// namespace AddisonWesley.Michaelis.EssentialCSharp.Chapter03.Listing03_01B
+//{
public class Program
{
public static void Main()
{
string? text;
// ...
+
// Compile Error: Use of unassigned local variable 'text'
- // System.Console.WriteLine(text.length);
- }
+ System.Console.WriteLine(text.Length);
}
}
+//}

Added text to describe enabling null.