Skip to content

Commit

Permalink
Add test for setting Configuration in Directory.Build.props
Browse files Browse the repository at this point in the history
  • Loading branch information
dsplaisted committed Mar 14, 2017
1 parent d747e69 commit ea991d7
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
using FluentAssertions;
using Microsoft.NET.TestFramework;
using Microsoft.NET.TestFramework.Assertions;
using Microsoft.NET.TestFramework.ProjectConstruction;
using Microsoft.NET.TestFramework.Commands;
using static Microsoft.NET.TestFramework.Commands.MSBuildTest;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml.Linq;
using Xunit;

namespace Microsoft.NET.Build.Tests
{
public class GivenThatWeWantToSetPropertiesInDirectoryBuildProps : SdkTest
{

[Fact]
public void The_default_configuration_can_be_set_to_release()
{
TestProject project = new TestProject()
{
Name = "DirectoryBuildPropsTest",
TargetFrameworks = "netstandard1.4",
IsSdkProject = true
};

var testAsset = _testAssetsManager.CreateTestProject(project);

string directoryBuildPropsPath = Path.Combine(testAsset.Path, "Directory.Build.props");

var directoryBuildPropsContent = @"
<Project>
<PropertyGroup>
<Configuration Condition="" '$(Configuration)' == '' "">Release</Configuration>
</PropertyGroup>
</Project>
";

File.WriteAllText(directoryBuildPropsPath, directoryBuildPropsContent);

var restoreCommand = testAsset.GetRestoreCommand(project.Name);

restoreCommand
.Execute()
.Should()
.Pass();

string projectFolder = Path.Combine(testAsset.Path, project.Name);

var buildCommand = new BuildCommand(Stage0MSBuild, projectFolder);

buildCommand
.Execute()
.Should()
.Pass();

string GetPropertyValue(string propertyName)
{
var getValuesCommand = new GetValuesCommand(Stage0MSBuild, projectFolder,
project.TargetFrameworks, propertyName, GetValuesCommand.ValueType.Property)
{
Configuration = "Release"
};

getValuesCommand
.Execute()
.Should()
.Pass();

var values = getValuesCommand.GetValues();
values.Count.Should().Be(1);
return values[0];
}

GetPropertyValue("Configuration").Should().Be("Release");
GetPropertyValue("Optimize").Should().Be("true");
}

}
}
4 changes: 0 additions & 4 deletions test/Microsoft.NET.TestFramework/Commands/GetValuesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,6 @@ public List<string> GetValues()
string outputFilename = $"{_valueName}Values.txt";
var outputDirectory = GetOutputDirectory(_targetFramework, Configuration ?? "Debug");

outputDirectory.Should().OnlyHaveFiles(new[] {
outputFilename,
});

return File.ReadAllLines(Path.Combine(outputDirectory.FullName, outputFilename))
.Select(line => line.Trim())
.Where(line => !string.IsNullOrEmpty(line))
Expand Down

0 comments on commit ea991d7

Please sign in to comment.