From d45032c9d73970b20935c54e7e3adb1aa8f35971 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Sun, 17 Apr 2016 01:42:36 -0700 Subject: [PATCH 1/3] Unit test added and Red --- .gitignore | 2 + scripts/dotnet-cli-build/TestTargets.cs | 15 ++-- .../GivenThatIWantANewCSApp.cs | 70 +++++++++++++++++++ test/dotnet-new.Tests/project.json | 28 ++++++++ 4 files changed, 108 insertions(+), 7 deletions(-) create mode 100644 test/dotnet-new.Tests/GivenThatIWantANewCSApp.cs create mode 100644 test/dotnet-new.Tests/project.json diff --git a/.gitignore b/.gitignore index 24c566a59..7e56f9616 100644 --- a/.gitignore +++ b/.gitignore @@ -142,6 +142,8 @@ $tf/ _ReSharper*/ *.[Rr]e[Ss]harper *.DotSettings.user +.idea/ +*.iml # JustCode is a .NET coding add-in .JustCode diff --git a/scripts/dotnet-cli-build/TestTargets.cs b/scripts/dotnet-cli-build/TestTargets.cs index ba6de920a..eb36712c5 100644 --- a/scripts/dotnet-cli-build/TestTargets.cs +++ b/scripts/dotnet-cli-build/TestTargets.cs @@ -17,25 +17,26 @@ namespace Microsoft.DotNet.Cli.Build public static readonly string[] TestProjects = new[] { + "ArgumentForwardingTests", "EndToEnd", "dotnet.Tests", - "dotnet-publish.Tests", + "dotnet-build.Tests", "dotnet-compile.Tests", "dotnet-compile.UnitTests", "dotnet-compile-fsc.Tests", - "dotnet-build.Tests", + "dotnet-new.Tests", "dotnet-pack.Tests", "dotnet-projectmodel-server.Tests", + "dotnet-publish.Tests", "dotnet-resgen.Tests", "dotnet-run.Tests", + "dotnet-test.Tests", + "dotnet-test.UnitTests", + "Kestrel.Tests", "Microsoft.DotNet.Cli.Utils.Tests", "Microsoft.DotNet.Compiler.Common.Tests", "Microsoft.DotNet.ProjectModel.Tests", - "Microsoft.Extensions.DependencyModel.Tests", - "ArgumentForwardingTests", - "dotnet-test.UnitTests", - "dotnet-test.Tests", - "Kestrel.Tests" + "Microsoft.Extensions.DependencyModel.Tests" }; public static readonly dynamic[] ConditionalTestAssets = new[] diff --git a/test/dotnet-new.Tests/GivenThatIWantANewCSApp.cs b/test/dotnet-new.Tests/GivenThatIWantANewCSApp.cs new file mode 100644 index 000000000..c0ae53e5a --- /dev/null +++ b/test/dotnet-new.Tests/GivenThatIWantANewCSApp.cs @@ -0,0 +1,70 @@ +// 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 Microsoft.DotNet.Tools.Test.Utilities; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Xunit; +using FluentAssertions; + +namespace Microsoft.DotNet.Tests +{ + public class GivenThatIWantANewCSApp : TestBase + { + [Fact] + public void When_NewtonsoftJson_dependency_added_Then_project_restores_and_runs() + { + var rootPath = Temp.CreateDirectory().Path; + var projectJsonFile = Path.Combine(rootPath, "project.json"); + + new TestCommand("dotnet") { WorkingDirectory = rootPath } + .Execute("new"); + + AddProjectJsonDependency(projectJsonFile, "Newtonsoft.Json", "7.0.1"); + + new TestCommand("dotnet") { WorkingDirectory = rootPath } + .Execute("restore") + .Should().Pass(); + + new TestCommand("dotnet") { WorkingDirectory = rootPath } + .Execute("run") + .Should().Pass(); + } + + private static void AddProjectJsonDependency(string projectJsonPath, string dependencyId, string dependencyVersion) + { + var projectJsonRoot = ReadProject(projectJsonPath); + + var dependenciesNode = projectJsonRoot + .Descendants() + .OfType() + .First(p => p.Name == "dependencies"); + + ((JObject)dependenciesNode.Value).Add(new JProperty(dependencyId, dependencyVersion)); + + WriteProject(projectJsonRoot, projectJsonPath); + } + + private static JObject ReadProject(string projectJsonPath) + { + using (TextReader projectFileReader = File.OpenText(projectJsonPath)) + { + var projectJsonReader = new JsonTextReader(projectFileReader); + + var serializer = new JsonSerializer(); + return serializer.Deserialize(projectJsonReader); + } + } + + private static void WriteProject(JObject projectRoot, string projectJsonPath) + { + string projectJson = JsonConvert.SerializeObject(projectRoot, Formatting.Indented); + + File.WriteAllText(projectJsonPath, projectJson + Environment.NewLine); + } + } +} \ No newline at end of file diff --git a/test/dotnet-new.Tests/project.json b/test/dotnet-new.Tests/project.json new file mode 100644 index 000000000..ba9df8166 --- /dev/null +++ b/test/dotnet-new.Tests/project.json @@ -0,0 +1,28 @@ +{ + "version": "1.0.0-*", + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.0-rc2-*" + }, + "Microsoft.DotNet.Tools.Tests.Utilities": { + "target": "project" + }, + "Newtonsoft.Json": "7.0.1", + "dotnet": { + "target": "project" + }, + "xunit": "2.1.0", + "dotnet-test-xunit": "1.0.0-dev-140469-38" + }, + "frameworks": { + "netcoreapp1.0": { + "imports": [ + "netstandardapp1.5", + "dnxcore50", + "portable-net45+win8" + ] + } + }, + "testRunner": "xunit" +} \ No newline at end of file From 496ec6b4742ac6418e2c38921804106aa156a224 Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Sun, 17 Apr 2016 10:04:12 -0700 Subject: [PATCH 2/3] dotnet-new template imports dnxcore50. Tests Green. --- .../dotnet-new/CSharp_Console/project.json.pretemplate | 4 +++- test/dotnet-new.Tests/GivenThatIWantANewCSApp.cs | 2 +- test/dotnet-new.Tests/project.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/dotnet/commands/dotnet-new/CSharp_Console/project.json.pretemplate b/src/dotnet/commands/dotnet-new/CSharp_Console/project.json.pretemplate index 666dee54e..88f99d13e 100644 --- a/src/dotnet/commands/dotnet-new/CSharp_Console/project.json.pretemplate +++ b/src/dotnet/commands/dotnet-new/CSharp_Console/project.json.pretemplate @@ -10,6 +10,8 @@ } }, "frameworks": { - "netcoreapp1.0": {} + "netcoreapp1.0": { + "imports": "dnxcore50" + } } } diff --git a/test/dotnet-new.Tests/GivenThatIWantANewCSApp.cs b/test/dotnet-new.Tests/GivenThatIWantANewCSApp.cs index c0ae53e5a..089e03208 100644 --- a/test/dotnet-new.Tests/GivenThatIWantANewCSApp.cs +++ b/test/dotnet-new.Tests/GivenThatIWantANewCSApp.cs @@ -67,4 +67,4 @@ namespace Microsoft.DotNet.Tests File.WriteAllText(projectJsonPath, projectJson + Environment.NewLine); } } -} \ No newline at end of file +} diff --git a/test/dotnet-new.Tests/project.json b/test/dotnet-new.Tests/project.json index ba9df8166..8cc41de4d 100644 --- a/test/dotnet-new.Tests/project.json +++ b/test/dotnet-new.Tests/project.json @@ -25,4 +25,4 @@ } }, "testRunner": "xunit" -} \ No newline at end of file +} From c231910e7d72d5ea8669090a38d996f7d537526b Mon Sep 17 00:00:00 2001 From: Piotr Puszkiewicz Date: Tue, 19 Apr 2016 11:23:16 -0700 Subject: [PATCH 3/3] Remove netstandardapp1.5 import --- test/dotnet-new.Tests/project.json | 1 - 1 file changed, 1 deletion(-) diff --git a/test/dotnet-new.Tests/project.json b/test/dotnet-new.Tests/project.json index 8cc41de4d..3b7503209 100644 --- a/test/dotnet-new.Tests/project.json +++ b/test/dotnet-new.Tests/project.json @@ -18,7 +18,6 @@ "frameworks": { "netcoreapp1.0": { "imports": [ - "netstandardapp1.5", "dnxcore50", "portable-net45+win8" ]