Moved ProjectModel to json.net for GlobalSettings and Project.json. Kept LockFileReader using the old API as I don't have the cycles to add the tests for it at the moment.
Added unit tests covering parsing of Json for all the pieces of the project.json Added a RawRuntimeOptions to Project and made Executable deserialize that into the runtimeOptions of runtimeconfig.json Added tests to cover copying runtimeoptions during dotnet build.
This commit is contained in:
parent
60b23d5115
commit
7b209e5603
24 changed files with 1771 additions and 247 deletions
|
@ -0,0 +1,125 @@
|
|||
// 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.IO;
|
||||
using Microsoft.DotNet.ProjectModel.Files;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel.Tests
|
||||
{
|
||||
public class GivenThatIWantToReadFilePatternsFromJson
|
||||
{
|
||||
private const string SomeProperty = "some property";
|
||||
private static readonly string[] SomeDefaultValues = { $"**{Path.DirectorySeparatorChar}*.cs" };
|
||||
|
||||
[Fact]
|
||||
public void It_returns_empty_when_there_is_no_property_and_no_default_pattern()
|
||||
{
|
||||
var json = new JObject();
|
||||
var patternsCollection = PatternsCollectionHelper.GetPatternsCollection(
|
||||
json,
|
||||
AppContext.BaseDirectory,
|
||||
string.Empty,
|
||||
"some non-existing property");
|
||||
|
||||
patternsCollection.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_uses_the_passed_in_default_collection_when_the_property_is_not_in_the_json()
|
||||
{
|
||||
var json = new JObject();
|
||||
var patternsCollection = PatternsCollectionHelper.GetPatternsCollection(
|
||||
json,
|
||||
AppContext.BaseDirectory,
|
||||
string.Empty,
|
||||
"some non-existing property",
|
||||
SomeDefaultValues);
|
||||
|
||||
patternsCollection.Should().Contain(SomeDefaultValues);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_uses_the_value_in_the_property_when_it_is_a_string()
|
||||
{
|
||||
var json = new JObject();
|
||||
json.Add(SomeProperty, "*");
|
||||
var patternsCollection = PatternsCollectionHelper.GetPatternsCollection(
|
||||
json,
|
||||
AppContext.BaseDirectory,
|
||||
string.Empty,
|
||||
SomeProperty,
|
||||
SomeDefaultValues);
|
||||
|
||||
patternsCollection.Should().Contain("*");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_uses_the_values_in_the_property_when_it_is_a_string_array()
|
||||
{
|
||||
var patterns = new[] {"*", $"**{Path.DirectorySeparatorChar}*.fs"};
|
||||
var json = new JObject();
|
||||
json.Add(SomeProperty, new JArray(patterns));
|
||||
var patternsCollection = PatternsCollectionHelper.GetPatternsCollection(
|
||||
json,
|
||||
AppContext.BaseDirectory,
|
||||
string.Empty,
|
||||
SomeProperty,
|
||||
SomeDefaultValues);
|
||||
|
||||
patternsCollection.Should().Contain(patterns);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_throws_when_the_property_value_is_neither_a_string_nor_an_array()
|
||||
{
|
||||
var json = new JObject();
|
||||
json.Add(SomeProperty, new JObject());
|
||||
Action action = () => PatternsCollectionHelper.GetPatternsCollection(
|
||||
json,
|
||||
AppContext.BaseDirectory,
|
||||
string.Empty,
|
||||
SomeProperty,
|
||||
SomeDefaultValues);
|
||||
|
||||
action.ShouldThrow<FileFormatException>().WithMessage("Value must be either string or array.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_throws_when_we_ask_for_a_literal_and_specify_a_pattern()
|
||||
{
|
||||
var json = new JObject();
|
||||
json.Add(SomeProperty, "*");
|
||||
Action action = () => PatternsCollectionHelper.GetPatternsCollection(
|
||||
json,
|
||||
AppContext.BaseDirectory,
|
||||
string.Empty,
|
||||
SomeProperty,
|
||||
SomeDefaultValues,
|
||||
true);
|
||||
|
||||
action.ShouldThrow<FileFormatException>()
|
||||
.WithMessage($"The '{SomeProperty}' property cannot contain wildcard characters.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_throws_when_the_property_value_is_a_rooted_path()
|
||||
{
|
||||
var json = new JObject();
|
||||
json.Add(SomeProperty, AppContext.BaseDirectory);
|
||||
Action action = () => PatternsCollectionHelper.GetPatternsCollection(
|
||||
json,
|
||||
AppContext.BaseDirectory,
|
||||
string.Empty,
|
||||
SomeProperty,
|
||||
SomeDefaultValues,
|
||||
true);
|
||||
|
||||
action.ShouldThrow<FileFormatException>()
|
||||
.WithMessage($"The '{SomeProperty}' property cannot be a rooted path.");
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue