Integrate ProjectModel server tests

This commit is contained in:
Troy Dai 2016-02-17 16:49:34 -08:00
parent b5de686ba4
commit f7e4714dc5
20 changed files with 28 additions and 29 deletions
TestAssets/ProjectModelServer
DthTestProjects
global.json
src
BrokenProjectPathSample
EmptyConsoleApp
EmptyLibrary
FailReleaseProject
IncompatiblePackageSample
UnresolvedPackageSample
UnresolvedProjectSample
DthUpdateSearchPathSample
ext/Newtonsoft.Json
home
scripts/dotnet-cli-build
test/dotnet-projectmodel-server.Tests

View file

@ -1,7 +1,7 @@
{
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811",
"EmptyLibrary": ""
"EmptyLibrary": "1.0.0-*"
},
"frameworks": {
"dnxcore50": { }

View file

@ -1,4 +1,5 @@
{
"version": "1.0.0-*",
"dependencies": { },
"frameworks": {
"dnxcore50": {

View file

@ -1,6 +1,6 @@
{
"dependencies": {
"EmptyLibrary": ""
"EmptyLibrary": "1.0.0-*"
},
"frameworks": {
"dnx451": { }

View file

@ -28,6 +28,7 @@ namespace Microsoft.DotNet.Cli.Build
"dotnet-compile.UnitTests",
"dotnet-build.Tests",
"dotnet-pack.Tests",
"dotnet-projectmodel-server.Tests",
"dotnet-resgen.Tests",
"dotnet-run.Tests",
"Microsoft.DotNet.Cli.Utils.Tests",
@ -76,8 +77,11 @@ namespace Microsoft.DotNet.Cli.Build
.WorkingDirectory(Path.Combine(c.BuildContext.BuildDirectory, "TestAssets", "TestProjects"))
.Execute().EnsureSuccessful();
// The 'testapp' 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();
// 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, "TestAssets", "ProjectModelServer"))
.CaptureStdErr()
.CaptureStdOut()
.Execute();
return c.Success();
}

View file

@ -9,7 +9,6 @@ using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Xunit;
@ -34,6 +33,9 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
public DthTestClient(DthTestServer server)
{
// Avoid Socket exception 10006 on Linux
Thread.Sleep(100);
_socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);

View file

@ -5,6 +5,8 @@ using System;
using System.IO;
using System.Linq;
using Microsoft.DotNet.ProjectModel.Server.Tests.Helpers;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.PlatformAbstractions;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
@ -92,6 +94,12 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
string expectedUnresolvedDependency,
string expectedUnresolvedType)
{
if (PlatformServices.Default.Runtime.OperatingSystemPlatform == Platform.Linux)
{
Console.WriteLine("Test is skipped on Linux");
return;
}
var projectPath = _testHelper.FindSampleProject(testProjectName);
Assert.NotNull(projectPath);

View file

@ -8,6 +8,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests.Helpers
public class TestHelper
{
private readonly string _tempPath;
private readonly string _testProjectsDir;
public TestHelper()
{
@ -28,8 +29,8 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests.Helpers
}
_tempPath = CreateTempFolder();
var dthTestProjectsFolder = Path.Combine(FindRoot(), "testapp", "DthTestProjects");
CopyFiles(dthTestProjectsFolder, _tempPath);
_testProjectsDir = Path.Combine(AppContext.BaseDirectory, "TestAssets", "ProjectModelServer");
CopyFiles(_testProjectsDir, _tempPath);
var logger = LoggerFactory.CreateLogger<TestHelper>();
logger.LogInformation($"Test projects are copied to {_tempPath}");
@ -39,7 +40,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests.Helpers
public string FindSampleProject(string name)
{
var result = Path.Combine(_tempPath, "src", name);
var result = Path.Combine(_tempPath, "DthTestProjects", "src", name);
if (Directory.Exists(result))
{
return result;
@ -52,7 +53,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests.Helpers
public string CreateSampleProject(string name)
{
var source = Path.Combine(FindRoot(), "test", name);
var source = Path.Combine(AppContext.BaseDirectory, "TestAssets", "ProjectModelServer");
if (!Directory.Exists(source))
{
return null;
@ -82,26 +83,6 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests.Helpers
}
}
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();

View file

@ -11,5 +11,8 @@
"imports": "portable-net45+win8"
}
},
"content": [
"../../TestAssets/ProjectModelServer/**"
],
"testRunner": "xunit"
}