This repository was archived by the owner on Apr 24, 2023. It is now read-only.
forked from daveaglick/Scripty
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScriptyTaskFixture.cs
More file actions
82 lines (69 loc) · 2.64 KB
/
ScriptyTaskFixture.cs
File metadata and controls
82 lines (69 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Diagnostics;
using System.IO;
using NUnit.Framework;
using NUnit.Framework.Internal;
namespace Scripty.MsBuild.Tests
{
[TestFixture]
public class ScriptyTaskFixture
{
static readonly string SolutionFilePath = Path.GetFullPath($"{AppDomain.CurrentDomain.BaseDirectory}/../../SampleSolution/Sample.sln");
static readonly string ProjectFilePath = Path.GetFullPath($"{AppDomain.CurrentDomain.BaseDirectory}/../../SampleSolution/Proj/Proj.csproj");
static readonly string ScriptyAssembly = Path.GetFullPath($"{AppDomain.CurrentDomain.BaseDirectory}/Scripty.MsBuild.dll");
string _msbuild;
string _output;
[OneTimeSetUp]
public void InitFixture()
{
_msbuild = FindMsBuild();
_output = Path.Combine(Path.GetDirectoryName(ProjectFilePath), "test.cs");
}
private static string FindMsBuild()
{
foreach (var v in new[] { "15.0", "14.0", "12.0", "4.0" })
{
string exe = null;
using (var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey($@"SOFTWARE\Microsoft\MSBuild\ToolsVersions\{v}"))
{
if (key != null)
{
exe = (string) key.GetValue("MSBuildToolsPath");
}
}
if (exe != null)
{
return exe + "msbuild.exe";
}
}
throw new ApplicationException("Could not find the location of MSBuild.");
}
[SetUp]
public void InitTest()
{
File.Delete(_output);
}
[Test]
public void UsesSolutionAndProperties()
{
var args = $"\"{SolutionFilePath}\" /p:ScriptyAssembly=\"{ScriptyAssembly}\";Include1=true;Include3=true";
var info = new ProcessStartInfo(_msbuild, args)
{
CreateNoWindow = true,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true
};
Process p = new Process();
p.StartInfo = info;
p.OutputDataReceived += (s, e) => TestContext.Out.WriteLine(e.Data);
p.ErrorDataReceived += (s, e) => TestContext.Out.WriteLine(e.Data);
p.Start();
p.BeginOutputReadLine();
p.WaitForExit();
Assert.AreEqual(0, p.ExitCode);
Assert.That(File.Exists(_output));
Assert.AreEqual($@"//Class1.cs;Class3.cs;ClassSolution.cs", File.ReadAllText(_output));
}
}
}