Merge branch 'troy/add.test.wip' into rel/1.0.0
This commit is contained in:
commit
7582649f88
19 changed files with 61 additions and 158 deletions
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"NETStandard.Library": "1.0.0-rc2-23811",
|
"NETStandard.Library": "1.0.0-rc2-23811",
|
||||||
"EmptyLibrary": ""
|
"EmptyLibrary": "1.0.0-*"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"dnxcore50": { }
|
"dnxcore50": { }
|
|
@ -1,4 +1,5 @@
|
||||||
{
|
{
|
||||||
|
"version": "1.0.0-*",
|
||||||
"dependencies": { },
|
"dependencies": { },
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"dnxcore50": {
|
"dnxcore50": {
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"EmptyLibrary": ""
|
"EmptyLibrary": "1.0.0-*"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"dnx451": { }
|
"dnx451": { }
|
|
@ -28,6 +28,7 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
"dotnet-compile.UnitTests",
|
"dotnet-compile.UnitTests",
|
||||||
"dotnet-build.Tests",
|
"dotnet-build.Tests",
|
||||||
"dotnet-pack.Tests",
|
"dotnet-pack.Tests",
|
||||||
|
"dotnet-projectmodel-server.Tests",
|
||||||
"dotnet-resgen.Tests",
|
"dotnet-resgen.Tests",
|
||||||
"dotnet-run.Tests",
|
"dotnet-run.Tests",
|
||||||
"Microsoft.DotNet.Cli.Utils.Tests",
|
"Microsoft.DotNet.Cli.Utils.Tests",
|
||||||
|
@ -76,8 +77,11 @@ namespace Microsoft.DotNet.Cli.Build
|
||||||
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"))
|
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"))
|
||||||
.Execute().EnsureSuccessful();
|
.Execute().EnsureSuccessful();
|
||||||
|
|
||||||
// The 'testapp' directory contains intentionally-unresolved dependencies, so don't check for success. Also, suppress the output
|
// The 'ProjectModelServer' directory contains intentionally-unresolved dependencies, so don't check for success. Also, suppress the output
|
||||||
dotnet.Restore().WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "testapp")).CaptureStdErr().CaptureStdOut().Execute();
|
dotnet.Restore().WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "ProjectModelServer"))
|
||||||
|
.CaptureStdErr()
|
||||||
|
.CaptureStdOut()
|
||||||
|
.Execute();
|
||||||
|
|
||||||
return c.Success();
|
return c.Success();
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,6 @@ using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
|
@ -34,6 +33,9 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
||||||
|
|
||||||
public DthTestClient(DthTestServer server)
|
public DthTestClient(DthTestServer server)
|
||||||
{
|
{
|
||||||
|
// Avoid Socket exception 10006 on Linux
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
_socket = new Socket(AddressFamily.InterNetwork,
|
_socket = new Socket(AddressFamily.InterNetwork,
|
||||||
SocketType.Stream,
|
SocketType.Stream,
|
||||||
ProtocolType.Tcp);
|
ProtocolType.Tcp);
|
||||||
|
|
|
@ -4,29 +4,51 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Microsoft.DotNet.ProjectModel.Server.Tests.Helpers;
|
using Microsoft.DotNet.ProjectModel.Graph;
|
||||||
|
using Microsoft.DotNet.TestFramework;
|
||||||
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using Microsoft.Extensions.PlatformAbstractions;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
||||||
{
|
{
|
||||||
public class DthTests : IClassFixture<TestHelper>
|
public class DthTests : TestBase
|
||||||
{
|
{
|
||||||
private readonly TestHelper _testHelper;
|
private readonly TestAssetsManager _testAssetsManager;
|
||||||
|
private readonly ILoggerFactory _loggerFactory;
|
||||||
|
|
||||||
public DthTests(TestHelper helper)
|
public DthTests()
|
||||||
{
|
{
|
||||||
_testHelper = helper;
|
_loggerFactory = new LoggerFactory();
|
||||||
|
|
||||||
|
var testVerbose = Environment.GetEnvironmentVariable("DOTNET_TEST_VERBOSE");
|
||||||
|
if (testVerbose == "2")
|
||||||
|
{
|
||||||
|
_loggerFactory.AddConsole(LogLevel.Trace);
|
||||||
|
}
|
||||||
|
else if (testVerbose == "1")
|
||||||
|
{
|
||||||
|
_loggerFactory.AddConsole(LogLevel.Information);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_loggerFactory.AddConsole(LogLevel.Warning);
|
||||||
|
}
|
||||||
|
|
||||||
|
_testAssetsManager = new TestAssetsManager(
|
||||||
|
Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer", "DthTestProjects", "src"));
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DthStartup_GetProjectInformation()
|
public void DthStartup_GetProjectInformation()
|
||||||
{
|
{
|
||||||
var projectPath = _testHelper.FindSampleProject("EmptyConsoleApp");
|
var projectPath = Path.Combine(_testAssetsManager.AssetsRoot, "EmptyConsoleApp");
|
||||||
Assert.NotNull(projectPath);
|
Assert.NotNull(projectPath);
|
||||||
|
|
||||||
using (var server = new DthTestServer(_testHelper.LoggerFactory))
|
using (var server = new DthTestServer(_loggerFactory))
|
||||||
using (var client = new DthTestClient(server))
|
using (var client = new DthTestClient(server))
|
||||||
{
|
{
|
||||||
client.Initialize(projectPath);
|
client.Initialize(projectPath);
|
||||||
|
@ -56,7 +78,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
||||||
[InlineData(3, 3)]
|
[InlineData(3, 3)]
|
||||||
public void DthStartup_ProtocolNegotiation(int requestVersion, int expectVersion)
|
public void DthStartup_ProtocolNegotiation(int requestVersion, int expectVersion)
|
||||||
{
|
{
|
||||||
using (var server = new DthTestServer(_testHelper.LoggerFactory))
|
using (var server = new DthTestServer(_loggerFactory))
|
||||||
using (var client = new DthTestClient(server))
|
using (var client = new DthTestClient(server))
|
||||||
{
|
{
|
||||||
client.SetProtocolVersion(requestVersion);
|
client.SetProtocolVersion(requestVersion);
|
||||||
|
@ -71,7 +93,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed()
|
public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed()
|
||||||
{
|
{
|
||||||
using (var server = new DthTestServer(_testHelper.LoggerFactory))
|
using (var server = new DthTestServer(_loggerFactory))
|
||||||
using (var client = new DthTestClient(server))
|
using (var client = new DthTestClient(server))
|
||||||
{
|
{
|
||||||
client.SetProtocolVersion(0);
|
client.SetProtocolVersion(0);
|
||||||
|
@ -92,10 +114,16 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
||||||
string expectedUnresolvedDependency,
|
string expectedUnresolvedDependency,
|
||||||
string expectedUnresolvedType)
|
string expectedUnresolvedType)
|
||||||
{
|
{
|
||||||
var projectPath = _testHelper.FindSampleProject(testProjectName);
|
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Linux)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Test is skipped on Linux");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var projectPath = Path.Combine(_testAssetsManager.AssetsRoot, testProjectName);
|
||||||
Assert.NotNull(projectPath);
|
Assert.NotNull(projectPath);
|
||||||
|
|
||||||
using (var server = new DthTestServer(_testHelper.LoggerFactory))
|
using (var server = new DthTestServer(_loggerFactory))
|
||||||
using (var client = new DthTestClient(server))
|
using (var client = new DthTestClient(server))
|
||||||
{
|
{
|
||||||
client.Initialize(projectPath);
|
client.Initialize(projectPath);
|
||||||
|
@ -149,12 +177,14 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DthNegative_BrokenProjectPathInLockFile()
|
public void DthNegative_BrokenProjectPathInLockFile()
|
||||||
{
|
{
|
||||||
using (var server = new DthTestServer(_testHelper.LoggerFactory))
|
using (var server = new DthTestServer(_loggerFactory))
|
||||||
using (var client = new DthTestClient(server))
|
using (var client = new DthTestClient(server))
|
||||||
{
|
{
|
||||||
// After restore the project is copied to another place so that
|
// After restore the project is copied to another place so that
|
||||||
// the relative path in project lock file is invalid.
|
// the relative path in project lock file is invalid.
|
||||||
var movedProjectPath = _testHelper.BuildProjectCopy("BrokenProjectPathSample");
|
var movedProjectPath = _testAssetsManager.CreateTestInstance("BrokenProjectPathSample")
|
||||||
|
.WithLockFiles()
|
||||||
|
.TestRoot;
|
||||||
|
|
||||||
client.Initialize(movedProjectPath);
|
client.Initialize(movedProjectPath);
|
||||||
|
|
||||||
|
@ -177,10 +207,11 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
||||||
[Fact(Skip = "Require dotnet restore integration test")]
|
[Fact(Skip = "Require dotnet restore integration test")]
|
||||||
public void DthDependencies_UpdateGlobalJson_RefreshDependencies()
|
public void DthDependencies_UpdateGlobalJson_RefreshDependencies()
|
||||||
{
|
{
|
||||||
var projectPath = _testHelper.CreateSampleProject("DthUpdateSearchPathSample");
|
var assets = new TestAssetsManager(Path.Combine(AppContext.BaseDirectory, "TestAssets", "ProjectModelServer"));
|
||||||
|
var projectPath = assets.CreateTestInstance("DthUpdateSearchPathSample").WithLockFiles().TestRoot;
|
||||||
Assert.True(Directory.Exists(projectPath));
|
Assert.True(Directory.Exists(projectPath));
|
||||||
|
|
||||||
using (var server = new DthTestServer(_testHelper.LoggerFactory))
|
using (var server = new DthTestServer(_loggerFactory))
|
||||||
using (var client = new DthTestClient(server))
|
using (var client = new DthTestClient(server))
|
||||||
{
|
{
|
||||||
var testProject = Path.Combine(projectPath, "home", "src", "MainProject");
|
var testProject = Path.Combine(projectPath, "home", "src", "MainProject");
|
||||||
|
@ -235,10 +266,9 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DthStartup_OpenProjectBeforeRestore()
|
public void DthStartup_OpenProjectBeforeRestore()
|
||||||
{
|
{
|
||||||
var projectPath = _testHelper.BuildProjectCopy("EmptyConsoleApp");
|
var projectPath = _testAssetsManager.CreateTestInstance("EmptyConsoleApp").TestRoot;
|
||||||
_testHelper.DeleteLockFile(projectPath);
|
|
||||||
|
|
||||||
using (var server = new DthTestServer(_testHelper.LoggerFactory))
|
using (var server = new DthTestServer(_loggerFactory))
|
||||||
using (var client = new DthTestClient(server))
|
using (var client = new DthTestClient(server))
|
||||||
{
|
{
|
||||||
client.Initialize(projectPath);
|
client.Initialize(projectPath);
|
||||||
|
|
|
@ -1,134 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using Microsoft.DotNet.ProjectModel.Graph;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
|
|
||||||
namespace Microsoft.DotNet.ProjectModel.Server.Tests.Helpers
|
|
||||||
{
|
|
||||||
public class TestHelper
|
|
||||||
{
|
|
||||||
private readonly string _tempPath;
|
|
||||||
|
|
||||||
public TestHelper()
|
|
||||||
{
|
|
||||||
LoggerFactory = new LoggerFactory();
|
|
||||||
|
|
||||||
var testVerbose = Environment.GetEnvironmentVariable("DOTNET_TEST_VERBOSE");
|
|
||||||
if (testVerbose == "2")
|
|
||||||
{
|
|
||||||
LoggerFactory.AddConsole(LogLevel.Trace);
|
|
||||||
}
|
|
||||||
else if (testVerbose == "1")
|
|
||||||
{
|
|
||||||
LoggerFactory.AddConsole(LogLevel.Information);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
LoggerFactory.AddConsole(LogLevel.Warning);
|
|
||||||
}
|
|
||||||
|
|
||||||
_tempPath = CreateTempFolder();
|
|
||||||
var dthTestProjectsFolder = Path.Combine(FindRoot(), "testapp", "DthTestProjects");
|
|
||||||
CopyFiles(dthTestProjectsFolder, _tempPath);
|
|
||||||
|
|
||||||
var logger = LoggerFactory.CreateLogger<TestHelper>();
|
|
||||||
logger.LogInformation($"Test projects are copied to {_tempPath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
public ILoggerFactory LoggerFactory { get; }
|
|
||||||
|
|
||||||
public string FindSampleProject(string name)
|
|
||||||
{
|
|
||||||
var result = Path.Combine(_tempPath, "src", name);
|
|
||||||
if (Directory.Exists(result))
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string CreateSampleProject(string name)
|
|
||||||
{
|
|
||||||
var source = Path.Combine(FindRoot(), "test", name);
|
|
||||||
if (!Directory.Exists(source))
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var target = Path.Combine(CreateTempFolder(), name);
|
|
||||||
CopyFiles(source, target);
|
|
||||||
|
|
||||||
return target;
|
|
||||||
}
|
|
||||||
|
|
||||||
public string BuildProjectCopy(string projectName)
|
|
||||||
{
|
|
||||||
var projectPath = FindSampleProject(projectName);
|
|
||||||
var movedProjectPath = Path.Combine(CreateTempFolder(), projectName);
|
|
||||||
CopyFiles(projectPath, movedProjectPath);
|
|
||||||
|
|
||||||
return movedProjectPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void DeleteLockFile(string folder)
|
|
||||||
{
|
|
||||||
var lockFilePath = Path.Combine(folder, LockFile.FileName);
|
|
||||||
if (File.Exists(lockFilePath))
|
|
||||||
{
|
|
||||||
File.Delete(lockFilePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string FindRoot()
|
|
||||||
{
|
|
||||||
var solutionName = "Microsoft.DotNet.Cli.sln";
|
|
||||||
var root = new DirectoryInfo(Directory.GetCurrentDirectory());
|
|
||||||
|
|
||||||
while (root != null && root.GetFiles(solutionName).Length == 0)
|
|
||||||
{
|
|
||||||
root = Directory.GetParent(root.FullName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (root != null)
|
|
||||||
{
|
|
||||||
return root.FullName;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static string CreateTempFolder()
|
|
||||||
{
|
|
||||||
var result = Path.GetTempFileName();
|
|
||||||
File.Delete(result);
|
|
||||||
Directory.CreateDirectory(result);
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CopyFiles(string sourceFolder, string targetFolder)
|
|
||||||
{
|
|
||||||
if (!Directory.Exists(targetFolder))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(targetFolder);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var filePath in Directory.EnumerateFiles(sourceFolder))
|
|
||||||
{
|
|
||||||
var filename = Path.GetFileName(filePath);
|
|
||||||
File.Copy(filePath, Path.Combine(targetFolder, filename));
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var folderPath in Directory.EnumerateDirectories(sourceFolder))
|
|
||||||
{
|
|
||||||
var folderName = new DirectoryInfo(folderPath).Name;
|
|
||||||
CopyFiles(folderPath, Path.Combine(targetFolder, folderName));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in a new issue