trim build dependencies from output

This commit is contained in:
Andrew Stanton-Nurse 2016-05-02 19:51:12 -07:00
parent afa471cde3
commit 08c4aae6a9
11 changed files with 209 additions and 51 deletions

View file

@ -1,14 +1,17 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
using Xunit;
namespace Microsoft.DotNet.ProjectModel.Tests
{
public class ProjectContextBuilderTests
public class ProjectContextBuilderTests : TestBase
{
private static readonly HashSet<string> KnownProperties = new HashSet<string>(StringComparer.Ordinal) {
"Project",
@ -48,7 +51,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var clonedBuilder = initialBuilder.Clone();
// Compare all the properties. This is a shallow clone, so they should all be exactly ReferenceEqual
foreach(var prop in typeof(ProjectContextBuilder).GetTypeInfo().DeclaredProperties)
foreach (var prop in typeof(ProjectContextBuilder).GetTypeInfo().DeclaredProperties)
{
KnownProperties.Remove(prop.Name).Should().BeTrue(because: $"{prop.Name} should be listed in the known properties to ensure it is properly tested.");
@ -65,5 +68,18 @@ namespace Microsoft.DotNet.ProjectModel.Tests
KnownProperties.Should().BeEmpty(because: "all properties should have been checked by the CloneTest");
}
[Fact]
public void BuildAllTargetsProperlyDeduplicatesTargets()
{
// Load all project contexts for the test project
var contexts = new ProjectContextBuilder()
.WithProjectDirectory(Path.Combine(TestAssetsManager.AssetsRoot, "TestProjectContextBuildAllDedupe"))
.BuildAllTargets()
.ToList();
// This is a portable app, so even though RIDs are specified, BuildAllTargets should only produce one output.
Assert.Equal(1, contexts.Count);
}
}
}

View file

@ -19,7 +19,7 @@ namespace Microsoft.Extensions.Testing.Abstractions.UnitTests
public void It_creates_a_pdb_reader_right_away()
{
var pdbReaderFactoryMock = new Mock<IPdbReaderFactory>();
var sourceInformationProvider = new SourceInformationProvider(_pdbPath, null, pdbReaderFactoryMock.Object);
var sourceInformationProvider = new SourceInformationProvider(_pdbPath, pdbReaderFactoryMock.Object);
pdbReaderFactoryMock.Verify(p => p.Create(_pdbPath), Times.Once);
}
@ -37,7 +37,7 @@ namespace Microsoft.Extensions.Testing.Abstractions.UnitTests
var pdbReaderFactoryMock = new Mock<IPdbReaderFactory>();
pdbReaderFactoryMock.Setup(p => p.Create(_pdbPath)).Returns(pdbReaderMock.Object);
var sourceInformationProvider = new SourceInformationProvider(_pdbPath, null, pdbReaderFactoryMock.Object);
var sourceInformationProvider = new SourceInformationProvider(_pdbPath, pdbReaderFactoryMock.Object);
var actualSourceInformation = sourceInformationProvider.GetSourceInformation(methodInfo);
@ -53,7 +53,7 @@ namespace Microsoft.Extensions.Testing.Abstractions.UnitTests
pdbReaderFactoryMock.Setup(p => p.Create(_pdbPath)).Returns(pdbReaderMock.Object);
using (var sourceInformationProvider =
new SourceInformationProvider(_pdbPath, null, pdbReaderFactoryMock.Object))
new SourceInformationProvider(_pdbPath, pdbReaderFactoryMock.Object))
{
}

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Microsoft.DotNet.Tools.Test.Utilities;
using Microsoft.Extensions.DependencyModel;
using Xunit;
namespace Microsoft.DotNet.Tools.Publish.Tests
{
public class PublishAppWithBuildDependency : TestBase
{
[Fact]
public void PublishExcludesBuildDependencies()
{
var testInstance = TestAssetsManager.CreateTestInstance("AppWithDirectDependencyAndTypeBuild")
.WithLockFiles();
new RestoreCommand() { WorkingDirectory = testInstance.TestRoot }.Execute().Should().Pass();
var publishCommand = new PublishCommand(testInstance.TestRoot);
var publishResult = publishCommand.Execute();
publishResult.Should().Pass();
var publishDir = publishCommand.GetOutputDirectory(portable: true);
publishDir.Should().HaveFiles(new[]
{
// This one is directly referenced
"xunit.core.dll"
});
// But these are brought in only by the type:build dependency, and should not be published
publishDir.Should().NotHaveFiles(new [] {
"xunit.assert.dll"
});
// Check the deps file
var reader = new DependencyContextJsonReader();
DependencyContext context;
using (var file = File.OpenRead(Path.Combine(publishDir.FullName, "AppWithDirectDependencyAndTypeBuild.deps.json")))
{
context = reader.Read(file);
}
context.RuntimeLibraries.Should().NotContain(l => string.Equals(l.Name, "xunit.assert"));
context.CompileLibraries.Should().NotContain(l => string.Equals(l.Name, "xunit.assert"));
}
}
}