forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoadLineProcessorTests.cs
More file actions
120 lines (93 loc) · 3.78 KB
/
LoadLineProcessorTests.cs
File metadata and controls
120 lines (93 loc) · 3.78 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using Moq;
using Ploeh.AutoFixture.Xunit;
using ScriptCs.Contracts;
using Should;
using Xunit.Extensions;
using Should.Core.Assertions;
using ScriptCs.Contracts.Exceptions;
namespace ScriptCs.Tests
{
public class LoadLineProcessorTests
{
public class TheProcessLineMethod : IDisposable
{
private const string EnvVarKey = "scriptcs";
private const string EnvVarValue = "Awesomeness!";
public TheProcessLineMethod()
{
Environment.SetEnvironmentVariable(EnvVarKey, EnvVarValue);
}
[Theory, ScriptCsAutoData]
public void ShouldReturnTrueOnLoadLine(IFileParser parser, LoadLineProcessor processor)
{
// Arrange
const string Line = @"#load ""script.csx""";
// Act
var result = processor.ProcessLine(parser, new FileParserContext(), Line, true);
// Assert
result.ShouldBeTrue();
}
[Theory, ScriptCsAutoData]
public void ShouldReturnFalseOtherwise(IFileParser parser, LoadLineProcessor processor)
{
// Arrange
const string Line = @"var x = new Test();";
// Act
var result = processor.ProcessLine(parser, new FileParserContext(), Line, true);
// Assert
result.ShouldBeFalse();
}
[Theory, ScriptCsAutoData]
public void ShouldThrowExceptionIfAfterCode(
[Frozen] Mock<IFileParser> parser,
[Frozen] Mock<IFileSystem> fileSystem,
LoadLineProcessor processor)
{
// Arrange
var context = new FileParserContext();
const string RelativePath = "..\\script.csx";
const string Line = @"#load " + RelativePath;
const string FullPath = "C:\\script.csx";
fileSystem.Setup(x => x.GetFullPath(RelativePath)).Returns(FullPath);
// Act / Assert
Assert.Throws(typeof(InvalidDirectiveUseException), () => processor.ProcessLine(parser.Object, context, Line, false));
}
[Theory, ScriptCsAutoData]
public void ShouldParseLoadedFile(
[Frozen] Mock<IFileParser> parser,
[Frozen] Mock<IFileSystem> fileSystem,
LoadLineProcessor processor)
{
// Arrange
var context = new FileParserContext();
const string RelativePath = "..\\script.csx";
const string Line = @"#load " + RelativePath;
const string FullPath = "C:\\script.csx";
fileSystem.Setup(x => x.GetFullPath(RelativePath)).Returns(FullPath);
// Act
processor.ProcessLine(parser.Object, context, Line, true);
// Assert
parser.Verify(x => x.ParseFile(FullPath, It.IsAny<FileParserContext>()));
}
[Theory, ScriptCsAutoData]
public void ShouldExpandEnvironmentVariables(
[Frozen] Mock<IFileSystem> fileSystem,
LoadLineProcessor processor,
IFileParser parser)
{
// Arrange
var context = new FileParserContext();
var line = string.Format("#load %{0}%", EnvVarKey);
// Act
processor.ProcessLine(parser, context, line, true);
// Assert
fileSystem.Verify(x => x.GetFullPath(EnvVarValue));
}
public void Dispose()
{
Environment.SetEnvironmentVariable(EnvVarKey, null);
}
}
}
}