Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Merge branch 'troy/add.test.wip' into rel/1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
troydai committed Mar 1, 2016
2 parents de89da6 + 13f97b0 commit 7582649
Show file tree
Hide file tree
Showing 19 changed files with 61 additions and 158 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811",
"EmptyLibrary": ""
"EmptyLibrary": "1.0.0-*"
},
"frameworks": {
"dnxcore50": { }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"version": "1.0.0-*",
"dependencies": { },
"frameworks": {
"dnxcore50": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"dependencies": {
"EmptyLibrary": ""
"EmptyLibrary": "1.0.0-*"
},
"frameworks": {
"dnx451": { }
Expand Down
8 changes: 6 additions & 2 deletions scripts/dotnet-cli-build/TestTargets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class TestTargets
"dotnet-compile.UnitTests",
"dotnet-build.Tests",
"dotnet-pack.Tests",
"dotnet-projectmodel-server.Tests",
"dotnet-resgen.Tests",
"dotnet-run.Tests",
"Microsoft.DotNet.Cli.Utils.Tests",
Expand Down Expand Up @@ -76,8 +77,11 @@ public static BuildTargetResult RestoreTestAssetProjects(BuildTargetContext c)
.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();
}
Expand Down
4 changes: 3 additions & 1 deletion test/dotnet-projectmodel-server.Tests/DthTestClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Xunit;

Expand All @@ -34,6 +33,9 @@ public class DthTestClient : IDisposable

public DthTestClient(DthTestServer server)
{
// Avoid Socket exception 10006 on Linux
Thread.Sleep(100);

_socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
Expand Down
68 changes: 49 additions & 19 deletions test/dotnet-projectmodel-server.Tests/DthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,51 @@
using System;
using System.IO;
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.Linq;
using Xunit;

namespace Microsoft.DotNet.ProjectModel.Server.Tests
{
public class DthTests : IClassFixture<TestHelper>
public class DthTests : TestBase
{
private readonly TestHelper _testHelper;

public DthTests(TestHelper helper)
private readonly TestAssetsManager _testAssetsManager;
private readonly ILoggerFactory _loggerFactory;

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]
public void DthStartup_GetProjectInformation()
{
var projectPath = _testHelper.FindSampleProject("EmptyConsoleApp");
var projectPath = Path.Combine(_testAssetsManager.AssetsRoot, "EmptyConsoleApp");
Assert.NotNull(projectPath);

using (var server = new DthTestServer(_testHelper.LoggerFactory))
using (var server = new DthTestServer(_loggerFactory))
using (var client = new DthTestClient(server))
{
client.Initialize(projectPath);
Expand Down Expand Up @@ -56,7 +78,7 @@ public void DthStartup_GetProjectInformation()
[InlineData(3, 3)]
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))
{
client.SetProtocolVersion(requestVersion);
Expand All @@ -71,7 +93,7 @@ public void DthStartup_ProtocolNegotiation(int requestVersion, int expectVersion
[Fact]
public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed()
{
using (var server = new DthTestServer(_testHelper.LoggerFactory))
using (var server = new DthTestServer(_loggerFactory))
using (var client = new DthTestClient(server))
{
client.SetProtocolVersion(0);
Expand All @@ -92,10 +114,16 @@ public void DthCompilation_Initialize_UnresolvedDependency(string referenceType,
string expectedUnresolvedDependency,
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);

using (var server = new DthTestServer(_testHelper.LoggerFactory))
using (var server = new DthTestServer(_loggerFactory))
using (var client = new DthTestClient(server))
{
client.Initialize(projectPath);
Expand Down Expand Up @@ -149,12 +177,14 @@ public void DthCompilation_Initialize_UnresolvedDependency(string referenceType,
[Fact]
public void DthNegative_BrokenProjectPathInLockFile()
{
using (var server = new DthTestServer(_testHelper.LoggerFactory))
using (var server = new DthTestServer(_loggerFactory))
using (var client = new DthTestClient(server))
{
// After restore the project is copied to another place so that
// the relative path in project lock file is invalid.
var movedProjectPath = _testHelper.BuildProjectCopy("BrokenProjectPathSample");
var movedProjectPath = _testAssetsManager.CreateTestInstance("BrokenProjectPathSample")
.WithLockFiles()
.TestRoot;

client.Initialize(movedProjectPath);

Expand All @@ -177,10 +207,11 @@ public void DthNegative_BrokenProjectPathInLockFile()
[Fact(Skip = "Require dotnet restore integration test")]
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));

using (var server = new DthTestServer(_testHelper.LoggerFactory))
using (var server = new DthTestServer(_loggerFactory))
using (var client = new DthTestClient(server))
{
var testProject = Path.Combine(projectPath, "home", "src", "MainProject");
Expand Down Expand Up @@ -235,10 +266,9 @@ public void DthDependencies_UpdateGlobalJson_RefreshDependencies()
[Fact]
public void DthStartup_OpenProjectBeforeRestore()
{
var projectPath = _testHelper.BuildProjectCopy("EmptyConsoleApp");
_testHelper.DeleteLockFile(projectPath);
var projectPath = _testAssetsManager.CreateTestInstance("EmptyConsoleApp").TestRoot;

using (var server = new DthTestServer(_testHelper.LoggerFactory))
using (var server = new DthTestServer(_loggerFactory))
using (var client = new DthTestClient(server))
{
client.Initialize(projectPath);
Expand Down
134 changes: 0 additions & 134 deletions test/dotnet-projectmodel-server.Tests/Helpers/TestHelper.cs

This file was deleted.

0 comments on commit 7582649

Please sign in to comment.