Merge branch 'rel/1.0.0' of https://github.com/dotnet/cli into cli-x86-support
This commit is contained in:
commit
01d2656be1
132 changed files with 4399 additions and 527 deletions
|
@ -69,10 +69,14 @@ try {
|
|||
|
||||
Write-Host "Running installer tests in Windows Container"
|
||||
|
||||
# --net="none" works around a networking issue on the containers on the CI machines.
|
||||
# Since our installer tests don't require the network, it is fine to shut it off.
|
||||
$MsiFileName = [System.IO.Path]::GetFileName($inputMsi)
|
||||
docker run `
|
||||
--rm `
|
||||
-v "$testBin\:D:" `
|
||||
-e "CLI_MSI=D:\$MsiFileName" `
|
||||
--net="none" `
|
||||
windowsservercore `
|
||||
D:\xunit.console.exe D:\$testName.dll | Out-Host
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
{
|
||||
private string _projectPath;
|
||||
private string _outputDirectory;
|
||||
private string _buildBasePath;
|
||||
private string _tempOutputDirectory;
|
||||
private string _configuration;
|
||||
private string _versionSuffix;
|
||||
|
@ -23,6 +24,15 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
$"-o \"{_outputDirectory}\"";
|
||||
}
|
||||
}
|
||||
private string BuildBasePathOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _buildBasePath == string.Empty ?
|
||||
"" :
|
||||
$"-b \"{_buildBasePath}\"";
|
||||
}
|
||||
}
|
||||
|
||||
private string TempOutputOption
|
||||
{
|
||||
|
@ -55,8 +65,9 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
}
|
||||
|
||||
public PackCommand(
|
||||
string projectPath,
|
||||
string output="",
|
||||
string projectPath,
|
||||
string output = "",
|
||||
string buildBasePath = "",
|
||||
string tempOutput="",
|
||||
string configuration="",
|
||||
string versionSuffix="")
|
||||
|
@ -64,6 +75,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
{
|
||||
_projectPath = projectPath;
|
||||
_outputDirectory = output;
|
||||
_buildBasePath = buildBasePath;
|
||||
_tempOutputDirectory = tempOutput;
|
||||
_configuration = configuration;
|
||||
_versionSuffix = versionSuffix;
|
||||
|
@ -77,7 +89,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
|
||||
private string BuildArgs()
|
||||
{
|
||||
return $"{_projectPath} {OutputOption} {TempOutputOption} {ConfigurationOption} {VersionSuffixOption}";
|
||||
return $"{_projectPath} {OutputOption} {BuildBasePathOption} {TempOutputOption} {ConfigurationOption} {VersionSuffixOption}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,94 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text;
|
||||
using Microsoft.Extensions.DependencyModel;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyModel.Tests
|
||||
{
|
||||
public class DependencyContextCsvReaderTests
|
||||
{
|
||||
private DependencyContext Read(string text)
|
||||
{
|
||||
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(text)))
|
||||
{
|
||||
return new DependencyContextCsvReader().Read(stream);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GroupsAssetsCorrectlyIntoLibraries()
|
||||
{
|
||||
var context = Read(@"
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.Runtime.dll""
|
||||
");
|
||||
context.RuntimeLibraries.Should().HaveCount(1);
|
||||
var library = context.RuntimeLibraries.Single();
|
||||
library.LibraryType.Should().Be("Package");
|
||||
library.PackageName.Should().Be("runtime.any.System.AppContext");
|
||||
library.Version.Should().Be("4.1.0-rc2-23811");
|
||||
library.Hash.Should().Be("sha512-1");
|
||||
library.Assemblies.Should().HaveCount(2).And
|
||||
.Contain(a => a.Path == "lib\\dnxcore50\\System.AppContext.dll").And
|
||||
.Contain(a => a.Path == "lib\\dnxcore50\\System.Runtime.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IgnoresAllButRuntimeAssets()
|
||||
{
|
||||
var context = Read(@"
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""native"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext2.so""
|
||||
");
|
||||
context.RuntimeLibraries.Should().HaveCount(1);
|
||||
var library = context.RuntimeLibraries.Single();
|
||||
library.Assemblies.Should().HaveCount(1).And
|
||||
.Contain(a => a.Path == "lib\\dnxcore50\\System.AppContext.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void IgnoresNiDllAssemblies()
|
||||
{
|
||||
var context = Read(@"
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.ni.dll""
|
||||
");
|
||||
context.RuntimeLibraries.Should().HaveCount(1);
|
||||
var library = context.RuntimeLibraries.Single();
|
||||
library.Assemblies.Should().HaveCount(1).And
|
||||
.Contain(a => a.Path == "lib\\dnxcore50\\System.AppContext.dll");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void UsesTypeNameVersionAndHashToGroup()
|
||||
{
|
||||
var context = Read(@"
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23812"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-2"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Package"",""runtime.any.System.AppContext2"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
""Project"",""runtime.any.System.AppContext"",""4.1.0-rc2-23811"",""sha512-1"",""runtime"",""System.AppContext"",""lib\\dnxcore50\\System.AppContext.dll""
|
||||
");
|
||||
context.RuntimeLibraries.Should().HaveCount(5);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("text")]
|
||||
[InlineData(" ")]
|
||||
[InlineData("\"")]
|
||||
[InlineData(@""",""")]
|
||||
[InlineData(@"\\")]
|
||||
public void ThrowsFormatException(string intput)
|
||||
{
|
||||
Assert.Throws<FormatException>(() => Read(intput));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,10 +3,12 @@
|
|||
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
using NuGet.Frameworks;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Builder.Tests
|
||||
|
@ -128,6 +130,42 @@ namespace Microsoft.DotNet.Tools.Builder.Tests
|
|||
informationalVersion.Should().BeEquivalentTo("1.0.0-85");
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("net461", true, true)]
|
||||
[InlineData("dnxcore50", true, false)]
|
||||
public void MultipleFrameworks_ShouldHaveValidTargetFrameworkAttribute(string frameworkName, bool shouldHaveTargetFrameworkAttribute, bool windowsOnly)
|
||||
{
|
||||
var framework = NuGetFramework.Parse(frameworkName);
|
||||
|
||||
var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithMultipleFrameworks")
|
||||
.WithLockFiles();
|
||||
|
||||
var cmd = new BuildCommand(Path.Combine(testInstance.TestRoot, Project.FileName), framework: framework.GetShortFolderName());
|
||||
|
||||
if (windowsOnly && !RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||
{
|
||||
// on non-windows platforms, desktop frameworks will not build
|
||||
cmd.ExecuteWithCapturedOutput().Should().Fail();
|
||||
}
|
||||
else
|
||||
{
|
||||
cmd.ExecuteWithCapturedOutput().Should().Pass();
|
||||
|
||||
var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", framework.GetShortFolderName(), "TestLibraryWithMultipleFrameworks.dll");
|
||||
var targetFramework = PeReaderUtils.GetAssemblyAttributeValue(output, "TargetFrameworkAttribute");
|
||||
|
||||
if (shouldHaveTargetFrameworkAttribute)
|
||||
{
|
||||
targetFramework.Should().NotBeNull();
|
||||
targetFramework.Should().BeEquivalentTo(framework.DotNetFrameworkName);
|
||||
}
|
||||
else
|
||||
{
|
||||
targetFramework.Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ResourceTest()
|
||||
{
|
||||
|
|
36
test/dotnet-build.Tests/WrappedProjectTests.cs
Normal file
36
test/dotnet-build.Tests/WrappedProjectTests.cs
Normal file
|
@ -0,0 +1,36 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Builder.Tests
|
||||
{
|
||||
public class WrappedProjectTests: TestBase
|
||||
{
|
||||
[Fact]
|
||||
public void WrappedProjectFilesResolvedCorrectly()
|
||||
{
|
||||
var testInstance = TestAssetsManager.CreateTestInstance("TestAppWithWrapperProjectDependency")
|
||||
.WithBuildArtifacts()
|
||||
.WithLockFiles();
|
||||
|
||||
var root = testInstance.TestRoot;
|
||||
|
||||
// run compile
|
||||
var outputDir = Path.Combine(root, "bin");
|
||||
var testProject = ProjectUtils.GetProjectJson(root, "TestApp");
|
||||
var buildCommand = new BuildCommand(testProject, output: outputDir, framework: DefaultFramework);
|
||||
var result = buildCommand.ExecuteWithCapturedOutput();
|
||||
result.Should().Pass();
|
||||
|
||||
new DirectoryInfo(outputDir).Should()
|
||||
.HaveFiles(new [] { "TestLibrary.dll", "TestLibrary.pdb" });
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using FluentAssertions;
|
||||
using Xunit;
|
||||
|
@ -146,6 +147,26 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
result.StdOut.Should().Contain("MyNamespace.Util");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EmbeddedDependencyContextIsValidOnBuild()
|
||||
{
|
||||
var testProjectPath = Path.Combine(RepoRoot, "TestAssets", "TestProjects", "DependencyContextValidator", "TestApp");
|
||||
var testProject = Path.Combine(testProjectPath, "project.json");
|
||||
|
||||
var runCommand = new RunCommand(testProject);
|
||||
runCommand.Execute().Should().Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DepsDependencyContextIsValidOnBuild()
|
||||
{
|
||||
var testProjectPath = Path.Combine(RepoRoot, "TestAssets", "TestProjects", "DependencyContextValidator", "TestAppDeps");
|
||||
var testProject = Path.Combine(testProjectPath, "project.json");
|
||||
|
||||
var runCommand = new RunCommand(testProject);
|
||||
runCommand.Execute().Should().Pass();
|
||||
}
|
||||
|
||||
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
||||
{
|
||||
// copy all the files to temp dir
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
},
|
||||
|
||||
"content": [
|
||||
"../../TestAssets/TestProjects/DependencyContextValidator/**/*",
|
||||
"../../TestAssets/TestProjects/TestLibraryWithAnalyzer/*",
|
||||
"../../TestAssets/TestProjects/TestAppWithLibrary/TestLibrary/*",
|
||||
"../../TestAssets/TestProjects/TestProjectWithCultureSpecificResource/*",
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
|
@ -78,6 +79,22 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
File.Exists(outputPackage).Should().BeTrue(outputPackage);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasBuildOutputWhenUsingBuildBasePath()
|
||||
{
|
||||
var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithConfiguration")
|
||||
.WithLockFiles();
|
||||
|
||||
var cmd = new PackCommand(Path.Combine(testInstance.TestRoot, Project.FileName), buildBasePath: "buildBase");
|
||||
cmd.Execute().Should().Pass();
|
||||
|
||||
var outputPackage = Path.Combine(testInstance.TestRoot, "bin", "Debug", "TestLibraryWithConfiguration.1.0.0.nupkg");
|
||||
File.Exists(outputPackage).Should().BeTrue(outputPackage);
|
||||
|
||||
var zip = ZipFile.Open(outputPackage, ZipArchiveMode.Read);
|
||||
zip.Entries.Should().Contain(e => e.FullName == "lib/dnxcore50/TestLibraryWithConfiguration.dll");
|
||||
}
|
||||
|
||||
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
||||
{
|
||||
// copy all the files to temp dir
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23811",
|
||||
|
||||
"System.IO.Compression.ZipFile": "4.0.1-rc2-23811",
|
||||
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"target": "project"
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Microsoft.Extensions.PlatformAbstractions;
|
||||
|
@ -163,7 +164,6 @@ namespace Microsoft.DotNet.Tools.Publish.Tests
|
|||
refsDirectory.Should().NotHaveFile("TestLibrary.dll");
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void CompilationFailedTest()
|
||||
{
|
||||
|
|
|
@ -3,38 +3,41 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.DotNet.TestFramework;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Compiler.Tests
|
||||
namespace Microsoft.DotNet.Tools.Run.Tests
|
||||
{
|
||||
public class CompilerTests : TestBase
|
||||
public class RunTests : TestBase
|
||||
{
|
||||
private static const string RunTestsBase = "RunTestsApps";
|
||||
private const string RunTestsBase = "RunTestsApps";
|
||||
|
||||
[WindowsOnlyFact]
|
||||
public void RunsSingleTarget()
|
||||
{
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine(RunTestsBase, "TestAppDesktopClr"))
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine(RunTestsBase, "TestAppFullClr"))
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
new RunCommand(testInstance.TestRoot).Execute().Should().Pass();
|
||||
new RunCommand(instance.TestRoot).Execute().Should().Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void RunsDefaultWhenPresent()
|
||||
{
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine(RunTestsBase, "TestAppMultiTarget"))
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
new RunCommand(testInstance.TestRoot).Execute().Should().Pass();
|
||||
new RunCommand(instance.TestRoot).Execute().Should().Pass();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void FailsWithMultipleTargetAndNoDefault()
|
||||
{
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance(RunTestsBase, "TestAppMultiTargetNoCoreClr")
|
||||
TestInstance instance = TestAssetsManager.CreateTestInstance(Path.Combine(RunTestsBase, "TestAppMultiTargetNoCoreClr"))
|
||||
.WithLockFiles()
|
||||
.WithBuildArtifacts();
|
||||
new RunCommand(testInstance.TestRoot).Execute().Should().Fail();
|
||||
new RunCommand(instance.TestRoot).Execute().Should().Fail();
|
||||
}
|
||||
|
||||
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
||||
|
|
76
test/dotnet-test.UnitTests/DotnetTestMessageScenario.cs
Normal file
76
test/dotnet-test.UnitTests/DotnetTestMessageScenario.cs
Normal file
|
@ -0,0 +1,76 @@
|
|||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class DotnetTestMessageScenario
|
||||
{
|
||||
private TestMessagesCollection _messages;
|
||||
private const string AssemblyUnderTest = "assembly.dll";
|
||||
private const string TestRunner = "testRunner";
|
||||
private const int Port = 1;
|
||||
|
||||
public DotnetTest DotnetTestUnderTest { get; private set; }
|
||||
public Mock<ITestRunner> TestRunnerMock { get; private set; }
|
||||
public Mock<IReportingChannel> AdapterChannelMock { get; private set; }
|
||||
public Mock<IReportingChannel> TestRunnerChannelMock { get; private set; }
|
||||
|
||||
public DotnetTestMessageScenario()
|
||||
{
|
||||
_messages = new TestMessagesCollection();
|
||||
DotnetTestUnderTest = new DotnetTest(_messages, AssemblyUnderTest);
|
||||
TestRunnerChannelMock = new Mock<IReportingChannel>();
|
||||
TestRunnerMock = new Mock<ITestRunner>();
|
||||
AdapterChannelMock = new Mock<IReportingChannel>();
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
var reportingChannelFactoryMock = new Mock<IReportingChannelFactory>();
|
||||
reportingChannelFactoryMock
|
||||
.Setup(r => r.CreateChannelWithAnyAvailablePort())
|
||||
.Returns(TestRunnerChannelMock.Object);
|
||||
|
||||
var commandFactoryMock = new Mock<ICommandFactory>();
|
||||
|
||||
var testRunnerFactoryMock = new Mock<ITestRunnerFactory>();
|
||||
testRunnerFactoryMock
|
||||
.Setup(t => t.CreateTestRunner(It.IsAny<DiscoverTestsArgumentsBuilder>()))
|
||||
.Returns(TestRunnerMock.Object);
|
||||
|
||||
testRunnerFactoryMock
|
||||
.Setup(t => t.CreateTestRunner(It.IsAny<RunTestsArgumentsBuilder>()))
|
||||
.Returns(TestRunnerMock.Object);
|
||||
|
||||
var reportingChannelFactory = reportingChannelFactoryMock.Object;
|
||||
var adapterChannel = AdapterChannelMock.Object;
|
||||
var commandFactory = commandFactoryMock.Object;
|
||||
var testRunnerFactory = testRunnerFactoryMock.Object;
|
||||
|
||||
using (DotnetTestUnderTest)
|
||||
{
|
||||
DotnetTestUnderTest
|
||||
.AddNonSpecificMessageHandlers(_messages, adapterChannel)
|
||||
.AddTestDiscoveryMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory)
|
||||
.AddTestRunMessageHandlers(adapterChannel, reportingChannelFactory, testRunnerFactory)
|
||||
.AddTestRunnnersMessageHandlers(adapterChannel);
|
||||
|
||||
DotnetTestUnderTest.StartListeningTo(adapterChannel);
|
||||
|
||||
AdapterChannelMock.Raise(r => r.MessageReceived += null, DotnetTestUnderTest, new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.VersionCheck,
|
||||
Payload = JToken.FromObject(new ProtocolVersionMessage { Version = 1 })
|
||||
});
|
||||
|
||||
DotnetTestUnderTest.StartHandlingMessages();
|
||||
}
|
||||
|
||||
AdapterChannelMock.Verify();
|
||||
TestRunnerMock.Verify();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenADiscoverTestsArgumentsBuilder
|
||||
{
|
||||
[Fact]
|
||||
public void It_generates_the_right_arguments_for_DiscoverTests()
|
||||
{
|
||||
const int port = 1;
|
||||
const string assembly = "assembly.dll";
|
||||
|
||||
var discoverTestsArgumentsBuilder = new DiscoverTestsArgumentsBuilder(assembly, port);
|
||||
|
||||
var arguments = discoverTestsArgumentsBuilder.BuildArguments();
|
||||
|
||||
arguments.Should().BeEquivalentTo(assembly, "--list", "--designtime", "--port", $"{port}");
|
||||
}
|
||||
}
|
||||
}
|
157
test/dotnet-test.UnitTests/GivenADotnetTestApp.cs
Normal file
157
test/dotnet-test.UnitTests/GivenADotnetTestApp.cs
Normal file
|
@ -0,0 +1,157 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenADotnetTestApp
|
||||
{
|
||||
private const string AssemblyUnderTest = "assembly.dll";
|
||||
|
||||
private Mock<IReportingChannel> _reportingChannelMock;
|
||||
private Mock<IDotnetTestMessageHandler> _noOpMessageHandlerMock;
|
||||
private Mock<IDotnetTestMessageHandler> _realMessageHandlerMock;
|
||||
private Mock<IDotnetTestMessageHandler> _unknownMessageHandlerMock;
|
||||
private DotnetTest _dotnetTest;
|
||||
|
||||
public GivenADotnetTestApp()
|
||||
{
|
||||
_noOpMessageHandlerMock = new Mock<IDotnetTestMessageHandler>();
|
||||
_noOpMessageHandlerMock
|
||||
.Setup(mh => mh.HandleMessage(It.IsAny<DotnetTest>(), It.IsAny<Message>()))
|
||||
.Returns(DotnetTestState.NoOp)
|
||||
.Verifiable();
|
||||
|
||||
_realMessageHandlerMock = new Mock<IDotnetTestMessageHandler>();
|
||||
_realMessageHandlerMock
|
||||
.Setup(mh => mh.HandleMessage(It.IsAny<DotnetTest>(), It.Is<Message>(m => m.MessageType == "Test message")))
|
||||
.Returns(DotnetTestState.VersionCheckCompleted).Callback(() =>
|
||||
_reportingChannelMock.Raise(r => r.MessageReceived += null, _dotnetTest, new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestSessionTerminate
|
||||
}));
|
||||
|
||||
_reportingChannelMock = new Mock<IReportingChannel>();
|
||||
_unknownMessageHandlerMock = new Mock<IDotnetTestMessageHandler>();
|
||||
_unknownMessageHandlerMock
|
||||
.Setup(mh => mh.HandleMessage(It.IsAny<DotnetTest>(), It.IsAny<Message>()))
|
||||
.Throws<InvalidOperationException>();
|
||||
|
||||
var testMessagesCollection = new TestMessagesCollection();
|
||||
_dotnetTest = new DotnetTest(testMessagesCollection, AssemblyUnderTest)
|
||||
{
|
||||
TestSessionTerminateMessageHandler = new TestSessionTerminateMessageHandler(testMessagesCollection),
|
||||
UnknownMessageHandler = _unknownMessageHandlerMock.Object
|
||||
};
|
||||
|
||||
_dotnetTest.StartListeningTo(_reportingChannelMock.Object);
|
||||
|
||||
_reportingChannelMock.Raise(r => r.MessageReceived += null, _dotnetTest, new Message
|
||||
{
|
||||
MessageType = "Test message"
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DotnetTest_handles_TestSession_Terminate_messages_implicitly()
|
||||
{
|
||||
_reportingChannelMock.Raise(r => r.MessageReceived += null, _dotnetTest, new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestSessionTerminate
|
||||
});
|
||||
|
||||
_dotnetTest.StartHandlingMessages();
|
||||
|
||||
//just the fact that we are not hanging means we stopped waiting for messages
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DotnetTest_calls_each_MessageHandler_until_one_returns_a_state_different_from_NoOp()
|
||||
{
|
||||
var secondNoOpMessageHandler = new Mock<IDotnetTestMessageHandler>();
|
||||
|
||||
_dotnetTest
|
||||
.AddMessageHandler(_noOpMessageHandlerMock.Object)
|
||||
.AddMessageHandler(_realMessageHandlerMock.Object)
|
||||
.AddMessageHandler(secondNoOpMessageHandler.Object);
|
||||
|
||||
_dotnetTest.StartHandlingMessages();
|
||||
|
||||
_noOpMessageHandlerMock.Verify();
|
||||
_realMessageHandlerMock.Verify();
|
||||
secondNoOpMessageHandler.Verify(
|
||||
mh => mh.HandleMessage(It.IsAny<DotnetTest>(), It.IsAny<Message>()),
|
||||
Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DotnetTest_does_not_send_an_error_when_the_message_gets_handled()
|
||||
{
|
||||
_dotnetTest.AddMessageHandler(_realMessageHandlerMock.Object);
|
||||
|
||||
_dotnetTest.StartHandlingMessages();
|
||||
|
||||
_reportingChannelMock.Verify(r => r.SendError(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DotnetTest_calls_the_unknown_message_handler_when_the_message_is_not_handled()
|
||||
{
|
||||
_dotnetTest.AddMessageHandler(_noOpMessageHandlerMock.Object);
|
||||
|
||||
Action action = () => _dotnetTest.StartHandlingMessages();
|
||||
|
||||
action.ShouldThrow<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_throws_an_InvalidOperationException_if_StartListening_is_called_without_setting_a_TestSessionTerminateMessageHandler()
|
||||
{
|
||||
var dotnetTest = new DotnetTest(new TestMessagesCollection(), AssemblyUnderTest)
|
||||
{
|
||||
UnknownMessageHandler = new Mock<IDotnetTestMessageHandler>().Object
|
||||
};
|
||||
|
||||
Action action = () => dotnetTest.StartListeningTo(new Mock<IReportingChannel>().Object);
|
||||
|
||||
action.ShouldThrow<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_throws_an_InvalidOperationException_if_StartListeningTo_is_called_without_setting_a_UnknownMessageHandler()
|
||||
{
|
||||
var dotnetTest = new DotnetTest(new TestMessagesCollection(), AssemblyUnderTest)
|
||||
{
|
||||
TestSessionTerminateMessageHandler = new Mock<IDotnetTestMessageHandler>().Object
|
||||
};
|
||||
|
||||
Action action = () => dotnetTest.StartListeningTo(new Mock<IReportingChannel>().Object);
|
||||
|
||||
action.ShouldThrow<InvalidOperationException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_disposes_all_reporting_channels_that_it_was_listening_to_when_it_gets_disposed()
|
||||
{
|
||||
var firstReportingChannelMock = new Mock<IReportingChannel>();
|
||||
var secondReportingChannelMock = new Mock<IReportingChannel>();
|
||||
using (var dotnetTest = new DotnetTest(new TestMessagesCollection(), AssemblyUnderTest))
|
||||
{
|
||||
dotnetTest.TestSessionTerminateMessageHandler = new Mock<IDotnetTestMessageHandler>().Object;
|
||||
dotnetTest.UnknownMessageHandler = new Mock<IDotnetTestMessageHandler>().Object;
|
||||
|
||||
dotnetTest.StartListeningTo(firstReportingChannelMock.Object);
|
||||
dotnetTest.StartListeningTo(secondReportingChannelMock.Object);
|
||||
}
|
||||
|
||||
firstReportingChannelMock.Verify(r => r.Dispose(), Times.Once);
|
||||
secondReportingChannelMock.Verify(r => r.Dispose(), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
41
test/dotnet-test.UnitTests/GivenARunTestsArgumentsBuilder.cs
Normal file
41
test/dotnet-test.UnitTests/GivenARunTestsArgumentsBuilder.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenARunTestsArgumentsBuilder
|
||||
{
|
||||
[Fact]
|
||||
public void It_generates_the_right_arguments_for_RunTests()
|
||||
{
|
||||
const int port = 1;
|
||||
const string assembly = "assembly.dll";
|
||||
|
||||
var message = new Message
|
||||
{
|
||||
Payload = JToken.FromObject(new RunTestsMessage { Tests = new List<string> { "test1", "test2" } })
|
||||
};
|
||||
|
||||
var runTestsArgumentsBuilder = new RunTestsArgumentsBuilder(assembly, port, message);
|
||||
|
||||
var arguments = runTestsArgumentsBuilder.BuildArguments();
|
||||
|
||||
arguments.Should().BeEquivalentTo(
|
||||
assembly,
|
||||
"--designtime",
|
||||
"--port",
|
||||
$"{port}",
|
||||
"--test",
|
||||
"test1",
|
||||
"--test",
|
||||
"test2");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,174 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Cli.Tools.Test;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenATestDiscoveryStartMessageHandler
|
||||
{
|
||||
private const int TestRunnerPort = 1;
|
||||
private const string AssemblyUnderTest = "assembly.dll";
|
||||
|
||||
private TestDiscoveryStartMessageHandler _testDiscoveryStartMessageHandler;
|
||||
private IDotnetTest _dotnetTestAtVersionCheckCompletedState;
|
||||
private Message _validMessage;
|
||||
private Mock<ITestRunnerFactory> _testRunnerFactoryMock;
|
||||
private Mock<ITestRunner> _testRunnerMock;
|
||||
private Mock<IReportingChannel> _adapterChannelMock;
|
||||
private Mock<IReportingChannel> _testRunnerChannelMock;
|
||||
private Mock<IReportingChannelFactory> _reportingChannelFactoryMock;
|
||||
private DiscoverTestsArgumentsBuilder _argumentsBuilder;
|
||||
private Mock<IDotnetTest> _dotnetTestMock;
|
||||
|
||||
public GivenATestDiscoveryStartMessageHandler()
|
||||
{
|
||||
_dotnetTestMock = new Mock<IDotnetTest>();
|
||||
_dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.VersionCheckCompleted);
|
||||
_dotnetTestMock.Setup(d => d.PathToAssemblyUnderTest).Returns(AssemblyUnderTest);
|
||||
_dotnetTestAtVersionCheckCompletedState = _dotnetTestMock.Object;
|
||||
|
||||
_testRunnerMock = new Mock<ITestRunner>();
|
||||
_testRunnerFactoryMock = new Mock<ITestRunnerFactory>();
|
||||
_testRunnerFactoryMock
|
||||
.Setup(c => c.CreateTestRunner(It.IsAny<DiscoverTestsArgumentsBuilder>()))
|
||||
.Callback<ITestRunnerArgumentsBuilder>(r => _argumentsBuilder = r as DiscoverTestsArgumentsBuilder)
|
||||
.Returns(_testRunnerMock.Object);
|
||||
|
||||
_adapterChannelMock = new Mock<IReportingChannel>();
|
||||
|
||||
_testRunnerChannelMock = new Mock<IReportingChannel>();
|
||||
_testRunnerChannelMock.Setup(t => t.Port).Returns(TestRunnerPort);
|
||||
|
||||
_reportingChannelFactoryMock = new Mock<IReportingChannelFactory>();
|
||||
_reportingChannelFactoryMock.Setup(r =>
|
||||
r.CreateChannelWithAnyAvailablePort()).Returns(_testRunnerChannelMock.Object);
|
||||
|
||||
_testDiscoveryStartMessageHandler = new TestDiscoveryStartMessageHandler(
|
||||
_testRunnerFactoryMock.Object,
|
||||
_adapterChannelMock.Object,
|
||||
_reportingChannelFactoryMock.Object);
|
||||
|
||||
_validMessage = new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestDiscoveryStart
|
||||
};
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_VersionCheckCompleted_or_InitialState()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
||||
|
||||
var nextState = _testDiscoveryStartMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
new Message { MessageType = TestMessageTypes.TestDiscoveryStart });
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_message_is_not_TestDiscoveryStart()
|
||||
{
|
||||
var nextState = _testDiscoveryStartMessageHandler.HandleMessage(
|
||||
_dotnetTestAtVersionCheckCompletedState,
|
||||
new Message { MessageType = "Something different from TestDiscovery.Start" });
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestDiscoveryCompleted_when_it_handles_the_message_and_current_state_is_InitialState()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.InitialState);
|
||||
|
||||
var nextState =
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(dotnetTestMock.Object, _validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestDiscoveryStarted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestDiscoveryCompleted_when_it_handles_the_message_and_current_state_is_VersionCheckCompleted()
|
||||
{
|
||||
var nextState =
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(_dotnetTestAtVersionCheckCompletedState, _validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestDiscoveryStarted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_uses_the_test_runner_to_discover_tests_when_it_handles_the_message()
|
||||
{
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(_dotnetTestAtVersionCheckCompletedState, _validMessage);
|
||||
|
||||
_testRunnerMock.Verify(t => t.RunTestCommand(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_sends_an_error_when_the_test_runner_fails()
|
||||
{
|
||||
const string testRunner = "SomeTestRunner";
|
||||
|
||||
_testRunnerMock.Setup(t => t.RunTestCommand()).Throws(new TestRunnerOperationFailedException(testRunner, 1));
|
||||
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(_dotnetTestAtVersionCheckCompletedState, _validMessage);
|
||||
|
||||
_adapterChannelMock.Verify(r => r.SendError($"'{testRunner}' returned '1'."), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_creates_a_new_reporting_channel()
|
||||
{
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_reportingChannelFactoryMock.Verify(r => r.CreateChannelWithAnyAvailablePort(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_calls_accept_on_the_test_runner_channel()
|
||||
{
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_testRunnerChannelMock.Verify(t => t.Accept(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_makes_dotnet_test_listen_on_the_test_runner_port_for_messages_when_it_handles_the_message()
|
||||
{
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_dotnetTestMock.Verify(d => d.StartListeningTo(_testRunnerChannelMock.Object), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_passes_the_right_arguments_to_the_run_tests_arguments_builder()
|
||||
{
|
||||
_testDiscoveryStartMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_argumentsBuilder.Should().NotBeNull();
|
||||
|
||||
var arguments = _argumentsBuilder.BuildArguments();
|
||||
|
||||
arguments.Should().Contain("--port", $"{TestRunnerPort}");
|
||||
arguments.Should().Contain($"{AssemblyUnderTest}");
|
||||
arguments.Should().Contain("--list");
|
||||
arguments.Should().Contain("--designtime");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,188 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenATestExecutionGetTestRunnerProcessStartInfoMessageHandler
|
||||
{
|
||||
private const int TestRunnerPort = 1;
|
||||
private const string AssemblyUnderTest = "assembly.dll";
|
||||
|
||||
private GetTestRunnerProcessStartInfoMessageHandler _testGetTestRunnerProcessStartInfoMessageHandler;
|
||||
private Message _validMessage;
|
||||
private ProcessStartInfo _processStartInfo;
|
||||
|
||||
private Mock<ITestRunner> _testRunnerMock;
|
||||
private Mock<ITestRunnerFactory> _testRunnerFactoryMock;
|
||||
private Mock<IReportingChannel> _adapterChannelMock;
|
||||
private Mock<IReportingChannel> _testRunnerChannelMock;
|
||||
private Mock<IReportingChannelFactory> _reportingChannelFactoryMock;
|
||||
private Mock<IDotnetTest> _dotnetTestMock;
|
||||
|
||||
private RunTestsArgumentsBuilder _argumentsBuilder;
|
||||
|
||||
public GivenATestExecutionGetTestRunnerProcessStartInfoMessageHandler()
|
||||
{
|
||||
_validMessage = new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestExecutionGetTestRunnerProcessStartInfo,
|
||||
Payload = JToken.FromObject(new RunTestsMessage { Tests = new List<string> { "test1", "test2" } })
|
||||
};
|
||||
|
||||
_dotnetTestMock = new Mock<IDotnetTest>();
|
||||
_dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.VersionCheckCompleted);
|
||||
_dotnetTestMock.Setup(d => d.PathToAssemblyUnderTest).Returns(AssemblyUnderTest);
|
||||
|
||||
_processStartInfo = new ProcessStartInfo("runner", "arguments");
|
||||
|
||||
_testRunnerMock = new Mock<ITestRunner>();
|
||||
_testRunnerMock.Setup(t => t.GetProcessStartInfo()).Returns(_processStartInfo);
|
||||
|
||||
_testRunnerFactoryMock = new Mock<ITestRunnerFactory>();
|
||||
_testRunnerFactoryMock
|
||||
.Setup(c => c.CreateTestRunner(It.IsAny<RunTestsArgumentsBuilder>()))
|
||||
.Callback<ITestRunnerArgumentsBuilder>(r => _argumentsBuilder = r as RunTestsArgumentsBuilder)
|
||||
.Returns(_testRunnerMock.Object);
|
||||
|
||||
_adapterChannelMock = new Mock<IReportingChannel>();
|
||||
_testRunnerChannelMock = new Mock<IReportingChannel>();
|
||||
_testRunnerChannelMock.Setup(t => t.Port).Returns(TestRunnerPort);
|
||||
|
||||
_reportingChannelFactoryMock = new Mock<IReportingChannelFactory>();
|
||||
_reportingChannelFactoryMock.Setup(r =>
|
||||
r.CreateChannelWithAnyAvailablePort()).Returns(_testRunnerChannelMock.Object);
|
||||
|
||||
_testGetTestRunnerProcessStartInfoMessageHandler = new GetTestRunnerProcessStartInfoMessageHandler(
|
||||
_testRunnerFactoryMock.Object,
|
||||
_adapterChannelMock.Object,
|
||||
_reportingChannelFactoryMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_VersionCheckCompleted_or_InitialState()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
||||
|
||||
var nextState = _testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_message_is_not_TestDiscoveryStart()
|
||||
{
|
||||
var nextState = _testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
new Message { MessageType = "Something different from TestDiscovery.Start" });
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestExecutionSentTestRunnerProcessStartInfo_when_it_handles_the_message_and_current_state_is_InitialState()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.InitialState);
|
||||
|
||||
var nextState = _testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestExecutionSentTestRunnerProcessStartInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestExecutionSentTestRunnerProcessStartInfo_when_it_handles_the_message_and_current_state_is_VersionCheckCompleted()
|
||||
{
|
||||
var nextState = _testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestExecutionSentTestRunnerProcessStartInfo);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_gets_the_process_start_info_from_the_test_runner_when_it_handles_the_message()
|
||||
{
|
||||
_testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_testRunnerMock.Verify(t => t.GetProcessStartInfo(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_sends_the_process_start_info_when_it_handles_the_message()
|
||||
{
|
||||
_adapterChannelMock.Setup(r => r.Send(It.Is<Message>(m =>
|
||||
m.MessageType == TestMessageTypes.TestExecutionTestRunnerProcessStartInfo &&
|
||||
m.Payload.ToObject<ProcessStartInfo>().FileName == _processStartInfo.FileName &&
|
||||
m.Payload.ToObject<ProcessStartInfo>().Arguments == _processStartInfo.Arguments))).Verifiable();
|
||||
|
||||
_testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_adapterChannelMock.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_creates_a_new_reporting_channel()
|
||||
{
|
||||
_testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_reportingChannelFactoryMock.Verify(r => r.CreateChannelWithAnyAvailablePort(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_calls_accept_on_the_test_runner_channel()
|
||||
{
|
||||
_testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_testRunnerChannelMock.Verify(t => t.Accept(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_makes_dotnet_test_listen_on_the_test_runner_port_for_messages_when_it_handles_the_message()
|
||||
{
|
||||
_testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_dotnetTestMock.Verify(d => d.StartListeningTo(_testRunnerChannelMock.Object), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_passes_the_right_arguments_to_the_run_tests_arguments_builder()
|
||||
{
|
||||
_testGetTestRunnerProcessStartInfoMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_argumentsBuilder.Should().NotBeNull();
|
||||
|
||||
var arguments = _argumentsBuilder.BuildArguments();
|
||||
|
||||
arguments.Should().Contain("--port", $"{TestRunnerPort}");
|
||||
arguments.Should().Contain($"{AssemblyUnderTest}");
|
||||
arguments.Should().Contain("--test", "test1");
|
||||
arguments.Should().Contain("--test", "test2");
|
||||
}
|
||||
}
|
||||
}
|
106
test/dotnet-test.UnitTests/GivenATestRunner.cs
Normal file
106
test/dotnet-test.UnitTests/GivenATestRunner.cs
Normal file
|
@ -0,0 +1,106 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Moq;
|
||||
using NuGet.Frameworks;
|
||||
using Xunit;
|
||||
using Newtonsoft.Json;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenATestRunner
|
||||
{
|
||||
private Mock<ICommand> _commandMock;
|
||||
private Mock<ICommandFactory> _commandFactoryMock;
|
||||
private Mock<ITestRunnerArgumentsBuilder> _argumentsBuilderMock;
|
||||
private string _runner = "runner";
|
||||
private string[] _testRunnerArguments;
|
||||
|
||||
public GivenATestRunner()
|
||||
{
|
||||
_testRunnerArguments = new[] {"assembly.dll", "--list", "--designtime"};
|
||||
|
||||
_commandMock = new Mock<ICommand>();
|
||||
_commandMock.Setup(c => c.CommandName).Returns(_runner);
|
||||
_commandMock.Setup(c => c.CommandArgs).Returns(string.Join(" ", _testRunnerArguments));
|
||||
_commandMock.Setup(c => c.OnOutputLine(It.IsAny<Action<string>>())).Returns(_commandMock.Object);
|
||||
|
||||
_argumentsBuilderMock = new Mock<ITestRunnerArgumentsBuilder>();
|
||||
_argumentsBuilderMock.Setup(a => a.BuildArguments())
|
||||
.Returns(_testRunnerArguments);
|
||||
|
||||
_commandFactoryMock = new Mock<ICommandFactory>();
|
||||
_commandFactoryMock.Setup(c => c.Create(
|
||||
_runner,
|
||||
_testRunnerArguments,
|
||||
new NuGetFramework("DNXCore", Version.Parse("5.0")),
|
||||
null)).Returns(_commandMock.Object).Verifiable();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_creates_a_command_using_the_right_parameters()
|
||||
{
|
||||
var testRunner = new TestRunner(_runner, _commandFactoryMock.Object, _argumentsBuilderMock.Object);
|
||||
|
||||
testRunner.RunTestCommand();
|
||||
|
||||
_commandFactoryMock.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_executes_the_command()
|
||||
{
|
||||
var testRunner = new TestRunner(_runner, _commandFactoryMock.Object, _argumentsBuilderMock.Object);
|
||||
|
||||
testRunner.RunTestCommand();
|
||||
|
||||
_commandMock.Verify(c => c.Execute(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_throws_TestRunnerOperationFailedException_when_the_returns_return_an_error_code()
|
||||
{
|
||||
_commandMock.Setup(c => c.Execute()).Returns(new CommandResult(null, 1, null, null));
|
||||
|
||||
var testRunner = new TestRunner(_runner, _commandFactoryMock.Object, _argumentsBuilderMock.Object);
|
||||
|
||||
Action action = () => testRunner.RunTestCommand();
|
||||
|
||||
action.ShouldThrow<TestRunnerOperationFailedException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_executes_the_command_when_RunTestCommand_is_called()
|
||||
{
|
||||
var testResult = new Message
|
||||
{
|
||||
MessageType = "Irrelevant",
|
||||
Payload = JToken.FromObject("Irrelevant")
|
||||
};
|
||||
|
||||
var testRunner = new TestRunner(_runner, _commandFactoryMock.Object, _argumentsBuilderMock.Object);
|
||||
|
||||
testRunner.RunTestCommand();
|
||||
|
||||
_commandMock.Verify(c => c.Execute(), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_a_ProcessStartInfo_object_with_the_right_parameters_to_execute_the_test_command()
|
||||
{
|
||||
var testRunner = new TestRunner(_runner, _commandFactoryMock.Object, _argumentsBuilderMock.Object);
|
||||
|
||||
var testCommandProcessStartInfo = testRunner.GetProcessStartInfo();
|
||||
|
||||
testCommandProcessStartInfo.FileName.Should().Be(_runner);
|
||||
testCommandProcessStartInfo.Arguments.Should().Be(string.Join(" ", _testRunnerArguments));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,122 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenATestRunnerTestCompletedMessageHandler
|
||||
{
|
||||
private Mock<IDotnetTest> _dotnetTestAtTestDiscoveryStartedMock;
|
||||
private Mock<IDotnetTest> _dotnetTestAtTestExecutionStartedMock;
|
||||
private Mock<IReportingChannel> _adapterChannelMock;
|
||||
|
||||
private Message _validMessage;
|
||||
private TestRunnerTestCompletedMessageHandler _testRunnerTestCompletedMessageHandler;
|
||||
|
||||
public GivenATestRunnerTestCompletedMessageHandler()
|
||||
{
|
||||
_dotnetTestAtTestDiscoveryStartedMock = new Mock<IDotnetTest>();
|
||||
_dotnetTestAtTestDiscoveryStartedMock.Setup(d => d.State).Returns(DotnetTestState.TestDiscoveryStarted);
|
||||
|
||||
_dotnetTestAtTestExecutionStartedMock = new Mock<IDotnetTest>();
|
||||
_dotnetTestAtTestExecutionStartedMock.Setup(d => d.State).Returns(DotnetTestState.TestExecutionStarted);
|
||||
|
||||
_adapterChannelMock = new Mock<IReportingChannel>();
|
||||
|
||||
_validMessage = new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestRunnerTestCompleted
|
||||
};
|
||||
|
||||
_testRunnerTestCompletedMessageHandler =
|
||||
new TestRunnerTestCompletedMessageHandler(_adapterChannelMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_TestDiscoveryStarted_or_TestExecutionStarted()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
||||
|
||||
var nextState = _testRunnerTestCompletedMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_message_is_not_TestRunnerTestCompleted_when_state_is_TestDiscoveryStarted()
|
||||
{
|
||||
var nextState = _testRunnerTestCompletedMessageHandler.HandleMessage(
|
||||
_dotnetTestAtTestDiscoveryStartedMock.Object,
|
||||
new Message { MessageType = "Something different from TestDiscovery.Start" });
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_message_is_not_TestRunnerTestCompleted_when_state_is_TestExecutionStarted()
|
||||
{
|
||||
var nextState = _testRunnerTestCompletedMessageHandler.HandleMessage(
|
||||
_dotnetTestAtTestExecutionStartedMock.Object,
|
||||
new Message { MessageType = "Something different from TestDiscovery.Start" });
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestDiscoveryCompleted_when_it_handles_the_message_and_current_state_is_TestDiscoveryStarted()
|
||||
{
|
||||
var nextState = _testRunnerTestCompletedMessageHandler.HandleMessage(
|
||||
_dotnetTestAtTestDiscoveryStartedMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestDiscoveryCompleted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_sends_a_TestDiscoveryCompleted_when_it_handles_the_message_and_current_state_is_TestDiscoveryStarted()
|
||||
{
|
||||
_adapterChannelMock
|
||||
.Setup(a => a.Send(It.Is<Message>(m => m.MessageType == TestMessageTypes.TestDiscoveryCompleted)))
|
||||
.Verifiable();
|
||||
|
||||
_testRunnerTestCompletedMessageHandler.HandleMessage(
|
||||
_dotnetTestAtTestDiscoveryStartedMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_adapterChannelMock.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestExecutionCompleted_when_it_handles_the_message_and_current_state_is_TestExecutionStarted()
|
||||
{
|
||||
var nextState = _testRunnerTestCompletedMessageHandler.HandleMessage(
|
||||
_dotnetTestAtTestExecutionStartedMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestExecutionCompleted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_sends_a_TestExecutionCompleted_when_it_handles_the_message_and_current_state_is_TestExecutionStarted()
|
||||
{
|
||||
_adapterChannelMock
|
||||
.Setup(a => a.Send(It.Is<Message>(m => m.MessageType == TestMessageTypes.TestExecutionCompleted)))
|
||||
.Verifiable();
|
||||
|
||||
_testRunnerTestCompletedMessageHandler.HandleMessage(
|
||||
_dotnetTestAtTestExecutionStartedMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_adapterChannelMock.Verify();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenATestRunnerTestFoundMessageHandler
|
||||
{
|
||||
private Mock<IDotnetTest> _dotnetTestMock;
|
||||
private Mock<IReportingChannel> _adapterChannelMock;
|
||||
|
||||
private Message _validMessage;
|
||||
private TestRunnerTestFoundMessageHandler _testRunnerTestFoundMessageHandler;
|
||||
|
||||
public GivenATestRunnerTestFoundMessageHandler()
|
||||
{
|
||||
_dotnetTestMock = new Mock<IDotnetTest>();
|
||||
_dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.TestDiscoveryStarted);
|
||||
|
||||
_adapterChannelMock = new Mock<IReportingChannel>();
|
||||
|
||||
_validMessage = new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestRunnerTestFound,
|
||||
Payload = JToken.FromObject("testFound")
|
||||
};
|
||||
|
||||
_testRunnerTestFoundMessageHandler = new TestRunnerTestFoundMessageHandler(_adapterChannelMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_TestDiscoveryStarted()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
||||
|
||||
var nextState = _testRunnerTestFoundMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_message_is_not_TestRunnerTestFound()
|
||||
{
|
||||
var nextState = _testRunnerTestFoundMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
new Message { MessageType = "Something different from TestDiscovery.Start" });
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestDiscoveryStarted_when_it_handles_the_message()
|
||||
{
|
||||
var nextState = _testRunnerTestFoundMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestDiscoveryStarted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_sends_the_payload_of_the_message_when_it_handles_the_message()
|
||||
{
|
||||
_adapterChannelMock.Setup(a => a.Send(It.Is<Message>(m =>
|
||||
m.MessageType == TestMessageTypes.TestDiscoveryTestFound &&
|
||||
m.Payload.ToObject<string>() == _validMessage.Payload.ToObject<string>()))).Verifiable();
|
||||
|
||||
_testRunnerTestFoundMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_adapterChannelMock.Verify();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenATestRunnerTestResultMessageHandler
|
||||
{
|
||||
private Mock<IDotnetTest> _dotnetTestMock;
|
||||
private Mock<IReportingChannel> _adapterChannelMock;
|
||||
|
||||
private Message _validMessage;
|
||||
private TestRunnerTestResultMessageHandler _testRunnerTestResultMessageHandler;
|
||||
|
||||
public GivenATestRunnerTestResultMessageHandler()
|
||||
{
|
||||
_dotnetTestMock = new Mock<IDotnetTest>();
|
||||
_dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.TestExecutionStarted);
|
||||
|
||||
_adapterChannelMock = new Mock<IReportingChannel>();
|
||||
|
||||
_validMessage = new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestRunnerTestResult,
|
||||
Payload = JToken.FromObject("testFound")
|
||||
};
|
||||
|
||||
_testRunnerTestResultMessageHandler = new TestRunnerTestResultMessageHandler(_adapterChannelMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_TestExecutionStarted()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
||||
|
||||
var nextState = _testRunnerTestResultMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_message_is_not_TestRunnerTestResult()
|
||||
{
|
||||
var nextState = _testRunnerTestResultMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
new Message { MessageType = "Something different from TestRunner.TestResult" });
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestExecutionStarted_when_it_handles_the_message()
|
||||
{
|
||||
var nextState = _testRunnerTestResultMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestExecutionStarted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_sends_the_payload_of_the_message_when_it_handles_the_message()
|
||||
{
|
||||
_adapterChannelMock.Setup(a => a.Send(It.Is<Message>(m =>
|
||||
m.MessageType == TestMessageTypes.TestExecutionTestResult &&
|
||||
m.Payload.ToObject<string>() == _validMessage.Payload.ToObject<string>()))).Verifiable();
|
||||
|
||||
_testRunnerTestResultMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_adapterChannelMock.Verify();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,112 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenATestRunnerTestStartedMessageHandler
|
||||
{
|
||||
private Mock<IDotnetTest> _dotnetTestMock;
|
||||
private Mock<IReportingChannel> _adapterChannelMock;
|
||||
|
||||
private Message _validMessage;
|
||||
private TestRunnerTestStartedMessageHandler _testRunnerTestStartedMessageHandler;
|
||||
|
||||
public GivenATestRunnerTestStartedMessageHandler()
|
||||
{
|
||||
_dotnetTestMock = new Mock<IDotnetTest>();
|
||||
_dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.TestExecutionSentTestRunnerProcessStartInfo);
|
||||
|
||||
_adapterChannelMock = new Mock<IReportingChannel>();
|
||||
|
||||
_validMessage = new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestRunnerTestStarted,
|
||||
Payload = JToken.FromObject("testFound")
|
||||
};
|
||||
|
||||
_testRunnerTestStartedMessageHandler =
|
||||
new TestRunnerTestStartedMessageHandler(_adapterChannelMock.Object);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_TestExecutionSentTestRunnerProcessStartInfo_or_TestExecutionTestStarted()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
||||
|
||||
var nextState = _testRunnerTestStartedMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_message_is_not_TestRunnerTestStarted()
|
||||
{
|
||||
var nextState = _testRunnerTestStartedMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
new Message { MessageType = "Something different from TestRunner.TestStart" });
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestExecutionStarted_when_it_handles_the_message_and_current_state_is_TestExecutionSentTestRunnerProcessStartInfo()
|
||||
{
|
||||
var nextState = _testRunnerTestStartedMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestExecutionStarted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_TestExecutionStarted_when_it_handles_the_message_and_current_state_is_TestExecutionTestStarted()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.TestExecutionStarted);
|
||||
|
||||
var nextState = _testRunnerTestStartedMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.TestExecutionStarted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_sends_a_TestExecutionTestStarted_when_it_handles_the_message()
|
||||
{
|
||||
_adapterChannelMock
|
||||
.Setup(a => a.Send(It.Is<Message>(m => m.MessageType == TestMessageTypes.TestExecutionStarted)))
|
||||
.Verifiable();
|
||||
|
||||
_testRunnerTestStartedMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_adapterChannelMock.Verify();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_sends_the_payload_of_the_message_when_it_handles_the_message()
|
||||
{
|
||||
_adapterChannelMock.Setup(a => a.Send(It.Is<Message>(m =>
|
||||
m.MessageType == TestMessageTypes.TestExecutionStarted &&
|
||||
m.Payload.ToObject<string>() == _validMessage.Payload.ToObject<string>()))).Verifiable();
|
||||
|
||||
_testRunnerTestStartedMessageHandler.HandleMessage(
|
||||
_dotnetTestMock.Object,
|
||||
_validMessage);
|
||||
|
||||
_adapterChannelMock.Verify();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenATestSessionTerminateMessageHandler
|
||||
{
|
||||
private DotnetTestState _nextState;
|
||||
private Mock<ITestMessagesCollection> _testMessagesCollectionMock;
|
||||
|
||||
public GivenATestSessionTerminateMessageHandler()
|
||||
{
|
||||
var reportingChannel = new Mock<IReportingChannel>();
|
||||
_testMessagesCollectionMock = new Mock<ITestMessagesCollection>();
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
var messageHandler = new TestSessionTerminateMessageHandler(_testMessagesCollectionMock.Object);
|
||||
|
||||
_nextState = messageHandler.HandleMessage(dotnetTestMock.Object, new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestSessionTerminate
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_always_returns_the_terminated_state_idependent_of_the_state_passed_to_it()
|
||||
{
|
||||
_nextState.Should().Be(DotnetTestState.Terminated);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_calls_drain_on_the_test_messages()
|
||||
{
|
||||
_testMessagesCollectionMock.Verify(tmc => tmc.Drain(), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
37
test/dotnet-test.UnitTests/GivenAUnknownMessageHandler.cs
Normal file
37
test/dotnet-test.UnitTests/GivenAUnknownMessageHandler.cs
Normal file
|
@ -0,0 +1,37 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenAUnknownMessageHandler
|
||||
{
|
||||
[Fact]
|
||||
public void It_throws_InvalidOperationException_and_sends_an_error_when_the_message_is_not_handled()
|
||||
{
|
||||
const string expectedError = "No handler for message 'Test Message' when at state 'InitialState'";
|
||||
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.InitialState);
|
||||
|
||||
var reportingChannel = new Mock<IReportingChannel>();
|
||||
reportingChannel.Setup(r => r.SendError(expectedError)).Verifiable();
|
||||
|
||||
var unknownMessageHandler = new UnknownMessageHandler(reportingChannel.Object);
|
||||
|
||||
Action action = () => unknownMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
new Message { MessageType = "Test Message" });
|
||||
|
||||
action.ShouldThrow<InvalidOperationException>().WithMessage(expectedError);
|
||||
|
||||
reportingChannel.Verify();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenAVersionCheckMessageHandler
|
||||
{
|
||||
private Mock<IReportingChannel> _reportingChannelMock;
|
||||
private VersionCheckMessageHandler _versionCheckMessageHandler;
|
||||
private Message _validMessage;
|
||||
private IDotnetTest _dotnetTestAtInitialState;
|
||||
|
||||
public GivenAVersionCheckMessageHandler()
|
||||
{
|
||||
_reportingChannelMock = new Mock<IReportingChannel>();
|
||||
_versionCheckMessageHandler = new VersionCheckMessageHandler(_reportingChannelMock.Object);
|
||||
|
||||
_validMessage = new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.VersionCheck,
|
||||
Payload = JToken.FromObject(new ProtocolVersionMessage
|
||||
{
|
||||
Version = 99
|
||||
})
|
||||
};
|
||||
|
||||
var dotnetTestAtInitialStateMock = new Mock<IDotnetTest>();
|
||||
dotnetTestAtInitialStateMock.Setup(d => d.State).Returns(DotnetTestState.InitialState);
|
||||
_dotnetTestAtInitialState = dotnetTestAtInitialStateMock.Object;
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_dotnet_test_state_is_not_initial()
|
||||
{
|
||||
var dotnetTestMock = new Mock<IDotnetTest>();
|
||||
dotnetTestMock.Setup(d => d.State).Returns(DotnetTestState.Terminated);
|
||||
|
||||
var nextState = _versionCheckMessageHandler.HandleMessage(
|
||||
dotnetTestMock.Object,
|
||||
new Message {MessageType = TestMessageTypes.VersionCheck});
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_NoOp_if_the_message_is_not_VersionCheck()
|
||||
{
|
||||
var nextState = _versionCheckMessageHandler.HandleMessage(
|
||||
_dotnetTestAtInitialState,
|
||||
new Message { MessageType = "Something different from ProtocolVersion" });
|
||||
|
||||
nextState.Should().Be(DotnetTestState.NoOp);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_VersionCheckCompleted_when_it_handles_the_message()
|
||||
{
|
||||
var nextState = _versionCheckMessageHandler.HandleMessage(_dotnetTestAtInitialState, _validMessage);
|
||||
|
||||
nextState.Should().Be(DotnetTestState.VersionCheckCompleted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_returns_a_ProtocolVersion_with_the_SupportedVersion_when_it_handles_the_message()
|
||||
{
|
||||
_reportingChannelMock.Setup(r =>
|
||||
r.Send(It.Is<Message>(m =>
|
||||
m.MessageType == TestMessageTypes.VersionCheck &&
|
||||
m.Payload.ToObject<ProtocolVersionMessage>().Version == 1))).Verifiable();
|
||||
|
||||
_versionCheckMessageHandler.HandleMessage(_dotnetTestAtInitialState, _validMessage);
|
||||
|
||||
_reportingChannelMock.Verify();
|
||||
}
|
||||
}
|
||||
}
|
67
test/dotnet-test.UnitTests/GivenThatWeWantToDiscoverTests.cs
Normal file
67
test/dotnet-test.UnitTests/GivenThatWeWantToDiscoverTests.cs
Normal file
|
@ -0,0 +1,67 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenThatWeWantToDiscoverTests
|
||||
{
|
||||
[Fact]
|
||||
public void Dotnet_test_handles_and_sends_all_the_right_messages()
|
||||
{
|
||||
var dotnetTestMessageScenario = new DotnetTestMessageScenario();
|
||||
|
||||
dotnetTestMessageScenario.TestRunnerMock
|
||||
.Setup(t => t.RunTestCommand())
|
||||
.Callback(() => dotnetTestMessageScenario.TestRunnerChannelMock.Raise(
|
||||
t => t.MessageReceived += null,
|
||||
dotnetTestMessageScenario.DotnetTestUnderTest,
|
||||
new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestRunnerTestFound,
|
||||
Payload = JToken.FromObject("testFound")
|
||||
}))
|
||||
.Verifiable();
|
||||
|
||||
dotnetTestMessageScenario.AdapterChannelMock
|
||||
.Setup(a => a.Send(It.Is<Message>(m => m.MessageType == TestMessageTypes.VersionCheck)))
|
||||
.Callback(() => dotnetTestMessageScenario.AdapterChannelMock.Raise(
|
||||
r => r.MessageReceived += null,
|
||||
dotnetTestMessageScenario.DotnetTestUnderTest,
|
||||
new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestDiscoveryStart
|
||||
}))
|
||||
.Verifiable();
|
||||
|
||||
dotnetTestMessageScenario.AdapterChannelMock
|
||||
.Setup(a => a.Send(It.Is<Message>(m => m.MessageType == TestMessageTypes.TestDiscoveryTestFound)))
|
||||
.Callback(() => dotnetTestMessageScenario.TestRunnerChannelMock.Raise(
|
||||
t => t.MessageReceived += null,
|
||||
dotnetTestMessageScenario.DotnetTestUnderTest,
|
||||
new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestRunnerTestCompleted
|
||||
}))
|
||||
.Verifiable();
|
||||
|
||||
dotnetTestMessageScenario.AdapterChannelMock
|
||||
.Setup(a => a.Send(It.Is<Message>(m => m.MessageType == TestMessageTypes.TestDiscoveryCompleted)))
|
||||
.Callback(() => dotnetTestMessageScenario.AdapterChannelMock.Raise(
|
||||
r => r.MessageReceived += null,
|
||||
dotnetTestMessageScenario.DotnetTestUnderTest,
|
||||
new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestSessionTerminate
|
||||
}))
|
||||
.Verifiable();
|
||||
|
||||
dotnetTestMessageScenario.Run();
|
||||
}
|
||||
}
|
||||
}
|
86
test/dotnet-test.UnitTests/GivenThatWeWantToRunTests.cs
Normal file
86
test/dotnet-test.UnitTests/GivenThatWeWantToRunTests.cs
Normal file
|
@ -0,0 +1,86 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Diagnostics;
|
||||
using Microsoft.DotNet.Tools.Test;
|
||||
using Microsoft.Extensions.Testing.Abstractions;
|
||||
using Moq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.Dotnet.Tools.Test.Tests
|
||||
{
|
||||
public class GivenThatWeWantToRunTests
|
||||
{
|
||||
[Fact]
|
||||
public void Dotnet_test_handles_and_sends_all_the_right_messages()
|
||||
{
|
||||
var dotnetTestMessageScenario = new DotnetTestMessageScenario();
|
||||
|
||||
dotnetTestMessageScenario.TestRunnerMock
|
||||
.Setup(t => t.GetProcessStartInfo())
|
||||
.Returns(new ProcessStartInfo())
|
||||
.Verifiable();
|
||||
|
||||
dotnetTestMessageScenario.AdapterChannelMock
|
||||
.Setup(a => a.Send(It.Is<Message>(m => m.MessageType == TestMessageTypes.VersionCheck)))
|
||||
.Callback(() => dotnetTestMessageScenario.AdapterChannelMock.Raise(
|
||||
r => r.MessageReceived += null,
|
||||
dotnetTestMessageScenario.DotnetTestUnderTest,
|
||||
new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestExecutionGetTestRunnerProcessStartInfo
|
||||
}))
|
||||
.Verifiable();
|
||||
|
||||
dotnetTestMessageScenario.AdapterChannelMock
|
||||
.Setup(a => a.Send(
|
||||
It.Is<Message>(m => m.MessageType == TestMessageTypes.TestExecutionTestRunnerProcessStartInfo)))
|
||||
.Callback(() => dotnetTestMessageScenario.TestRunnerChannelMock.Raise(
|
||||
t => t.MessageReceived += null,
|
||||
dotnetTestMessageScenario.DotnetTestUnderTest,
|
||||
new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestRunnerTestStarted
|
||||
}))
|
||||
.Verifiable();
|
||||
|
||||
dotnetTestMessageScenario.AdapterChannelMock
|
||||
.Setup(a => a.Send(
|
||||
It.Is<Message>(m => m.MessageType == TestMessageTypes.TestExecutionStarted)))
|
||||
.Callback(() => dotnetTestMessageScenario.TestRunnerChannelMock.Raise(
|
||||
t => t.MessageReceived += null,
|
||||
dotnetTestMessageScenario.DotnetTestUnderTest,
|
||||
new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestRunnerTestResult
|
||||
}))
|
||||
.Verifiable();
|
||||
|
||||
dotnetTestMessageScenario.AdapterChannelMock
|
||||
.Setup(a => a.Send(
|
||||
It.Is<Message>(m => m.MessageType == TestMessageTypes.TestExecutionTestResult)))
|
||||
.Callback(() => dotnetTestMessageScenario.TestRunnerChannelMock.Raise(
|
||||
t => t.MessageReceived += null,
|
||||
dotnetTestMessageScenario.DotnetTestUnderTest,
|
||||
new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestRunnerTestCompleted
|
||||
}))
|
||||
.Verifiable();
|
||||
|
||||
dotnetTestMessageScenario.AdapterChannelMock
|
||||
.Setup(a => a.Send(It.Is<Message>(m => m.MessageType == TestMessageTypes.TestExecutionCompleted)))
|
||||
.Callback(() => dotnetTestMessageScenario.AdapterChannelMock.Raise(
|
||||
r => r.MessageReceived += null,
|
||||
dotnetTestMessageScenario.DotnetTestUnderTest,
|
||||
new Message
|
||||
{
|
||||
MessageType = TestMessageTypes.TestSessionTerminate
|
||||
}))
|
||||
.Verifiable();
|
||||
|
||||
dotnetTestMessageScenario.Run();
|
||||
}
|
||||
}
|
||||
}
|
18
test/dotnet-test.UnitTests/dotnet-test.UnitTests.xproj
Normal file
18
test/dotnet-test.UnitTests/dotnet-test.UnitTests.xproj
Normal file
|
@ -0,0 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0.24720" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.24720</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>857274ac-e741-4266-a7fd-14dee0c1cc96</ProjectGuid>
|
||||
<RootNamespace>Microsoft.Dotnet.Tools.Test.Tests</RootNamespace>
|
||||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
|
||||
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
23
test/dotnet-test.UnitTests/project.json
Normal file
23
test/dotnet-test.UnitTests/project.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
|
||||
"dependencies": {
|
||||
"Newtonsoft.Json": "7.0.1",
|
||||
"NETStandard.Library": "1.0.0-rc2-23811",
|
||||
|
||||
"dotnet": { "target": "project" },
|
||||
|
||||
"xunit": "2.1.0",
|
||||
"dotnet-test-xunit": "1.0.0-dev-48273-16",
|
||||
"moq.netcore": "4.4.0-beta8",
|
||||
"FluentAssertions": "4.2.2"
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"dnxcore50": {
|
||||
"imports": "portable-net45+win8"
|
||||
}
|
||||
},
|
||||
|
||||
"testRunner": "xunit"
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue