Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix more IDE warnings #3388

Merged
merged 2 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ await _testRunAttachmentsProcessingManager.ProcessTestRunAttachmentsAsync(runset
private TestArtifacts[] LoadTestArtifacts() => _fileHelper.GetFiles(_processArtifactFolder, "*.*", SearchOption.AllDirectories)
.Select(file => new { TestSessionId = Path.GetFileName(Path.GetDirectoryName(file)), Artifact = file })
.GroupBy(grp => grp.TestSessionId)
.Select(testSessionArtifact => new TestArtifacts(testSessionArtifact.Key, testSessionArtifact.Select(x => ParseArtifact(x.Artifact)).Where(x => x is not null).ToArray()))
.Select(testSessionArtifact => new TestArtifacts(testSessionArtifact.Key, testSessionArtifact.Select(x => ParseArtifact(x.Artifact)).Where(x => x is not null).ToArray()!)) // Bang because null dataflow doesn't yet backport learning from the `Where` clause
.ToArray();

private static Artifact? ParseArtifact(string fileName!!) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// 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.CrossPlatEngine.ArtifactProcessing;

using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;

using Microsoft.VisualStudio.TestPlatform.ObjectModel;
Expand All @@ -23,9 +20,9 @@ internal class PostProcessingTestRunAttachmentsProcessingEventsHandler : ITestRu
private readonly IOutput _consoleOutput;
private readonly ConcurrentBag<AttachmentSet> _attachmentsSet = new();

public PostProcessingTestRunAttachmentsProcessingEventsHandler(IOutput consoleOutput)
public PostProcessingTestRunAttachmentsProcessingEventsHandler(IOutput consoleOutput!!)
{
_consoleOutput = consoleOutput ?? throw new ArgumentNullException(nameof(consoleOutput));
_consoleOutput = consoleOutput;
}

public void HandleLogMessage(TestMessageLevel level, string message)
Expand Down Expand Up @@ -69,8 +66,7 @@ public void HandleTestRunAttachmentsProcessingComplete(TestRunAttachmentsProcess
{
foreach (var uriDataAttachment in attachmentSet.Attachments)
{
var attachmentOutput = string.Format(CultureInfo.CurrentCulture, CommandLineResources.AttachmentOutputFormat, uriDataAttachment.Uri.LocalPath);
_consoleOutput.Information(false, ConsoleColor.Gray, attachmentOutput);
_consoleOutput.Information(false, ConsoleColor.Gray, CommandLineResources.AttachmentOutputFormat, uriDataAttachment.Uri.LocalPath);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
// 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.CrossPlatEngine.ArtifactProcessing;

using System;

internal class TestArtifacts
{
public TestArtifacts(string testSession, Artifact[] artifacts)
public TestArtifacts(string testSession!!, Artifact[] artifacts!!)
{
TestSession = testSession ?? throw new ArgumentNullException(nameof(testSession));
Artifacts = artifacts ?? throw new ArgumentNullException(nameof(artifacts));
TestSession = testSession;
Artifacts = artifacts;
}

public Artifact[] Artifacts { get; set; }
Expand All @@ -22,9 +18,9 @@ public TestArtifacts(string testSession, Artifact[] artifacts)

internal class Artifact
{
public Artifact(string fileName, ArtifactType type)
public Artifact(string fileName!!, ArtifactType type)
{
FileName = fileName ?? throw new ArgumentNullException(nameof(fileName));
FileName = fileName;
Type = type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,10 @@ public override XmlElement ToXml()
root.AppendChild(testAdaptersPaths);
}

if (this.TestAdapterLoadingStrategy != TestAdapterLoadingStrategy.Default)
if (TestAdapterLoadingStrategy != TestAdapterLoadingStrategy.Default)
{
XmlElement adapterLoadingStrategy = doc.CreateElement("TestAdapterLoadingStrategy");
adapterLoadingStrategy.InnerXml = this.TestAdapterLoadingStrategy.ToString();
adapterLoadingStrategy.InnerXml = TestAdapterLoadingStrategy.ToString();
root.AppendChild(adapterLoadingStrategy);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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.CommandLine.Processors;

using System;
Expand All @@ -19,9 +17,9 @@ internal class ArtifactProcessingCollectModeProcessor : IArgumentProcessor
/// </summary>
public const string CommandName = "/ArtifactsProcessingMode-Collect";

private Lazy<IArgumentProcessorCapabilities> _metadata;
private Lazy<IArgumentProcessorCapabilities>? _metadata;

private Lazy<IArgumentExecutor> _executor;
private Lazy<IArgumentExecutor>? _executor;

/// <summary>
/// Gets the metadata.
Expand Down Expand Up @@ -74,7 +72,7 @@ internal class ArtifactProcessingCollectModeProcessorCapabilities : BaseArgument
public override HelpContentPriority HelpPriority => HelpContentPriority.None;

// We want to be sure that this command won't show in user help
public override string HelpContentResourceName => null;
public override string? HelpContentResourceName => null;
}

internal enum ArtifactProcessingMode
Expand All @@ -91,12 +89,12 @@ internal class ArtifactProcessingCollectModeProcessorExecutor : IArgumentExecuto
{
private readonly CommandLineOptions _commandLineOptions;

public ArtifactProcessingCollectModeProcessorExecutor(CommandLineOptions options)
public ArtifactProcessingCollectModeProcessorExecutor(CommandLineOptions options!!)
{
_commandLineOptions = options ?? throw new ArgumentNullException(nameof(options));
_commandLineOptions = options;
}

public void Initialize(string argument)
public void Initialize(string? _)
{
_commandLineOptions.ArtifactProcessingMode = ArtifactProcessingMode.Collect;
EqtTrace.Verbose($"ArtifactProcessingPostProcessModeProcessorExecutor.Initialize: ArtifactProcessingMode.Collect");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.CommandLine.Processors;

using System;
Expand All @@ -23,9 +21,9 @@ internal class ArtifactProcessingPostProcessModeProcessor : IArgumentProcessor
/// </summary>
public const string CommandName = "/ArtifactsProcessingMode-PostProcess";

private Lazy<IArgumentProcessorCapabilities> _metadata;
private Lazy<IArgumentProcessorCapabilities>? _metadata;

private Lazy<IArgumentExecutor> _executor;
private Lazy<IArgumentExecutor>? _executor;

/// <summary>
/// Gets the metadata.
Expand Down Expand Up @@ -65,7 +63,7 @@ public Lazy<IArgumentExecutor> Executor
}
}

public static bool ContainsPostProcessCommand(string[] args, IFeatureFlag featureFlag = null)
public static bool ContainsPostProcessCommand(string[]? args, IFeatureFlag? featureFlag = null)
=> (featureFlag ?? FeatureFlag.Instance).IsEnabled(FeatureFlag.ARTIFACTS_POSTPROCESSING) &&
(args?.Contains("--artifactsProcessingMode-postprocess", StringComparer.OrdinalIgnoreCase) == true ||
args?.Contains(CommandName, StringComparer.OrdinalIgnoreCase) == true);
Expand All @@ -82,7 +80,7 @@ internal class ArtifactProcessingPostProcessModeProcessorCapabilities : BaseArgu
public override HelpContentPriority HelpPriority => HelpContentPriority.None;

// We want to be sure that this command won't show in user help
public override string HelpContentResourceName => null;
public override string? HelpContentResourceName => null;

public override bool IsAction => true;
}
Expand All @@ -95,13 +93,13 @@ internal class ArtifactProcessingPostProcessModeProcessorExecutor : IArgumentExe
private readonly CommandLineOptions _commandLineOptions;
private readonly IArtifactProcessingManager _artifactProcessingManage;

public ArtifactProcessingPostProcessModeProcessorExecutor(CommandLineOptions options, IArtifactProcessingManager artifactProcessingManager)
public ArtifactProcessingPostProcessModeProcessorExecutor(CommandLineOptions options!!, IArtifactProcessingManager artifactProcessingManager!!)
{
_commandLineOptions = options ?? throw new ArgumentNullException(nameof(options));
_artifactProcessingManage = artifactProcessingManager ?? throw new ArgumentNullException(nameof(artifactProcessingManager)); ;
_commandLineOptions = options;
_artifactProcessingManage = artifactProcessingManager; ;
}

public void Initialize(string argument)
public void Initialize(string? _)
{
_commandLineOptions.ArtifactProcessingMode = ArtifactProcessingMode.PostProcess;
EqtTrace.Verbose($"ArtifactProcessingPostProcessModeProcessorExecutor.Initialize: ArtifactProcessingMode.PostProcess");
Expand Down
Original file line number Diff line number Diff line change
@@ -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.CommandLine.Processors;

using System;
Expand All @@ -21,9 +19,9 @@ internal class TestSessionCorrelationIdProcessor : IArgumentProcessor
/// </summary>
public const string CommandName = "/TestSessionCorrelationId";

private Lazy<IArgumentProcessorCapabilities> _metadata;
private Lazy<IArgumentProcessorCapabilities>? _metadata;

private Lazy<IArgumentExecutor> _executor;
private Lazy<IArgumentExecutor>? _executor;

/// <summary>
/// Gets the metadata.
Expand Down Expand Up @@ -76,7 +74,7 @@ internal class TestSessionCorrelationIdProcessorCapabilities : BaseArgumentProce
public override HelpContentPriority HelpPriority => HelpContentPriority.None;

// We want to be sure that this command won't show in user help
public override string HelpContentResourceName => null;
public override string? HelpContentResourceName => null;
}

/// <summary>
Expand All @@ -86,12 +84,12 @@ internal class TestSessionCorrelationIdProcessorModeProcessorExecutor : IArgumen
{
private readonly CommandLineOptions _commandLineOptions;

public TestSessionCorrelationIdProcessorModeProcessorExecutor(CommandLineOptions options)
public TestSessionCorrelationIdProcessorModeProcessorExecutor(CommandLineOptions options!!)
{
_commandLineOptions = options ?? throw new ArgumentNullException(nameof(options));
_commandLineOptions = options;
}

public void Initialize(string argument)
public void Initialize(string? argument)
{
if (string.IsNullOrEmpty(argument))
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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.CommandLine.Processors;

/// <summary>
Expand All @@ -28,12 +26,12 @@ internal abstract class BaseArgumentProcessorCapabilities : IArgumentProcessorCa
/// <summary>
/// Gets the short command name.
/// </summary>
public virtual string ShortCommandName => null;
public virtual string? ShortCommandName => null;

/// <summary>
/// Gets the help content resource name.
/// </summary>
public virtual string HelpContentResourceName => null;
public virtual string? HelpContentResourceName => null;

/// <summary>
/// Gets the help priority.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ArtifactProcessingCollectModeProcessorTest
{
[TestMethod]
public void ProcessorExecutorInitialize_ShouldFailIfNullCommandOption() =>
Assert.ThrowsException<ArgumentNullException>(() => new ArtifactProcessingCollectModeProcessorExecutor(null));
Assert.ThrowsException<ArgumentNullException>(() => new ArtifactProcessingCollectModeProcessorExecutor(null!));

[TestMethod]
public void ProcessorExecutorInitialize_ShouldNotFailIfNullArg()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class ArtifactProcessingPostProcessModeProcessorTest
[TestMethod]
public void ProcessorExecutorInitialize_ShouldFailIfNullCtor()
{
Assert.ThrowsException<ArgumentNullException>(() => new ArtifactProcessingPostProcessModeProcessorExecutor(null, _artifactProcessingManagerMock.Object));
Assert.ThrowsException<ArgumentNullException>(() => new ArtifactProcessingPostProcessModeProcessorExecutor(new CommandLineOptions(), null));
Assert.ThrowsException<ArgumentNullException>(() => new ArtifactProcessingPostProcessModeProcessorExecutor(null!, _artifactProcessingManagerMock.Object));
Assert.ThrowsException<ArgumentNullException>(() => new ArtifactProcessingPostProcessModeProcessorExecutor(new CommandLineOptions(), null!));
}

[TestMethod]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class TestSessionCorrelationIdProcessorTests
{
[TestMethod]
public void ProcessorExecutorInitialize_ShouldFailIfNullCommandOption() =>
Assert.ThrowsException<ArgumentNullException>(() => new TestSessionCorrelationIdProcessorModeProcessorExecutor(null));
Assert.ThrowsException<ArgumentNullException>(() => new TestSessionCorrelationIdProcessorModeProcessorExecutor(null!));

[TestMethod]
public void ProcessorExecutorInitialize_ShouldFailIfNullSession()
Expand Down