From a10920bf9a95a0e29bfbd347639007fef37d55dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 2 Jun 2022 14:19:17 +0200 Subject: [PATCH] Enable nullable on HtmlLogger --- TestPlatform.sln | 5 ++ .../BannedSymbols.txt | 4 + .../Constants.cs | 2 - .../Html.xslt | 32 +++---- .../HtmlLogger.cs | 60 +++++++------ .../HtmlTransformer.cs | 2 - .../IHtmlTransformer.cs | 2 - ....TestPlatform.Extensions.HtmlLogger.csproj | 3 + .../ObjectModel/HtmlTestResult.cs | 14 ++-- .../ObjectModel/TestResultCollection.cs | 6 +- .../ObjectModel/TestRunDetails.cs | 10 +-- .../ObjectModel/TestRunSummary.cs | 4 +- .../PublicAPI/PublicAPI.Shipped.txt | 81 +++++++++--------- .../InferRunSettingsHelper.cs | 3 +- .../TestPlatformHelpers/TestRequestManager.cs | 9 +- .../HtmlLoggerTests.cs | 84 ++++++++++--------- 16 files changed, 166 insertions(+), 155 deletions(-) create mode 100644 src/Microsoft.TestPlatform.Extensions.HtmlLogger/BannedSymbols.txt diff --git a/TestPlatform.sln b/TestPlatform.sln index b3053c9883..4b1f213312 100644 --- a/TestPlatform.sln +++ b/TestPlatform.sln @@ -189,6 +189,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "testhost.arm64", "src\testh EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DumpMinitool.arm64", "src\DataCollectors\DumpMinitool.arm64\DumpMinitool.arm64.csproj", "{62E9D32B-B989-43CF-81A2-B38B3367FCA3}" EndProject +Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Microsoft.TestPlatform.Nullability", "src\Microsoft.TestPlatform.Nullability\Microsoft.TestPlatform.Nullability.shproj", "{9DF3BC3C-2A53-46E7-9291-40728ACE5F82}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -1023,6 +1025,7 @@ Global {29270853-90DC-4C39-9621-F47AE40A79B6} = {B27FAFDF-2DBA-4AB0-BA85-FD5F21D359D6} {186069FE-E1E8-4DE1-BEA4-0FF1484D22D1} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} {62E9D32B-B989-43CF-81A2-B38B3367FCA3} = {B705537C-B82C-4A30-AFA5-6244D9A7DAEB} + {9DF3BC3C-2A53-46E7-9291-40728ACE5F82} = {ED0C35EB-7F31-4841-A24F-8EB708FFA959} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {0541B30C-FF51-4E28-B172-83F5F3934BCD} @@ -1030,6 +1033,7 @@ Global GlobalSection(SharedMSBuildProjectFiles) = preSolution src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{10b6ade1-f808-4612-801d-4452f5b52242}*SharedItemsImports = 5 src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{186069fe-e1e8-4de1-bea4-0ff1484d22d1}*SharedItemsImports = 5 + src\Microsoft.TestPlatform.Nullability\Microsoft.TestPlatform.Nullability.projitems*{236a71e3-01da-4679-9dff-16a8e079acff}*SharedItemsImports = 5 src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{27dfbd04-64b2-4f1b-82b2-006620cca6f8}*SharedItemsImports = 5 src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{2c7ce1f8-e73e-4987-8023-b5a0ebac86e8}*SharedItemsImports = 5 src\Microsoft.TestPlatform.Nullability\Microsoft.TestPlatform.Nullability.projitems*{61f7f446-9ef3-4768-b33a-4d75f60e1059}*SharedItemsImports = 5 @@ -1037,6 +1041,7 @@ Global src\Microsoft.TestPlatform.Nullability\Microsoft.TestPlatform.Nullability.projitems*{68adc720-316e-4895-9f8e-c3ccadd262be}*SharedItemsImports = 5 src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{71cb42ff-e750-4a3b-9c3a-ac938853cc89}*SharedItemsImports = 5 src\Microsoft.TestPlatform.Execution.Shared\Microsoft.TestPlatform.Execution.Shared.projitems*{7f26eda3-c8c4-4b7f-a9b6-d278c2f40a13}*SharedItemsImports = 13 + src\Microsoft.TestPlatform.Nullability\Microsoft.TestPlatform.Nullability.projitems*{9df3bc3c-2a53-46e7-9291-40728ace5f82}*SharedItemsImports = 13 src\Microsoft.TestPlatform.Nullability\Microsoft.TestPlatform.Nullability.projitems*{fbf74c8f-695c-4967-84ac-358eefb1376d}*SharedItemsImports = 5 EndGlobalSection EndGlobal diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/BannedSymbols.txt b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/BannedSymbols.txt new file mode 100644 index 0000000000..c3370ddb45 --- /dev/null +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/BannedSymbols.txt @@ -0,0 +1,4 @@ +M:System.Diagnostics.Debug.Assert(System.Boolean); Use 'TPDebug.Assert' instead +M:System.Diagnostics.Debug.Assert(System.Boolean,System.String); Use 'TPDebug.Assert' instead +M:System.String.IsNullOrEmpty(System.String); Use 'StringUtils.IsNullOrEmpty' instead +M:System.String.IsNullOrWhiteSpace(System.String); Use 'StringUtils.IsNullOrWhiteSpace' instead diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Constants.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Constants.cs index 53bbcd068f..48e789459b 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Constants.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Constants.cs @@ -5,8 +5,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel; -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger; public static class Constants diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Html.xslt b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Html.xslt index 4b4e11be1f..c96e41e10e 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Html.xslt +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Html.xslt @@ -2,7 +2,7 @@ @@ -109,7 +109,7 @@

