From a8da94010a38944687287e1515bdd968331044c4 Mon Sep 17 00:00:00 2001 From: dotMorten Date: Wed, 21 Aug 2019 11:00:28 -0700 Subject: [PATCH] Enable nullability in unit tests --- .../NmeaParser.Tests.NET45/NmeaParser.Tests.NET45.csproj | 2 ++ .../NmeaParser.Tests.UWP/NmeaParser.Tests.UWP.csproj | 4 +++- src/UnitTests/NmeaParser.Tests.UWP/UnitTestApp.xaml.cs | 8 +++++--- src/UnitTests/NmeaParser.Tests/DeviceTests.cs | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/UnitTests/NmeaParser.Tests.NET45/NmeaParser.Tests.NET45.csproj b/src/UnitTests/NmeaParser.Tests.NET45/NmeaParser.Tests.NET45.csproj index 8d18743..c3d4368 100644 --- a/src/UnitTests/NmeaParser.Tests.NET45/NmeaParser.Tests.NET45.csproj +++ b/src/UnitTests/NmeaParser.Tests.NET45/NmeaParser.Tests.NET45.csproj @@ -19,6 +19,8 @@ UnitTest + 8.0 + enable true diff --git a/src/UnitTests/NmeaParser.Tests.UWP/NmeaParser.Tests.UWP.csproj b/src/UnitTests/NmeaParser.Tests.UWP/NmeaParser.Tests.UWP.csproj index 95e231d..a115610 100644 --- a/src/UnitTests/NmeaParser.Tests.UWP/NmeaParser.Tests.UWP.csproj +++ b/src/UnitTests/NmeaParser.Tests.UWP/NmeaParser.Tests.UWP.csproj @@ -13,12 +13,14 @@ UAP 10.0.17763.0 10.0.16299.0 - 14 + 16 512 {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} NmeaParser.Tests.UWP_TemporaryKey.pfx $(VisualStudioVersion) D07B149B4E796AB0184B2E2FC9DDC1A2F5CA5A7E + 8.0 + enable true diff --git a/src/UnitTests/NmeaParser.Tests.UWP/UnitTestApp.xaml.cs b/src/UnitTests/NmeaParser.Tests.UWP/UnitTestApp.xaml.cs index bbcb58c..4d18550 100644 --- a/src/UnitTests/NmeaParser.Tests.UWP/UnitTestApp.xaml.cs +++ b/src/UnitTests/NmeaParser.Tests.UWP/UnitTestApp.xaml.cs @@ -47,7 +47,7 @@ namespace NmeaParser.Tests.UWP } #endif - Frame rootFrame = Window.Current.Content as Frame; + Frame? rootFrame = Window.Current?.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active @@ -64,13 +64,15 @@ namespace NmeaParser.Tests.UWP } // Place the frame in the current Window - Window.Current.Content = rootFrame; + if (Window.Current != null) + Window.Current.Content = rootFrame; } Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.CreateDefaultUI(); // Ensure the current window is active - Window.Current.Activate(); + if (Window.Current != null) + Window.Current.Activate(); Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.Run(e.Arguments); } diff --git a/src/UnitTests/NmeaParser.Tests/DeviceTests.cs b/src/UnitTests/NmeaParser.Tests/DeviceTests.cs index d7702d3..d4a61f7 100644 --- a/src/UnitTests/NmeaParser.Tests/DeviceTests.cs +++ b/src/UnitTests/NmeaParser.Tests/DeviceTests.cs @@ -26,7 +26,7 @@ namespace NmeaParser.Tests { Assert.IsTrue(e.IsMultipart, "IsMultiPart"); Assert.IsInstanceOfType(e.Message, typeof(NmeaParser.Nmea.Gsv)); - var msg = e.Message as NmeaParser.Nmea.Gsv; + var msg = (NmeaParser.Nmea.Gsv)e.Message; if (msg.TotalMessages == msg.MessageNumber) { Assert.IsNotNull(e.MessageParts); @@ -67,7 +67,7 @@ $GAGSV,4,4,14,19,82,349,40,1,44,220,40,4,24,314,38*5F"; { Assert.IsTrue(e.IsMultipart, "IsMultiPart"); Assert.IsInstanceOfType(e.Message, typeof(NmeaParser.Nmea.Gsv)); - var msg = e.Message as NmeaParser.Nmea.Gsv; + var msg = (NmeaParser.Nmea.Gsv)e.Message; if (msg.TotalMessages == msg.MessageNumber) { Assert.IsNotNull(e.MessageParts);