Skip to content
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 @@ -3,9 +3,10 @@

namespace Microsoft.DotNet.Cli.Utils.Tests
{
[TestClass]
public class TransientSdkResolutionErrorDetectorTests
{
[Fact]
[TestMethod]
public void TransientInBoxSdkResolutionFailureIsDetected()
{
string input =
Expand All @@ -20,13 +21,13 @@ public void TransientInBoxSdkResolutionFailureIsDetected()
TransientSdkResolutionErrorDetector.IsTransientError(input).Should().BeTrue();
}

[Fact]
[TestMethod]
public void NullInputIsNotTransient()
{
TransientSdkResolutionErrorDetector.IsTransientError(null).Should().BeFalse();
}

[Fact]
[TestMethod]
public void SuccessfulBuildIsNotTransient()
{
string input =
Expand All @@ -37,7 +38,7 @@ public void SuccessfulBuildIsNotTransient()
TransientSdkResolutionErrorDetector.IsTransientError(input).Should().BeFalse();
}

[Fact]
[TestMethod]
public void MissingVersionedSdkWithoutResolverNullIsNotTransient()
{
// A genuinely missing, version-specified SDK is a deterministic failure (no workload resolver
Expand All @@ -47,7 +48,7 @@ public void MissingVersionedSdkWithoutResolverNullIsNotTransient()
TransientSdkResolutionErrorDetector.IsTransientError(input).Should().BeFalse();
}

[Fact]
[TestMethod]
public void OtherResolverReturningNullIsNotTransient()
{
// A "returned null" message from a different resolver must not trigger a retry: only the in-box
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.NET.TestFramework.MSTest/SdkTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class SdkTest
/// <summary>
/// Set by the MSTest runtime before each test runs.
/// </summary>
public TestContext TestContext { get; set; } = null!;
public virtual TestContext TestContext { get; set; } = null!;

protected bool? UsingFullFrameworkMSBuild => SdkTestContext.Current.ToolsetUnderTest?.ShouldUseFullFrameworkMSBuild;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ namespace Microsoft.TemplateEngine.TestHelper
public class EnvironmentSettingsHelper : IDisposable
{
private readonly List<string> _foldersToCleanup = new List<string>();
private readonly SharedTestOutputHelper _testOutputHelper;
private readonly SharedTestOutputHelper? _testOutputHelper;

public EnvironmentSettingsHelper(IMessageSink messageSink)
public EnvironmentSettingsHelper(IMessageSink? messageSink = null)
{
_testOutputHelper = new SharedTestOutputHelper(messageSink);
_testOutputHelper = messageSink is not null ? new SharedTestOutputHelper(messageSink) : null;
}

public IEngineEnvironmentSettings CreateEnvironment(
Expand All @@ -35,7 +35,9 @@ public IEngineEnvironmentSettings CreateEnvironment(
locale = "en-US";
}

IEnumerable<ILoggerProvider> loggerProviders = new[] { new XunitLoggerProvider(_testOutputHelper) };
IEnumerable<ILoggerProvider> loggerProviders = _testOutputHelper is not null
? new[] { new XunitLoggerProvider(_testOutputHelper) }
: [];
if (addLoggerProviders != null)
{
loggerProviders = loggerProviders.Concat(addLoggerProviders);
Expand Down
21 changes: 11 additions & 10 deletions test/dotnet.Tests/BuildServerTests/BuildServerProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@

namespace Microsoft.DotNet.Tests.BuildServerTests
{
[TestClass]
public class BuildServerProviderTests : SdkTest
{
public BuildServerProviderTests(ITestOutputHelper log) : base(log)
public BuildServerProviderTests()
{

}

[Fact]
[TestMethod]
public void GivenMSBuildFlagItYieldsMSBuild()
{
var provider = new BuildServerProvider(
Expand All @@ -35,7 +36,7 @@ public void GivenMSBuildFlagItYieldsMSBuild()
.Equal(CliStrings.MSBuildServer);
}

[Fact]
[TestMethod]
public void GivenVBCSCompilerFlagItYieldsVBCSCompiler()
{
var provider = new BuildServerProvider(
Expand All @@ -49,7 +50,7 @@ public void GivenVBCSCompilerFlagItYieldsVBCSCompiler()
.Equal(CliStrings.VBCSCompilerServer);
}

[Fact]
[TestMethod]
public void GivenRazorFlagAndNoPidDirectoryTheEnumerationIsEmpty()
{
var provider = new BuildServerProvider(
Expand All @@ -62,7 +63,7 @@ public void GivenRazorFlagAndNoPidDirectoryTheEnumerationIsEmpty()
.BeEmpty();
}

[Fact]
[TestMethod]
public void GivenNoEnvironmentVariableItUsesTheDefaultPidDirectory()
{
var provider = new BuildServerProvider(
Expand All @@ -79,7 +80,7 @@ public void GivenNoEnvironmentVariableItUsesTheDefaultPidDirectory()
"build"));
}

[Fact]
[TestMethod]
public void GivenEnvironmentVariableItUsesItForThePidDirectory()
{
IFileSystem fileSystem = new FileSystemMockBuilder().UseCurrentSystemTemporaryDirectory().Build();
Expand All @@ -95,7 +96,7 @@ public void GivenEnvironmentVariableItUsesItForThePidDirectory()
.Be(pidDirectory);
}

[Fact]
[TestMethod]
public void GivenARazorPidFileItReturnsARazorBuildServer()
{
const int ProcessId = 1234;
Expand Down Expand Up @@ -134,9 +135,9 @@ public void GivenARazorPidFileItReturnsARazorBuildServer()
razorServer.PidFile.PipeName.Should().Be(PipeName);
}

[Theory]
[InlineData(typeof(UnauthorizedAccessException))]
[InlineData(typeof(IOException))]
[TestMethod]
[DataRow(typeof(UnauthorizedAccessException))]
[DataRow(typeof(IOException))]
public void GivenAnExceptionAccessingTheRazorPidFileItPrintsAWarning(Type exceptionType)
{
const int ProcessId = 1234;
Expand Down
7 changes: 4 additions & 3 deletions test/dotnet.Tests/BuildServerTests/RazorServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

namespace Microsoft.DotNet.Tests.BuildServerTests
{
[TestClass]
public class RazorServerTests
{
[Fact]
[TestMethod]
public void GivenAFailedShutdownCommandItThrows()
{
const int ProcessId = 1234;
Expand Down Expand Up @@ -56,7 +57,7 @@ public void GivenAFailedShutdownCommandItThrows()
fileSystemMock.File.Exists(pidFilePath).Should().BeTrue();
}

[Fact]
[TestMethod]
public void GivenASuccessfulShutdownItDoesNotThrow()
{
const int ProcessId = 1234;
Expand Down Expand Up @@ -90,7 +91,7 @@ public void GivenASuccessfulShutdownItDoesNotThrow()
fileSystemMock.File.Exists(pidFilePath).Should().BeFalse();
}

[Fact]
[TestMethod]
public void GivenANonExistingRazorServerPathItDeletesPidFileAndDoesNotThrow()
{
const int ProcessId = 1234;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@

namespace Microsoft.DotNet.Tests.BuildServerTests
{
[TestClass]
public class VBCSCompilerServerTests
{
[Fact]
[TestMethod]
public void GivenAZeroExitShutdownDoesNotThrow()
{
var server = new VBCSCompilerServer(CreateCommandFactoryMock().Object);
server.Shutdown();
}

[Fact]
[TestMethod]
public void GivenANonZeroExitCodeShutdownThrows()
{
const string ErrorMessage = "failed!";
Expand Down
5 changes: 3 additions & 2 deletions test/dotnet.Tests/BundledTargetFramworkTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@

namespace Microsoft.DotNet.Tests
{
[TestClass]
public class BundledTargetFrameworkTests : SdkTest
{
public BundledTargetFrameworkTests(ITestOutputHelper log) : base(log)
public BundledTargetFrameworkTests()
{
}

[Fact]
[TestMethod]
public void VersionCommandDisplaysCorrectVersion()
{
var filePath = Path.Combine(
Expand Down
27 changes: 14 additions & 13 deletions test/dotnet.Tests/CliSchemaTests.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.DotNet.Cli;
using Microsoft.DotNet.Cli.Utils;

namespace Microsoft.DotNet.Tests;

[TestClass]
public class CliSchemaTests : SdkTest
{
public CliSchemaTests(ITestOutputHelper log) : base(log)
public CliSchemaTests()
{
}

Expand Down Expand Up @@ -1193,17 +1194,17 @@ public CliSchemaTests(ITestOutputHelper log) : base(log)
}
""";

public static TheoryData<string[], string> CommandsJson => new()
{
{ new[] { "solution", "list", "--cli-schema" }, SolutionListJson },
{ new[] { "clean", "--cli-schema" }, CleanJson },
{ new[] { "reference", "--cli-schema" }, ReferenceJson },
{ new[] { "workload", "install", "--cli-schema" }, WorkloadInstallJson },
{ new[] { "build", "--cli-schema" }, BuildJson }
};
public static IEnumerable<object[]> CommandsJson =>
[
[new[] { "solution", "list", "--cli-schema" }, SolutionListJson],
[new[] { "clean", "--cli-schema" }, CleanJson],
[new[] { "reference", "--cli-schema" }, ReferenceJson],
[new[] { "workload", "install", "--cli-schema" }, WorkloadInstallJson],
[new[] { "build", "--cli-schema" }, BuildJson]
];

[Theory]
[MemberData(nameof(CommandsJson))]
[TestMethod]
[DynamicData(nameof(CommandsJson))]
public void PrintCliSchema_WritesExpectedJson(string[] commandArgs, string json)
{
var stream = new MemoryStream();
Expand All @@ -1215,7 +1216,7 @@ public void PrintCliSchema_WritesExpectedJson(string[] commandArgs, string json)
output.Should().BeVisuallyEquivalentTo(json);
}

[Fact]
[TestMethod]
public void CanGenerateJsonSchemaForCLIOutput()
{
var schema = CliSchema.GetJsonSchema();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

namespace Microsoft.DotNet.Tests
{
[TestClass]
public class GivenACompositeCommandResolver
{
[Fact]
[TestMethod]
public void It_iterates_through_all_added_resolvers_in_order_when_they_return_null()
{
var compositeCommandResolver = new CompositeCommandResolver();
Expand Down Expand Up @@ -42,7 +43,7 @@ public void It_iterates_through_all_added_resolvers_in_order_when_they_return_nu

}

[Fact]
[TestMethod]
public void It_stops_iterating_through_added_resolvers_when_one_returns_nonnull()
{
var compositeCommandResolver = new CompositeCommandResolver();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

namespace Microsoft.DotNet.Tests
{
[TestClass]
public class GivenADefaultCommandResolver
{
[Fact]
[TestMethod]
public void It_contains_resolvers_in_the_right_order()
{
var defaultCommandResolver = DefaultCommandResolverPolicy.Create();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
namespace Microsoft.DotNet.Tests
{

[TestClass]
public class GivenADotnetToolsCommandResolver : SdkTest
{
private readonly DotnetToolsCommandResolver _dotnetToolsCommandResolver;

public GivenADotnetToolsCommandResolver(ITestOutputHelper log) : base(log)
public GivenADotnetToolsCommandResolver()
{
var dotnetToolPath = Path.Combine(SdkTestContext.Current.ToolsetUnderTest.SdkFolderUnderTest, "DotnetTools");
_dotnetToolsCommandResolver = new DotnetToolsCommandResolver(dotnetToolPath);
}

[Fact]
[TestMethod]
public void ItReturnsNullWhenCommandNameIsNull()
{
var commandResolverArguments = new CommandResolverArguments()
Expand All @@ -31,7 +32,7 @@ public void ItReturnsNullWhenCommandNameIsNull()
result.Should().BeNull();
}

[Fact]
[TestMethod]
public void ItReturnsNullWhenCommandNameDoesNotExistInProjectTools()
{
var commandResolverArguments = new CommandResolverArguments()
Expand All @@ -44,7 +45,7 @@ public void ItReturnsNullWhenCommandNameDoesNotExistInProjectTools()
result.Should().BeNull();
}

[Fact]
[TestMethod]
public void ItReturnsACommandSpec()
{
var commandResolverArguments = new CommandResolverArguments()
Expand All @@ -60,7 +61,7 @@ public void ItReturnsACommandSpec()
commandPath.Should().Contain("dotnet-watch.dll");
}

[Fact]
[TestMethod]
public void ItReturnsAnExecutableCommandSpecWhenExecutableExists()
{
var dotnetToolPath = TestAssetsManager.CreateTestDirectory().Path;
Expand Down
Loading
Loading