2016-04-17 08:42:36 +00:00
|
|
|
// 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;
|
2016-10-14 07:06:35 +00:00
|
|
|
using Microsoft.Build.Construction;
|
2016-04-17 08:42:36 +00:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
using Xunit;
|
|
|
|
using FluentAssertions;
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
namespace Microsoft.DotNet.New.Tests
|
2016-04-17 08:42:36 +00:00
|
|
|
{
|
|
|
|
public class GivenThatIWantANewCSApp : TestBase
|
|
|
|
{
|
2016-10-14 07:06:35 +00:00
|
|
|
[Fact(Skip="https://github.com/dotnet/cli/issues/4381")]
|
2016-04-17 08:42:36 +00:00
|
|
|
public void When_NewtonsoftJson_dependency_added_Then_project_restores_and_runs()
|
|
|
|
{
|
2016-10-14 07:06:35 +00:00
|
|
|
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
|
|
|
|
var projectName = new DirectoryInfo(rootPath).Name;
|
|
|
|
var projectFile = Path.Combine(rootPath, $"{projectName}.csproj");
|
2016-04-17 08:42:36 +00:00
|
|
|
|
|
|
|
new TestCommand("dotnet") { WorkingDirectory = rootPath }
|
|
|
|
.Execute("new");
|
|
|
|
|
2016-10-14 07:06:35 +00:00
|
|
|
AddProjectDependency(projectFile, "Newtonsoft.Json", "7.0.1");
|
2016-04-17 08:42:36 +00:00
|
|
|
|
|
|
|
new TestCommand("dotnet") { WorkingDirectory = rootPath }
|
2016-10-28 01:46:43 +00:00
|
|
|
.Execute("restore /p:SkipInvalidConfigurations=true")
|
2016-04-17 08:42:36 +00:00
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
new TestCommand("dotnet") { WorkingDirectory = rootPath }
|
2016-10-28 01:46:43 +00:00
|
|
|
.Execute("run")
|
2016-04-17 08:42:36 +00:00
|
|
|
.Should().Pass();
|
|
|
|
}
|
|
|
|
|
2016-05-03 21:07:50 +00:00
|
|
|
[Fact]
|
2016-10-14 07:06:35 +00:00
|
|
|
public void When_dotnet_build_is_invoked_Then_app_builds_without_warnings()
|
2016-05-03 21:07:50 +00:00
|
|
|
{
|
2016-10-14 07:06:35 +00:00
|
|
|
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
|
2016-05-03 21:07:50 +00:00
|
|
|
|
|
|
|
new TestCommand("dotnet") { WorkingDirectory = rootPath }
|
|
|
|
.Execute("new");
|
|
|
|
|
|
|
|
new TestCommand("dotnet") { WorkingDirectory = rootPath }
|
2016-10-28 01:46:43 +00:00
|
|
|
.Execute("restore /p:SkipInvalidConfigurations=true");
|
2016-05-03 21:07:50 +00:00
|
|
|
|
|
|
|
var buildResult = new TestCommand("dotnet") { WorkingDirectory = rootPath }
|
2016-10-28 01:46:43 +00:00
|
|
|
.ExecuteWithCapturedOutput("build");
|
2016-05-03 21:07:50 +00:00
|
|
|
|
2016-10-14 07:06:35 +00:00
|
|
|
buildResult.Should().Pass()
|
|
|
|
.And.NotHaveStdErr();
|
2016-05-03 21:07:50 +00:00
|
|
|
}
|
2016-06-14 20:20:29 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void When_dotnet_new_is_invoked_mupliple_times_it_should_fail()
|
|
|
|
{
|
2016-10-14 07:06:35 +00:00
|
|
|
var rootPath = TestAssetsManager.CreateTestDirectory().Path;
|
2016-06-14 20:20:29 +00:00
|
|
|
|
|
|
|
new TestCommand("dotnet") { WorkingDirectory = rootPath }
|
|
|
|
.Execute("new");
|
|
|
|
|
|
|
|
DateTime expectedState = Directory.GetLastWriteTime(rootPath);
|
|
|
|
|
|
|
|
var result = new TestCommand("dotnet") { WorkingDirectory = rootPath }
|
|
|
|
.ExecuteWithCapturedOutput("new");
|
|
|
|
|
|
|
|
DateTime actualState = Directory.GetLastWriteTime(rootPath);
|
|
|
|
|
|
|
|
Assert.Equal(expectedState, actualState);
|
|
|
|
|
2016-10-14 07:06:35 +00:00
|
|
|
result.Should().Fail()
|
|
|
|
.And.HaveStdErr();
|
2016-06-14 20:20:29 +00:00
|
|
|
}
|
2016-05-03 21:07:50 +00:00
|
|
|
|
2016-10-14 07:06:35 +00:00
|
|
|
private static void AddProjectDependency(string projectFilePath, string dependencyId, string dependencyVersion)
|
2016-04-17 08:42:36 +00:00
|
|
|
{
|
2016-10-14 07:06:35 +00:00
|
|
|
var projectRootElement = ProjectRootElement.Open(projectFilePath);
|
2016-04-17 08:42:36 +00:00
|
|
|
|
2016-10-14 07:06:35 +00:00
|
|
|
projectRootElement.AddItem("PackageReference", dependencyId, new Dictionary<string, string>{{"Version", dependencyVersion}});
|
2016-04-17 08:42:36 +00:00
|
|
|
|
2016-10-14 07:06:35 +00:00
|
|
|
projectRootElement.Save();
|
2016-04-17 08:42:36 +00:00
|
|
|
}
|
|
|
|
}
|
2016-04-17 17:04:12 +00:00
|
|
|
}
|