Add tests to capture issue 1568

This commit is contained in:
Troy Dai 2016-02-29 10:46:13 -08:00
parent ab5df03700
commit 78433197b3
6 changed files with 96 additions and 0 deletions

View file

@ -0,0 +1,9 @@
{
"version": "1.0.0-*",
"dependencies": {
"
},
"frameworks": {
[]
}
}

View file

@ -0,0 +1,3 @@
{
"projects": ["src"]]
}

View file

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
</packageSources>
</configuration>

View file

@ -0,0 +1,12 @@
using System;
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
}
}
}

View file

@ -0,0 +1,14 @@
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"NETStandard.Library": "1.0.0-rc2-23811"
},
"frameworks": {
"dnxcore50": { }
}
}

View file

@ -9,6 +9,7 @@ using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.PlatformAbstractions;
using Microsoft.DotNet.TestFramework;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;
@ -286,5 +287,53 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
}
}
}
[Fact]
public void InvalidProjectJson()
{
using (var server = new DthTestServer(_loggerFactory))
using (var client = new DthTestClient(server))
{
client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "EmptyLibrary"));
client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "BrokenProjectFileSample"));
// Error for invalid project.json
var messages = client.DrainAllMessages();
messages.Single(msg => msg.MessageType == MessageTypes.Error)
.Payload.AsJObject()
.AssertProperty<string>("Path", v => v.Contains("BrokenProjectFileSample"));
// Successfully initialize the other project
messages.Single(msg => msg.MessageType == MessageTypes.ProjectInformation)
.Payload.AsJObject()
.AssertProperty<string>("Name", v => string.Equals(v, "EmptyLibrary", StringComparison.Ordinal));
// Successfully initialize another project afterwards
client.Initialize(Path.Combine(_testAssetsManager.AssetsRoot, "EmptyConsoleApp"));
messages = client.DrainAllMessages();
messages.Single(msg => msg.MessageType == MessageTypes.ProjectInformation)
.Payload.AsJObject()
.AssertProperty<string>("Name", v => string.Equals(v, "EmptyConsoleApp", StringComparison.Ordinal));
}
}
[Fact]
public void InvalidGlobalJson()
{
var testAssetsPath = Path.Combine(RepoRoot, "TestAssets", "ProjectModelServer");
var assetsManager = new TestAssetsManager(testAssetsPath);
var testSource = assetsManager.CreateTestInstance("IncorrectGlobalJson");
using (var server = new DthTestServer(_loggerFactory))
using (var client = new DthTestClient(server))
{
client.Initialize(Path.Combine(testSource.TestRoot, "src", "Project1"));
var messages = client.DrainAllMessages();
messages.ContainsMessage(MessageTypes.Error)
.Single().Payload.AsJObject()
.AssertProperty<string>("Path", v => v.Contains("InvalidGlobalJson"));
}
}
}
}