-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfigurableScriptOptionsFactoryTests.cs
94 lines (78 loc) · 3.19 KB
/
ConfigurableScriptOptionsFactoryTests.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
namespace CSharpInteractive.Tests;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.Scripting;
public class ConfigurableScriptOptionsFactoryTests
{
private readonly Mock<ISettingGetter<LanguageVersion>> _languageVersion = new();
private readonly Mock<ISettingGetter<OptimizationLevel>> _optimizationLevel = new();
private readonly Mock<ISettingGetter<WarningLevel>> _warningLevel = new();
private readonly Mock<ISettingGetter<CheckOverflow>> _checkOverflow = new();
private readonly Mock<ISettingGetter<AllowUnsafe>> _allowUnsafe = new();
public ConfigurableScriptOptionsFactoryTests()
{
_languageVersion.Setup(i => i.GetSetting()).Returns(LanguageVersion.Default);
_optimizationLevel.Setup(i => i.GetSetting()).Returns(OptimizationLevel.Debug);
_warningLevel.Setup(i => i.GetSetting()).Returns(WarningLevel.L0);
_checkOverflow.Setup(i => i.GetSetting()).Returns(CheckOverflow.On);
_allowUnsafe.Setup(i => i.GetSetting()).Returns(AllowUnsafe.Off);
}
[Theory]
[InlineData(OptimizationLevel.Debug)]
[InlineData(OptimizationLevel.Release)]
public void ShouldConfigureOptimizationLevel(OptimizationLevel value)
{
// Given
var factory = CreateInstance();
_optimizationLevel.Setup(i => i.GetSetting()).Returns(value);
// When
var options = factory.Create(ScriptOptions.Default);
// Then
options.OptimizationLevel.ShouldBe(value);
}
[Theory]
[InlineData(WarningLevel.L0, 0)]
[InlineData(WarningLevel.L1, 1)]
[InlineData(WarningLevel.L2, 2)]
[InlineData(WarningLevel.L3, 3)]
[InlineData(WarningLevel.L4, 4)]
[InlineData(WarningLevel.L5, 5)]
internal void ShouldConfigureWarningLevel(WarningLevel value, int expectedValue)
{
// Given
var factory = CreateInstance();
_warningLevel.Setup(i => i.GetSetting()).Returns(value);
// When
var options = factory.Create(ScriptOptions.Default);
// Then
options.WarningLevel.ShouldBe(expectedValue);
}
[Theory]
[InlineData(CheckOverflow.Off, false)]
[InlineData(CheckOverflow.On, true)]
internal void ShouldConfigureCheckOverflow(CheckOverflow value, bool expectedValue)
{
// Given
var factory = CreateInstance();
_checkOverflow.Setup(i => i.GetSetting()).Returns(value);
// When
var options = factory.Create(ScriptOptions.Default);
// Then
options.CheckOverflow.ShouldBe(expectedValue);
}
[Theory]
[InlineData(AllowUnsafe.Off, false)]
[InlineData(AllowUnsafe.On, true)]
internal void ShouldConfigureAllowUnsafe(AllowUnsafe value, bool expectedValue)
{
// Given
var factory = CreateInstance();
_allowUnsafe.Setup(i => i.GetSetting()).Returns(value);
// When
var options = factory.Create(ScriptOptions.Default);
// Then
options.AllowUnsafe.ShouldBe(expectedValue);
}
private ConfigurableScriptOptionsFactory CreateInstance() =>
new(_languageVersion.Object, _optimizationLevel.Object, _warningLevel.Object, _checkOverflow.Object, _allowUnsafe.Object);
}