dotnet-installer/test/dotnet-compile.UnitTests/GivenACompilationDriver.cs
Eric Erhardt 6468b14e1d Move to CoreFX build rc2-23901
Update .exe's project.json Target Framework from dnxcore50 to netstandardapp1.5.
Update .dll's project.json Target Framework from dnxcore50 to netstandard1.3.

Adding workaround for DataContractSerialization to src\dotnet\project.json to fix crossgen issue.
Build 23901 has a dependency issue that doesn't allow the runtime.any.System.Private.DataContractSerialization
package to be restored. When we move to a new build of CoreFX we should take this workaround out.
2016-03-03 16:41:55 -06:00

83 lines
3.2 KiB
C#

// 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 FluentAssertions;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.Tools.Compiler;
using Moq;
using NuGet.Frameworks;
using Xunit;
namespace Microsoft.DotNet.Tools.Compiler.Tests
{
public class GivenACompilationDriverController
{
private string _projectJson;
private Mock<ICompiler> _managedCompilerMock;
private Mock<ICompiler> _nativeCompilerMock;
private List<ProjectContext> _contexts;
private CompilerCommandApp _args;
public GivenACompilationDriverController()
{
_projectJson =
Path.Combine(AppContext.BaseDirectory, "TestAssets", "TestProjects", "TestAppWithLibrary", "TestApp", "project.json");
_managedCompilerMock = new Mock<ICompiler>();
_managedCompilerMock.Setup(c => c
.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()))
.Returns(true);
_nativeCompilerMock = new Mock<ICompiler>();
_nativeCompilerMock.Setup(c => c
.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()))
.Returns(true);
_contexts = new List<ProjectContext>
{
ProjectContext.Create(_projectJson, NuGetFramework.Parse("netstandardapp1.5"))
};
_args = new CompilerCommandApp("dotnet compile", ".NET Compiler", "Compiler for the .NET Platform");
}
[Fact]
public void It_compiles_all_project_contexts()
{
var compiledProjectContexts = new List<ProjectContext>();
_managedCompilerMock.Setup(c => c
.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()))
.Callback<ProjectContext, CompilerCommandApp>((p, c) => compiledProjectContexts.Add(p))
.Returns(true);
var compilerController = new CompilationDriver(_managedCompilerMock.Object, _nativeCompilerMock.Object);
compilerController.Compile(_contexts, _args);
compiledProjectContexts.Should().BeEquivalentTo(_contexts);
}
[Fact]
public void It_does_not_compile_native_when_the_native_parameter_is_not_passed()
{
var compilerController = new CompilationDriver(_managedCompilerMock.Object, _nativeCompilerMock.Object);
compilerController.Compile(_contexts, _args);
_nativeCompilerMock.Verify(c => c.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()), Times.Never);
}
[Fact]
public void It_does_compile_native_when_the_native_parameter_is_passed()
{
var compilerController = new CompilationDriver(_managedCompilerMock.Object, _nativeCompilerMock.Object);
_args.IsNativeValue = true;
compilerController.Compile(_contexts, _args);
_nativeCompilerMock.Verify(c => c.Compile(It.IsAny<ProjectContext>(), It.IsAny<CompilerCommandApp>()), Times.Once);
}
}
}