All Results

- +

Informational messages

@@ -118,7 +118,7 @@
- +

Error and Warning messages

@@ -127,7 +127,7 @@
- + @@ -149,23 +149,23 @@ - - - + + + - +
-
- + +
-
- + +
- +
@@ -176,12 +176,12 @@
-
+
- + Error:

@@ -223,7 +223,7 @@
- +   diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs index 2adff9775b..1d31b1a9d5 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlLogger.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Concurrent; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Linq; @@ -22,8 +23,6 @@ using HtmlLoggerConstants = Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants; using HtmlResource = Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Resources.Resources; -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger; /// @@ -37,7 +36,7 @@ public class HtmlLogger : ITestLoggerWithParameters private readonly XmlObjectSerializer _xmlSerializer; private readonly IHtmlTransformer _htmlTransformer; private static readonly object FileCreateLockObject = new(); - private Dictionary _parametersDictionary; + private Dictionary? _parametersDictionary; public HtmlLogger() : this(new FileHelper(), new HtmlTransformer(), new DataContractSerializer(typeof(TestRunDetails))) @@ -55,23 +54,23 @@ public HtmlLogger(IFileHelper fileHelper, IHtmlTransformer htmlTransformer, /// /// Gets the directory under which default html file and test results attachments should be saved. /// - public string TestResultsDirPath { get; private set; } + public string? TestResultsDirPath { get; private set; } /// /// Total results are stored in sequential order /// /// - public ConcurrentDictionary Results { get; private set; } + public ConcurrentDictionary? Results { get; private set; } /// /// /// - public ConcurrentDictionary ResultCollectionDictionary { get; private set; } + public ConcurrentDictionary? ResultCollectionDictionary { get; private set; } /// /// Test results stores all the summary and the details of every results in hierarchical order. /// - public TestRunDetails TestRunDetails { get; private set; } + public TestRunDetails? TestRunDetails { get; private set; } /// /// Total passed tests in the test results. @@ -96,14 +95,15 @@ public HtmlLogger(IFileHelper fileHelper, IHtmlTransformer htmlTransformer, /// /// Path to the xml file. /// - public string XmlFilePath { get; private set; } + public string? XmlFilePath { get; private set; } /// /// path to html file. /// - public string HtmlFilePath { get; private set; } + public string? HtmlFilePath { get; private set; } /// + [MemberNotNull(nameof(TestResultsDirPath), nameof(TestRunDetails), nameof(Results), nameof(ResultCollectionDictionary))] public void Initialize(TestLoggerEvents events, string testResultsDirPath) { ValidateArg.NotNull(events, nameof(events)); @@ -124,7 +124,8 @@ public void Initialize(TestLoggerEvents events, string testResultsDirPath) } /// - public void Initialize(TestLoggerEvents events, Dictionary parameters) + [MemberNotNull(nameof(_parametersDictionary))] + public void Initialize(TestLoggerEvents events, Dictionary parameters) { ValidateArg.NotNull(parameters, nameof(parameters)); if (parameters.Count == 0) @@ -140,7 +141,7 @@ public void Initialize(TestLoggerEvents events, Dictionary param throw new ArgumentException(htmlParameterErrorMsg); } - Initialize(events, parameters[DefaultLoggerParameterNames.TestRunDirectory]); + Initialize(events, parameters[DefaultLoggerParameterNames.TestRunDirectory]!); } /// @@ -148,11 +149,12 @@ public void Initialize(TestLoggerEvents events, Dictionary param /// /// /// - public void TestMessageHandler(object sender, TestRunMessageEventArgs e) + public void TestMessageHandler(object? sender, TestRunMessageEventArgs e) { - ValidateArg.NotNull(sender, nameof(sender)); ValidateArg.NotNull(e, nameof(e)); + TPDebug.Assert(TestRunDetails != null, "Initialize must be called before this method."); + switch (e.Level) { case TestMessageLevel.Informational: @@ -184,11 +186,12 @@ public void TestMessageHandler(object sender, TestRunMessageEventArgs e) /// /// /// - public void TestResultHandler(object sender, TestResultEventArgs e) + public void TestResultHandler(object? sender, TestResultEventArgs e) { - ValidateArg.NotNull(sender, nameof(sender)); ValidateArg.NotNull(e, nameof(e)); + TPDebug.Assert(ResultCollectionDictionary != null && TestRunDetails != null && Results != null, "Initialize must be called before this method."); + var testResult = new ObjectModel.TestResult { DisplayName = e.Result.DisplayName ?? e.Result.TestCase.FullyQualifiedName, @@ -212,7 +215,7 @@ public void TestResultHandler(object sender, TestResultEventArgs e) FailedResultList = new List(), }; ResultCollectionDictionary.TryAdd(e.Result.TestCase.Source, testResultCollection); - TestRunDetails.ResultCollectionList.Add(testResultCollection); + TestRunDetails.ResultCollectionList!.Add(testResultCollection); } TotalTests++; @@ -238,10 +241,10 @@ public void TestResultHandler(object sender, TestResultEventArgs e) { if (e.Result.Outcome == TestOutcome.Failed) { - testResultCollection.FailedResultList.Add(testResult); + testResultCollection.FailedResultList!.Add(testResult); } - testResultCollection.ResultList.Add(testResult); + testResultCollection.ResultList!.Add(testResult); } else { @@ -251,6 +254,9 @@ public void TestResultHandler(object sender, TestResultEventArgs e) private void AddToParentResult(Guid parentExecutionId, ObjectModel.TestResult testResult) { + TPDebug.Assert(Results != null, "Initialize must be called before this method."); + + if (Results.TryGetValue(parentExecutionId, out var parentTestResult)) { if (parentTestResult.InnerTestResults == null) @@ -265,8 +271,10 @@ private void AddToParentResult(Guid parentExecutionId, ObjectModel.TestResult te /// /// /// - public void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) + public void TestRunCompleteHandler(object? sender, TestRunCompleteEventArgs e) { + TPDebug.Assert(TestRunDetails != null && _parametersDictionary != null, "Initialize must be called before this method."); + TestRunDetails.Summary = new TestRunSummary { FailedTests = FailedTests, @@ -276,7 +284,7 @@ public void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) PassPercentage = TotalTests == 0 ? 0 : PassedTests * 100 / TotalTests, TotalRunTime = GetFormattedDurationString(e.ElapsedTimeInRunningTests), }; - if (_parametersDictionary.TryGetValue(HtmlLoggerConstants.LogFilePrefixKey, out string logFilePrefixValue) && !string.IsNullOrWhiteSpace(logFilePrefixValue)) + if (_parametersDictionary.TryGetValue(HtmlLoggerConstants.LogFilePrefixKey, out string? logFilePrefixValue) && !logFilePrefixValue.IsNullOrWhiteSpace()) { var framework = _parametersDictionary[DefaultLoggerParameterNames.TargetFramework]; if (framework != null) @@ -290,7 +298,7 @@ public void TestRunCompleteHandler(object sender, TestRunCompleteEventArgs e) } else { - if (_parametersDictionary.TryGetValue(HtmlLoggerConstants.LogFileNameKey, out string logFileNameValue) && !string.IsNullOrWhiteSpace(logFileNameValue)) + if (_parametersDictionary.TryGetValue(HtmlLoggerConstants.LogFileNameKey, out string? logFileNameValue) && !logFileNameValue.IsNullOrWhiteSpace()) { HtmlFilePath = Path.Combine(TestResultsDirPath, logFileNameValue); } @@ -314,7 +322,7 @@ private void PopulateHtmlFile() _xmlSerializer.WriteObject(xmlStream, TestRunDetails); } - if (string.IsNullOrEmpty(HtmlFilePath)) + if (HtmlFilePath.IsNullOrEmpty()) { HtmlFilePath = GenerateUniqueFilePath(fileName, HtmlLoggerConstants.HtmlFileExtension); } @@ -361,7 +369,7 @@ private string GenerateUniqueFilePath(string fileName, string fileExtension) throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, HtmlResource.CannotGenerateUniqueFilePath, fileName, TestResultsDirPath)); } - private string FormatDateTimeForRunName(DateTime timeStamp) + private static string FormatDateTimeForRunName(DateTime timeStamp) { return timeStamp.ToString("yyyyMMdd_HHmmss", DateTimeFormatInfo.InvariantInfo); } @@ -371,7 +379,7 @@ private string FormatDateTimeForRunName(DateTime timeStamp) /// /// /// - private Guid GetParentExecutionId(TestPlatform.ObjectModel.TestResult testResult) + private static Guid GetParentExecutionId(TestPlatform.ObjectModel.TestResult testResult) { var parentExecutionIdProperty = testResult.Properties.FirstOrDefault(property => property.Id.Equals(HtmlLoggerConstants.ParentExecutionIdPropertyIdentifier)); @@ -385,7 +393,7 @@ private Guid GetParentExecutionId(TestPlatform.ObjectModel.TestResult testResult /// /// /// - private Guid GetExecutionId(TestPlatform.ObjectModel.TestResult testResult) + private static Guid GetExecutionId(TestPlatform.ObjectModel.TestResult testResult) { var executionIdProperty = testResult.Properties.FirstOrDefault(property => property.Id.Equals(HtmlLoggerConstants.ExecutionIdPropertyIdentifier)); @@ -404,7 +412,7 @@ private Guid GetExecutionId(TestPlatform.ObjectModel.TestResult testResult) /// /// /// - internal string GetFormattedDurationString(TimeSpan duration) + internal static string? GetFormattedDurationString(TimeSpan duration) { if (duration == default) { diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlTransformer.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlTransformer.cs index 788146ee4a..08e9986591 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlTransformer.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/HtmlTransformer.cs @@ -5,8 +5,6 @@ using System.Xml; using System.Xml.Xsl; -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger; /// diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/IHtmlTransformer.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/IHtmlTransformer.cs index ef34290207..0b615e9bda 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/IHtmlTransformer.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/IHtmlTransformer.cs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger; public interface IHtmlTransformer diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Microsoft.TestPlatform.Extensions.HtmlLogger.csproj b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Microsoft.TestPlatform.Extensions.HtmlLogger.csproj index 111783e19f..9c8c248202 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Microsoft.TestPlatform.Extensions.HtmlLogger.csproj +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/Microsoft.TestPlatform.Extensions.HtmlLogger.csproj @@ -3,12 +3,14 @@ ..\..\ + Microsoft.VisualStudio.TestPlatform.Extensions.Html.TestLogger netstandard2.0;net451 net6.0 false + true @@ -44,6 +46,7 @@ Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger + diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/HtmlTestResult.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/HtmlTestResult.cs index 06c26cd7e2..1603585975 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/HtmlTestResult.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/HtmlTestResult.cs @@ -7,8 +7,6 @@ using Microsoft.VisualStudio.TestPlatform.ObjectModel; -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel; /// @@ -20,7 +18,7 @@ public class TestResult /// /// Fully qualified name of the Test Result. /// - [DataMember] public string FullyQualifiedName { get; set; } + [DataMember] public string? FullyQualifiedName { get; set; } /// /// Unique identifier for test result @@ -30,17 +28,17 @@ public class TestResult /// /// Display Name for the particular Test Result /// - [DataMember] public string DisplayName { get; set; } + [DataMember] public string? DisplayName { get; set; } /// /// The error stack trace of the Test Result. /// - [DataMember] public string ErrorStackTrace { get; set; } + [DataMember] public string? ErrorStackTrace { get; set; } /// /// Error message of the Test Result. /// - [DataMember] public string ErrorMessage { get; set; } + [DataMember] public string? ErrorMessage { get; set; } /// /// Enum that determines the outcome of the test case @@ -50,10 +48,10 @@ public class TestResult /// /// Total timespan of the TestResult /// - [DataMember] public string Duration { get; set; } + [DataMember] public string? Duration { get; set; } /// /// The list of TestResults that are children to the current Test Result. /// - [DataMember] public List InnerTestResults { get; set; } + [DataMember] public List? InnerTestResults { get; set; } } diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestResultCollection.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestResultCollection.cs index 58c7e54a05..eea80fdfdb 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestResultCollection.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestResultCollection.cs @@ -5,8 +5,6 @@ using System.Collections.Generic; using System.Runtime.Serialization; -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel; /// @@ -42,10 +40,10 @@ private set { } /// /// List of test results. /// - [DataMember] public List ResultList { get; set; } + [DataMember] public List? ResultList { get; set; } /// /// List of failed test results. /// - [DataMember] public List FailedResultList { get; set; } + [DataMember] public List? FailedResultList { get; set; } } diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestRunDetails.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestRunDetails.cs index 9c9d788c2c..12f841ed5f 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestRunDetails.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestRunDetails.cs @@ -4,8 +4,6 @@ using System.Collections.Generic; using System.Runtime.Serialization; -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel; /// @@ -17,20 +15,20 @@ public sealed class TestRunDetails /// /// Test run summary of all test results. /// - [DataMember] public TestRunSummary Summary { get; set; } + [DataMember] public TestRunSummary? Summary { get; set; } /// /// List of informational run level messages. /// - [DataMember] public List RunLevelMessageInformational; + [DataMember] public List? RunLevelMessageInformational; /// /// List of error and warning messages. /// - [DataMember] public List RunLevelMessageErrorAndWarning; + [DataMember] public List? RunLevelMessageErrorAndWarning; /// /// List of all the results /// - [DataMember] public List ResultCollectionList = new(); + [DataMember] public List? ResultCollectionList = new(); } diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestRunSummary.cs b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestRunSummary.cs index ba33a06f2c..18ce46e46a 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestRunSummary.cs +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/ObjectModel/TestRunSummary.cs @@ -3,8 +3,6 @@ using System.Runtime.Serialization; -#nullable disable - namespace Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel; /// @@ -21,7 +19,7 @@ public class TestRunSummary /// /// Total test run time. /// - [DataMember] public string TotalRunTime { get; set; } + [DataMember] public string? TotalRunTime { get; set; } /// /// Total tests of a test run. diff --git a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/PublicAPI/PublicAPI.Shipped.txt b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/PublicAPI/PublicAPI.Shipped.txt index 3f7c98707c..99dd7c096e 100644 --- a/src/Microsoft.TestPlatform.Extensions.HtmlLogger/PublicAPI/PublicAPI.Shipped.txt +++ b/src/Microsoft.TestPlatform.Extensions.HtmlLogger/PublicAPI/PublicAPI.Shipped.txt @@ -1,45 +1,46 @@ -const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.ExecutionIdPropertyIdentifier = "ExecutionId" -> string -const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.ExtensionUri = "logger://Microsoft/TestPlatform/HtmlLogger/v1" -> string -const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.FriendlyName = "Html" -> string -const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.HtmlFileExtension = "html" -> string -const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.LogFileNameKey = "LogFileName" -> string -const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.LogFilePrefixKey = "LogFilePrefix" -> string -const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.ParentExecutionIdPropertyIdentifier = "ParentExecId" -> string -const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.TestTypePropertyIdentifier = "TestType" -> string -const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.XmlFileExtension = "xml" -> string +#nullable enable +const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.ExecutionIdPropertyIdentifier = "ExecutionId" -> string! +const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.ExtensionUri = "logger://Microsoft/TestPlatform/HtmlLogger/v1" -> string! +const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.FriendlyName = "Html" -> string! +const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.HtmlFileExtension = "html" -> string! +const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.LogFileNameKey = "LogFileName" -> string! +const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.LogFilePrefixKey = "LogFilePrefix" -> string! +const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.ParentExecutionIdPropertyIdentifier = "ParentExecId" -> string! +const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.TestTypePropertyIdentifier = "TestType" -> string! +const Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.XmlFileExtension = "xml" -> string! Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.FailedTests.get -> int -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.HtmlFilePath.get -> string +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.HtmlFilePath.get -> string? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.HtmlLogger() -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.HtmlLogger(Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces.IFileHelper fileHelper, Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.IHtmlTransformer htmlTransformer, System.Runtime.Serialization.XmlObjectSerializer dataContractSerializer) -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.Initialize(Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestLoggerEvents events, string testResultsDirPath) -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.Initialize(Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestLoggerEvents events, System.Collections.Generic.Dictionary parameters) -> void +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.HtmlLogger(Microsoft.VisualStudio.TestPlatform.Utilities.Helpers.Interfaces.IFileHelper! fileHelper, Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.IHtmlTransformer! htmlTransformer, System.Runtime.Serialization.XmlObjectSerializer! dataContractSerializer) -> void +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.Initialize(Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestLoggerEvents! events, string! testResultsDirPath) -> void +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.Initialize(Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestLoggerEvents! events, System.Collections.Generic.Dictionary! parameters) -> void Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.PassedTests.get -> int -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.ResultCollectionDictionary.get -> System.Collections.Concurrent.ConcurrentDictionary -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.Results.get -> System.Collections.Concurrent.ConcurrentDictionary +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.ResultCollectionDictionary.get -> System.Collections.Concurrent.ConcurrentDictionary? +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.Results.get -> System.Collections.Concurrent.ConcurrentDictionary? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.SkippedTests.get -> int -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TestMessageHandler(object sender, Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestRunMessageEventArgs e) -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TestResultHandler(object sender, Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestResultEventArgs e) -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TestResultsDirPath.get -> string -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TestRunCompleteHandler(object sender, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestRunCompleteEventArgs e) -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TestRunDetails.get -> Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TestMessageHandler(object? sender, Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestRunMessageEventArgs! e) -> void +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TestResultHandler(object? sender, Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging.TestResultEventArgs! e) -> void +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TestResultsDirPath.get -> string? +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TestRunCompleteHandler(object? sender, Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.TestRunCompleteEventArgs! e) -> void +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TestRunDetails.get -> Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.TotalTests.get -> int -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.XmlFilePath.get -> string +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.XmlFilePath.get -> string? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.IHtmlTransformer -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.IHtmlTransformer.Transform(string xmlFile, string htmlFile) -> void +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.IHtmlTransformer.Transform(string! xmlFile, string! htmlFile) -> void Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.DisplayName.get -> string +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.DisplayName.get -> string? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.DisplayName.set -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.Duration.get -> string +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.Duration.get -> string? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.Duration.set -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.ErrorMessage.get -> string +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.ErrorMessage.get -> string? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.ErrorMessage.set -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.ErrorStackTrace.get -> string +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.ErrorStackTrace.get -> string? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.ErrorStackTrace.set -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.FullyQualifiedName.get -> string +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.FullyQualifiedName.get -> string? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.FullyQualifiedName.set -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.InnerTestResults.get -> System.Collections.Generic.List +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.InnerTestResults.get -> System.Collections.Generic.List? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.InnerTestResults.set -> void Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.ResultOutcome.get -> Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.ResultOutcome.set -> void @@ -47,18 +48,18 @@ Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.TestResultId.get -> System.Guid Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResult.TestResultId.set -> void Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.FailedResultList.get -> System.Collections.Generic.List +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.FailedResultList.get -> System.Collections.Generic.List? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.FailedResultList.set -> void Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.Id.get -> int -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.ResultList.get -> System.Collections.Generic.List +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.ResultList.get -> System.Collections.Generic.List? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.ResultList.set -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.Source.get -> string -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.TestResultCollection(string source) -> void +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.Source.get -> string! +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestResultCollection.TestResultCollection(string! source) -> void Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails.ResultCollectionList -> System.Collections.Generic.List -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails.RunLevelMessageErrorAndWarning -> System.Collections.Generic.List -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails.RunLevelMessageInformational -> System.Collections.Generic.List -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails.Summary.get -> Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails.ResultCollectionList -> System.Collections.Generic.List? +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails.RunLevelMessageErrorAndWarning -> System.Collections.Generic.List? +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails.RunLevelMessageInformational -> System.Collections.Generic.List? +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails.Summary.get -> Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails.Summary.set -> void Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunDetails.TestRunDetails() -> void Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary @@ -71,11 +72,11 @@ Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSum Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary.SkippedTests.get -> int Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary.SkippedTests.set -> void Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary.TestRunSummary() -> void -Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary.TotalRunTime.get -> string +Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary.TotalRunTime.get -> string? Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary.TotalRunTime.set -> void Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary.TotalTests.get -> int Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.ObjectModel.TestRunSummary.TotalTests.set -> void -static readonly Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.ExecutionIdProperty -> Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProperty +static readonly Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.ExecutionIdProperty -> Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProperty! static readonly Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.OrderedTestTypeGuid -> System.Guid -static readonly Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.ParentExecIdProperty -> Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProperty -static readonly Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.TestTypeProperty -> Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProperty \ No newline at end of file +static readonly Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.ParentExecIdProperty -> Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProperty! +static readonly Microsoft.VisualStudio.TestPlatform.Extensions.HtmlLogger.Constants.TestTypeProperty -> Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProperty! diff --git a/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs b/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs index 7c0072db2f..5325088ee5 100644 --- a/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs +++ b/src/Microsoft.TestPlatform.Utilities/InferRunSettingsHelper.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.IO; using System.Text; @@ -434,7 +435,7 @@ public static bool TryGetLegacySettingElements(string runsettingsXml, out Dictio public static void UpdateTargetPlatform(XmlDocument runSettingsDocument, string platform, bool overwrite = false) => AddNodeIfNotPresent(runSettingsDocument, TargetPlatformNodePath, TargetPlatformNodeName, platform, overwrite); - public static bool TryGetDeviceXml(XPathNavigator runSettingsNavigator, out string? deviceXml) + public static bool TryGetDeviceXml(XPathNavigator runSettingsNavigator, [NotNullWhen(true)] out string? deviceXml) { ValidateArg.NotNull(runSettingsNavigator, nameof(runSettingsNavigator)); diff --git a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs index ee79e16d92..814daf205f 100644 --- a/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs +++ b/src/vstest.console/TestPlatformHelpers/TestRequestManager.cs @@ -855,16 +855,17 @@ private bool AddOrUpdateConsoleLogger( return !designMode || consoleLoggerUpdated; } - private bool UpdateTargetDevice( + private static bool UpdateTargetDevice( XPathNavigator navigator, XmlDocument document) { - bool updateRequired = InferRunSettingsHelper.TryGetDeviceXml(navigator, out string deviceXml); - if (updateRequired) + if (InferRunSettingsHelper.TryGetDeviceXml(navigator, out string? deviceXml)) { InferRunSettingsHelper.UpdateTargetDevice(document, deviceXml); + return true; } - return updateRequired; + + return false; } private bool UpdateCollectSourceInformation( diff --git a/test/Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests/HtmlLoggerTests.cs b/test/Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests/HtmlLoggerTests.cs index 41bb939f41..821093aa91 100644 --- a/test/Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests/HtmlLoggerTests.cs +++ b/test/Microsoft.TestPlatform.Extensions.HtmlLogger.UnitTests/HtmlLoggerTests.cs @@ -56,7 +56,7 @@ public HtmlLoggerTests() public void InitializeShouldThrowExceptionIfEventsIsNull() { Assert.ThrowsException( - () => _htmlLogger.Initialize(null, _parameters)); + () => _htmlLogger.Initialize(null!, _parameters)); } [TestMethod] @@ -79,7 +79,7 @@ public void InitializeShouldThrowExceptionIfTestRunDirectoryIsEmptyOrNull() () => { _events = new Mock(); - _parameters[DefaultLoggerParameterNames.TestRunDirectory] = null; + _parameters[DefaultLoggerParameterNames.TestRunDirectory] = null!; _htmlLogger.Initialize(_events.Object, _parameters); }); } @@ -88,13 +88,13 @@ public void InitializeShouldThrowExceptionIfTestRunDirectoryIsEmptyOrNull() public void InitializeShouldThrowExceptionIfParametersAreEmpty() { var events = new Mock(); - Assert.ThrowsException(() => _htmlLogger.Initialize(events.Object, new Dictionary())); + Assert.ThrowsException(() => _htmlLogger.Initialize(events.Object, new Dictionary())); } [TestMethod] public void TestMessageHandlerShouldThrowExceptionIfEventArgsIsNull() { - Assert.ThrowsException(() => _htmlLogger.TestMessageHandler(new object(), default)); + Assert.ThrowsException(() => _htmlLogger.TestMessageHandler(new object(), default!)); } #endregion @@ -107,23 +107,23 @@ public void TestMessageHandlerShouldAddMessageWhenItIsInformation() _htmlLogger.TestMessageHandler(new object(), testRunMessageEventArgs); - var actualMessage = _htmlLogger.TestRunDetails.RunLevelMessageInformational.First(); + var actualMessage = _htmlLogger.TestRunDetails!.RunLevelMessageInformational!.First(); Assert.AreEqual(message, actualMessage); } [TestMethod] public void TestMessageHandlerShouldNotInitializelistForInformationErrorAndWarningMessages() { - Assert.IsNull(_htmlLogger.TestRunDetails.RunLevelMessageInformational); + Assert.IsNull(_htmlLogger.TestRunDetails!.RunLevelMessageInformational); Assert.IsNull(_htmlLogger.TestRunDetails.RunLevelMessageErrorAndWarning); } [TestMethod] public void TestCompleteHandlerShouldThrowExceptionIfParametersAreNull() { - Dictionary? parameters = null; + Dictionary? parameters = null; var events = new Mock(); - Assert.ThrowsException(() => _htmlLogger.Initialize(events.Object, parameters)); + Assert.ThrowsException(() => _htmlLogger.Initialize(events.Object, parameters!)); } [TestMethod] @@ -137,8 +137,9 @@ public void TestMessageHandlerShouldAddMessageInListIfItIsWarningAndError() var testRunMessageEventArgs2 = new TestRunMessageEventArgs(TestMessageLevel.Warning, message2); _htmlLogger.TestMessageHandler(new object(), testRunMessageEventArgs2); - Assert.AreEqual(message, _htmlLogger.TestRunDetails.RunLevelMessageErrorAndWarning.First()); - Assert.AreEqual(2, _htmlLogger.TestRunDetails.RunLevelMessageErrorAndWarning.Count); + var runLevelMessageErrorAndWarning = _htmlLogger.TestRunDetails!.RunLevelMessageErrorAndWarning!; + Assert.AreEqual(2, runLevelMessageErrorAndWarning.Count); + Assert.AreEqual(message, runLevelMessageErrorAndWarning.First()); } [TestMethod] @@ -199,7 +200,7 @@ public void TestResultHandlerShouldSetDisplayNameIfDisplayNameIsNull() _htmlLogger.TestResultHandler(new object(), new Mock(passTestResultExpected).Object); - Assert.AreEqual("abc", _htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.First().DisplayName); + Assert.AreEqual("abc", _htmlLogger.TestRunDetails!.ResultCollectionList!.First().ResultList!.First().DisplayName); } [TestMethod] @@ -215,7 +216,7 @@ public void TestResultHandlerShouldSetDisplayNameIfDisplayNameIsNotNull() _htmlLogger.TestResultHandler(new object(), new Mock(passTestResultExpected).Object); - Assert.AreEqual("def", _htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.Last().DisplayName); + Assert.AreEqual("def", _htmlLogger.TestRunDetails!.ResultCollectionList!.First().ResultList!.Last().DisplayName); } [TestMethod] @@ -239,13 +240,14 @@ public void TestResultHandlerShouldCreateTestResultProperly() // Act _htmlLogger.TestResultHandler(new object(), eventArg.Object); - var result = _htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.First(); + var resultCollectionList = _htmlLogger.TestRunDetails!.ResultCollectionList!; + var result = resultCollectionList.First().ResultList!.First(); Assert.AreEqual("def", result.DisplayName); Assert.AreEqual("error message", result.ErrorMessage); Assert.AreEqual("Error stack trace", result.ErrorStackTrace); Assert.AreEqual("fully", result.FullyQualifiedName); - Assert.AreEqual("abc/def.dll", _htmlLogger.TestRunDetails.ResultCollectionList.First().Source); + Assert.AreEqual("abc/def.dll", resultCollectionList.First().Source); Assert.AreEqual("1s", result.Duration); } @@ -253,34 +255,34 @@ public void TestResultHandlerShouldCreateTestResultProperly() public void GetFormattedDurationStringShouldGiveCorrectFormat() { TimeSpan ts1 = new(0, 0, 0, 0, 1); - Assert.AreEqual("1ms", _htmlLogger.GetFormattedDurationString(ts1)); + Assert.AreEqual("1ms", VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.GetFormattedDurationString(ts1)); TimeSpan ts2 = new(0, 0, 0, 1, 0); - Assert.AreEqual("1s", _htmlLogger.GetFormattedDurationString(ts2)); + Assert.AreEqual("1s", VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.GetFormattedDurationString(ts2)); TimeSpan ts3 = new(0, 0, 1, 0, 1); - Assert.AreEqual("1m", _htmlLogger.GetFormattedDurationString(ts3)); + Assert.AreEqual("1m", VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.GetFormattedDurationString(ts3)); TimeSpan ts4 = new(0, 1, 0, 2, 3); - Assert.AreEqual("1h", _htmlLogger.GetFormattedDurationString(ts4)); + Assert.AreEqual("1h", VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.GetFormattedDurationString(ts4)); TimeSpan ts5 = new(0, 1, 2, 3, 4); - Assert.AreEqual("1h 2m", _htmlLogger.GetFormattedDurationString(ts5)); + Assert.AreEqual("1h 2m", VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.GetFormattedDurationString(ts5)); TimeSpan ts6 = new(0, 0, 1, 2, 3); - Assert.AreEqual("1m 2s", _htmlLogger.GetFormattedDurationString(ts6)); + Assert.AreEqual("1m 2s", VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.GetFormattedDurationString(ts6)); TimeSpan ts7 = new(0, 0, 0, 1, 3); - Assert.AreEqual("1s 3ms", _htmlLogger.GetFormattedDurationString(ts7)); + Assert.AreEqual("1s 3ms", VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.GetFormattedDurationString(ts7)); TimeSpan ts8 = new(2); - Assert.AreEqual("< 1ms", _htmlLogger.GetFormattedDurationString(ts8)); + Assert.AreEqual("< 1ms", VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.GetFormattedDurationString(ts8)); TimeSpan ts10 = new(1, 0, 0, 1, 3); - Assert.AreEqual("> 1d", _htmlLogger.GetFormattedDurationString(ts10)); + Assert.AreEqual("> 1d", VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.GetFormattedDurationString(ts10)); TimeSpan ts9 = new(0, 0, 0, 0, 0); - Assert.IsNull(_htmlLogger.GetFormattedDurationString(ts9)); + Assert.IsNull(VisualStudio.TestPlatform.Extensions.HtmlLogger.HtmlLogger.GetFormattedDurationString(ts9)); } [TestMethod] @@ -297,7 +299,7 @@ public void TestResultHandlerShouldCreateOneTestEntryForEachTestCase() _htmlLogger.TestResultHandler(new object(), resultEventArg1.Object); _htmlLogger.TestResultHandler(new object(), resultEventArg2.Object); - Assert.AreEqual(2, _htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.Count, "TestResultHandler is not creating test result entry for each test case"); + Assert.AreEqual(2, _htmlLogger.TestRunDetails!.ResultCollectionList!.First().ResultList!.Count, "TestResultHandler is not creating test result entry for each test case"); } [TestMethod] @@ -315,7 +317,7 @@ public void TestResultHandlerShouldCreateOneTestResultCollectionForOneSource() _htmlLogger.TestResultHandler(new object(), new Mock(result1).Object); _htmlLogger.TestResultHandler(new object(), new Mock(result2).Object); - Assert.AreEqual(2, _htmlLogger.TestRunDetails.ResultCollectionList.Count); + Assert.AreEqual(2, _htmlLogger.TestRunDetails!.ResultCollectionList!.Count); Assert.AreEqual("abc.dll", _htmlLogger.TestRunDetails.ResultCollectionList.First().Source); Assert.AreEqual("def.dll", _htmlLogger.TestRunDetails.ResultCollectionList.Last().Source); } @@ -328,7 +330,7 @@ public void TestResultHandlerShouldAddFailedResultToFailedResultListInTestResult _htmlLogger.TestResultHandler(new object(), new Mock(result1).Object); - Assert.AreEqual(1, _htmlLogger.TestRunDetails.ResultCollectionList.First().FailedResultList.Count); + Assert.AreEqual(1, _htmlLogger.TestRunDetails!.ResultCollectionList!.First().FailedResultList!.Count); } [TestMethod] @@ -346,8 +348,8 @@ public void TestResultHandlerShouldAddHierarchicalResultsForOrderedTest() _htmlLogger.TestResultHandler(new object(), new Mock(result1).Object); - Assert.AreEqual(1, _htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.Count, "test handler is adding parent result correctly"); - Assert.IsNull(_htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.First().InnerTestResults, "test handler is adding child result correctly"); + Assert.AreEqual(1, _htmlLogger.TestRunDetails!.ResultCollectionList!.First().ResultList!.Count, "test handler is adding parent result correctly"); + Assert.IsNull(_htmlLogger.TestRunDetails!.ResultCollectionList!.First().ResultList!.First().InnerTestResults, "test handler is adding child result correctly"); var result2 = new ObjectModel.TestResult(testCase2); result2.SetPropertyValue(HtmlLoggerConstants.ExecutionIdProperty, Guid.NewGuid()); @@ -360,8 +362,8 @@ public void TestResultHandlerShouldAddHierarchicalResultsForOrderedTest() _htmlLogger.TestResultHandler(new object(), new Mock(result2).Object); _htmlLogger.TestResultHandler(new object(), new Mock(result3).Object); - Assert.AreEqual(1, _htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.Count, "test handler is adding parent result correctly"); - Assert.AreEqual(2, _htmlLogger.TestRunDetails.ResultCollectionList.First().ResultList.First().InnerTestResults.Count, "test handler is adding child result correctly"); + Assert.AreEqual(1, _htmlLogger.TestRunDetails!.ResultCollectionList!.First().ResultList!.Count, "test handler is adding parent result correctly"); + Assert.AreEqual(2, _htmlLogger.TestRunDetails.ResultCollectionList!.First().ResultList!.First().InnerTestResults!.Count, "test handler is adding child result correctly"); } [TestMethod] @@ -387,7 +389,7 @@ public void TestCompleteHandlerShouldKeepTackOfSummary() _htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, null, TimeSpan.Zero)); - Assert.AreEqual(4, _htmlLogger.TestRunDetails.Summary.TotalTests, "summary should keep track of total tests"); + Assert.AreEqual(4, _htmlLogger.TestRunDetails!.Summary!.TotalTests, "summary should keep track of total tests"); Assert.AreEqual(1, _htmlLogger.TestRunDetails.Summary.FailedTests, "summary should keep track of failed tests"); Assert.AreEqual(2, _htmlLogger.TestRunDetails.Summary.PassedTests, "summary should keep track of passed tests"); Assert.AreEqual(1, _htmlLogger.TestRunDetails.Summary.SkippedTests, "summary should keep track of passed tests"); @@ -411,13 +413,13 @@ public void TestCompleteHandlerShouldCreateCustomHtmlFileNamewithLogFileNameKey( _htmlLogger.Initialize(new Mock().Object, parameters); _htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, null, TimeSpan.Zero)); - Assert.IsTrue(_htmlLogger.HtmlFilePath.Contains("TestResult")); + Assert.IsTrue(_htmlLogger.HtmlFilePath!.Contains("TestResult")); } [TestMethod] public void TestCompleteHandlerShouldCreateCustomHtmlFileNameWithLogPrefix() { - var parameters = new Dictionary + var parameters = new Dictionary { [HtmlLoggerConstants.LogFilePrefixKey] = "sample", [DefaultLoggerParameterNames.TestRunDirectory] = "dsa", @@ -431,13 +433,13 @@ public void TestCompleteHandlerShouldCreateCustomHtmlFileNameWithLogPrefix() _htmlLogger.Initialize(new Mock().Object, parameters); _htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, null, TimeSpan.Zero)); - Assert.IsFalse(_htmlLogger.HtmlFilePath.Contains("__")); + Assert.IsFalse(_htmlLogger.HtmlFilePath!.Contains("__")); } [TestMethod] public void TestCompleteHandlerShouldCreateCustomHtmlFileNameWithLogPrefixIfTargetFrameworkIsNull() { - var parameters = new Dictionary + var parameters = new Dictionary { [HtmlLoggerConstants.LogFilePrefixKey] = "sample", [DefaultLoggerParameterNames.TestRunDirectory] = "dsa", @@ -451,7 +453,7 @@ public void TestCompleteHandlerShouldCreateCustomHtmlFileNameWithLogPrefixIfTarg _htmlLogger.Initialize(new Mock().Object, parameters); _htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, null, TimeSpan.Zero)); - Assert.IsTrue(_htmlLogger.HtmlFilePath.Contains("sample_net451")); + Assert.IsTrue(_htmlLogger.HtmlFilePath!.Contains("sample_net451")); } [TestMethod] @@ -481,7 +483,7 @@ public void TestCompleteHandlerShouldCreateCustomHtmlFileNameWithLogPrefixNull() [TestMethod] public void TestCompleteHandlerShouldThrowExceptionWithLogPrefixIfTargetFrameworkKeyIsNotPresent() { - var parameters = new Dictionary + var parameters = new Dictionary { [HtmlLoggerConstants.LogFilePrefixKey] = "sample.html", [DefaultLoggerParameterNames.TestRunDirectory] = "dsa" @@ -572,8 +574,8 @@ public void TestCompleteHandlerShouldWriteToXmlSerializerCorrectly() _htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, null, TimeSpan.Zero)); _mockXmlSerializer.Verify(x => x.WriteObject(It.IsAny(), It.IsAny()), Times.Once); - Assert.IsTrue(_htmlLogger.XmlFilePath.Contains(".xml")); - Assert.IsTrue(_htmlLogger.HtmlFilePath.Contains(".html")); + Assert.IsTrue(_htmlLogger.XmlFilePath!.Contains(".xml")); + Assert.IsTrue(_htmlLogger.HtmlFilePath!.Contains(".html")); } [TestMethod] @@ -585,7 +587,7 @@ public void TestCompleteHandlerShouldNotDivideByZeroWhenThereAre0TestResults() _htmlLogger.TestRunCompleteHandler(new object(), new TestRunCompleteEventArgs(null, false, true, null, null, null, TimeSpan.Zero)); - Assert.AreEqual(0, _htmlLogger.TestRunDetails.Summary.TotalTests); + Assert.AreEqual(0, _htmlLogger.TestRunDetails!.Summary!.TotalTests); Assert.AreEqual(0, _htmlLogger.TestRunDetails.Summary.PassPercentage); }