Skip to content

Commit 6698e6b

Browse files
committed
Add first test case for referencing and running Exe project
See dotnet#1675
1 parent c95a06c commit 6698e6b

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
//
4+
5+
using System.IO;
6+
using System.Linq;
7+
using System.Xml.Linq;
8+
using FluentAssertions;
9+
using Microsoft.DotNet.Cli.Utils;
10+
using Microsoft.NET.TestFramework;
11+
using Microsoft.NET.TestFramework.Assertions;
12+
using Microsoft.NET.TestFramework.Commands;
13+
using Microsoft.NET.TestFramework.ProjectConstruction;
14+
using Xunit;
15+
using Xunit.Abstractions;
16+
17+
namespace Microsoft.NET.Build.Tests
18+
{
19+
public class ReferenceExeTests : SdkTest
20+
{
21+
public ReferenceExeTests(ITestOutputHelper log) : base(log)
22+
{
23+
}
24+
25+
[Fact]
26+
public void ReferencedExeCanRun()
27+
{
28+
var mainProject = new TestProject()
29+
{
30+
Name = "MainProject",
31+
TargetFrameworks = "net5.0",
32+
IsSdkProject = true,
33+
IsExe = true
34+
};
35+
36+
mainProject.SourceFiles["Program.cs"] = @"System.Console.WriteLine(""Main Project"");";
37+
38+
var referencedProject = new TestProject()
39+
{
40+
Name = "ReferencedProject",
41+
TargetFrameworks = "net5.0",
42+
IsSdkProject = true,
43+
IsExe = true
44+
};
45+
46+
referencedProject.SourceFiles["Program.cs"] = @"System.Console.WriteLine(""Referenced Project"");";
47+
48+
mainProject.ReferencedProjects.Add(referencedProject);
49+
50+
var testProjectInstance = _testAssetsManager.CreateTestProject(mainProject);
51+
52+
var buildCommand = new BuildCommand(testProjectInstance);
53+
54+
buildCommand.Execute()
55+
.Should()
56+
.Pass();
57+
58+
var outputDirectory = buildCommand.GetOutputDirectory(mainProject.TargetFrameworks);
59+
60+
var mainExePath = Path.Combine(outputDirectory.FullName, mainProject.Name + Constants.ExeSuffix);
61+
62+
var referencedExePath = Path.Combine(outputDirectory.FullName, referencedProject.Name + Constants.ExeSuffix);
63+
64+
new RunExeCommand(Log, mainExePath)
65+
.Execute()
66+
.Should()
67+
.Pass()
68+
.And
69+
.HaveStdOut("Main Project");
70+
71+
72+
new RunExeCommand(Log, referencedExePath)
73+
.Execute()
74+
.Should()
75+
.Pass()
76+
.And
77+
.HaveStdOut("Referenced Project");
78+
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)