-
Notifications
You must be signed in to change notification settings - Fork 225
/
ProcessExecutorStub.cs
72 lines (65 loc) · 2.64 KB
/
ProcessExecutorStub.cs
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
namespace CruiseControl.Core.Tests.Stubs
{
using System;
using System.IO;
using CruiseControl.Core.Interfaces;
using CruiseControl.Core.Utilities;
using Moq;
using NUnit.Framework;
public class ProcessExecutorStub
: IProcessExecutor
{
public ProcessExecutorStub(
string fileName,
string args,
string workingDir,
ProjectItem item,
TaskExecutionContext context)
{
this.FileName = fileName;
this.Arguments = args;
this.WorkingDirectory = workingDir;
this.Item = item;
this.Context = context;
}
public string FileName { get; set; }
public string Arguments { get; set; }
public string WorkingDirectory { get; set; }
public ProjectItem Item { get; set; }
public TaskExecutionContext Context { get; set; }
public bool Failed { get; set; }
public bool TimedOut { get; set; }
public int ExitCode { get; set; }
public ProcessResult Execute(ProcessInfo processInfo, string projectName, string itemId, string outputFile)
{
throw new NotImplementedException();
}
public ProcessResult Execute(ProcessInfo processInfo, ProjectItem item, TaskExecutionContext context)
{
var outputFile = context.GeneratePathInWorkingDirectory(item.NameOrType + ".log");
if ((this.Item == null) || (this.Context == null))
{
return this.Execute(processInfo,
item.Project.Name,
item.NameOrType,
outputFile);
}
Assert.AreEqual(this.FileName, processInfo.FileName);
var actual = processInfo.Arguments == null ? null : processInfo.Arguments.ToString();
Assert.AreEqual(this.Arguments, actual);
Assert.AreEqual(this.WorkingDirectory, processInfo.WorkingDirectory);
Assert.AreSame(this.Item, item);
Assert.AreEqual(this.Context, context);
var fileSystemMock = new Mock<IFileSystem>();
fileSystemMock.Setup(fs => fs.OpenFileForRead(outputFile)).Returns(new MemoryStream());
var result = new ProcessResult(
fileSystemMock.Object,
outputFile,
this.ExitCode,
this.TimedOut,
this.Failed);
return result;
}
public event EventHandler<ProcessOutputEventArgs> ProcessOutput;
}
}