Repository navigation
Expand file tree
/
Copy pathScriptOptionsTests.cs
More file actions
151 lines (121 loc) · 8.28 KB
/
Copy pathScriptOptionsTests.cs
File metadata and controls
151 lines (121 loc) · 8.28 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Reflection;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.Scripting.Test
{
public class ScriptOptionsTests : TestBase
{
[Fact]
public void AddReferences()
{
var options = ScriptOptions.Default.
AddReferences(typeof(int).GetTypeInfo().Assembly).
AddReferences(typeof(int).GetTypeInfo().Assembly).
AddReferences(MetadataReference.CreateFromAssemblyInternal(typeof(int).GetTypeInfo().Assembly)).
AddReferences("System.Linq").
AddReferences("System.Linq");
Assert.Equal(5, options.MetadataReferences.Length);
}
[Fact]
public void AddReferences_Errors()
{
var moduleRef = ModuleMetadata.CreateFromImage(TestResources.MetadataTests.NetModule01.ModuleCS00).GetReference();
var options = ScriptOptions.Default;
Assert.Throws<ArgumentNullException>("references", () => options.AddReferences((MetadataReference[])null));
Assert.Throws<ArgumentNullException>("references[0]", () => options.AddReferences(new MetadataReference[] { null }));
Assert.Throws<ArgumentNullException>("references", () => options.AddReferences((IEnumerable<MetadataReference>)null));
Assert.Throws<ArgumentNullException>("references[0]", () => options.AddReferences((IEnumerable<MetadataReference>)new MetadataReference[] { null }));
Assert.Throws<ArgumentNullException>("references", () => options.AddReferences((Assembly[])null));
Assert.Throws<ArgumentNullException>("references[0]", () => options.AddReferences(new Assembly[] { null }));
Assert.Throws<ArgumentNullException>("references", () => options.AddReferences((IEnumerable<Assembly>)null));
Assert.Throws<ArgumentNullException>("references[0]", () => options.AddReferences((IEnumerable<Assembly>)new Assembly[] { null }));
Assert.Throws<ArgumentNullException>("references", () => options.AddReferences((string[])null));
Assert.Throws<ArgumentNullException>("references[0]", () => options.AddReferences(new string[] { null }));
Assert.Throws<ArgumentNullException>("references", () => options.AddReferences((IEnumerable<string>)null));
Assert.Throws<ArgumentNullException>("references[0]", () => options.AddReferences((IEnumerable<string>)new string[] { null }));
}
[Fact]
public void WithReferences()
{
var options = ScriptOptions.Default.WithReferences("System.Linq", "system.linq");
Assert.Equal(2, options.MetadataReferences.Length);
options = ScriptOptions.Default.WithReferences(typeof(int).GetTypeInfo().Assembly, typeof(int).GetTypeInfo().Assembly);
Assert.Equal(2, options.MetadataReferences.Length);
var assemblyRef = ModuleMetadata.CreateFromImage(TestResources.SymbolsTests.Methods.CSMethods).GetReference();
options = ScriptOptions.Default.WithReferences(assemblyRef, assemblyRef);
Assert.Equal(2, options.MetadataReferences.Length);
}
[Fact]
public void WithReferences_Errors()
{
var moduleRef = ModuleMetadata.CreateFromImage(TestResources.MetadataTests.NetModule01.ModuleCS00).GetReference();
var options = ScriptOptions.Default;
Assert.Throws<ArgumentNullException>("references", () => options.WithReferences((MetadataReference[])null));
Assert.Throws<ArgumentNullException>("references", () => options.WithReferences((IEnumerable<MetadataReference>)null));
Assert.Throws<ArgumentNullException>("references", () => options.WithReferences(default(ImmutableArray<MetadataReference>)));
Assert.Throws<ArgumentNullException>("references[0]", () => options.WithReferences(new MetadataReference[] { null }));
Assert.Throws<ArgumentNullException>("references[0]", () => options.WithReferences(ImmutableArray.Create((MetadataReference)null)));
Assert.Throws<ArgumentNullException>("references", () => options.WithReferences((Assembly[])null));
Assert.Throws<ArgumentNullException>("references", () => options.WithReferences((IEnumerable<Assembly>)null));
Assert.Throws<ArgumentNullException>("references", () => options.WithReferences(default(ImmutableArray<Assembly>)));
Assert.Throws<ArgumentNullException>("references[0]", () => options.WithReferences(new Assembly[] { null }));
Assert.Throws<ArgumentNullException>("references[0]", () => options.WithReferences(ImmutableArray.Create((Assembly)null)));
Assert.Throws<ArgumentNullException>("references", () => options.WithReferences((string[])null));
Assert.Throws<ArgumentNullException>("references", () => options.WithReferences((IEnumerable<string>)null));
Assert.Throws<ArgumentNullException>("references", () => options.WithReferences(default(ImmutableArray<string>)));
Assert.Throws<ArgumentNullException>("references[0]", () => options.WithReferences(new string[] { null }));
Assert.Throws<ArgumentNullException>("references[0]", () => options.WithReferences(ImmutableArray.Create((string)null)));
}
[Fact]
public void AddNamespaces()
{
// we only check if the specified name is a valid CLR namespace name, it might not be a valid C#/VB namespace name:
var options = ScriptOptions.Default.
AddImports("").
AddImports("blah.").
AddImports("b\0lah").
AddImports(".blah").
AddImports("b\0lah").
AddImports(".blah");
AssertEx.Equal(new[] { "", "blah.", "b\0lah", ".blah", "b\0lah", ".blah" }, options.Imports);
}
[Fact]
public void AddImports_Errors()
{
var options = ScriptOptions.Default;
Assert.Throws<ArgumentNullException>("imports", () => options.AddImports((string[])null));
Assert.Throws<ArgumentNullException>("imports[0]", () => options.AddImports(new string[] { null }));
Assert.Throws<ArgumentNullException>("imports", () => options.AddImports((IEnumerable<string>)null));
Assert.Throws<ArgumentNullException>("imports[0]", () => options.AddImports((IEnumerable<string>)new string[] { null }));
Assert.Throws<ArgumentNullException>("imports", () => options.AddImports(default(ImmutableArray<string>)));
Assert.Throws<ArgumentNullException>("imports[0]", () => options.AddImports(ImmutableArray.Create((string)null)));
// we only check if the specified name is a valid CLR namespace name, it might not be a valid C#/VB namespace name:
options.AddImports("");
options.AddImports("blah.");
options.AddImports("b\0lah");
options.AddImports(".blah");
}
[Fact]
public void WithImports_Errors()
{
var options = ScriptOptions.Default;
Assert.Throws<ArgumentNullException>("imports", () => options.WithImports((string[])null));
Assert.Throws<ArgumentNullException>("imports[0]", () => options.WithImports(new string[] { null }));
Assert.Throws<ArgumentNullException>("imports", () => options.WithImports((IEnumerable<string>)null));
Assert.Throws<ArgumentNullException>("imports[0]", () => options.WithImports((IEnumerable<string>)new string[] { null }));
Assert.Throws<ArgumentNullException>("imports", () => options.WithImports(default(ImmutableArray<string>)));
Assert.Throws<ArgumentNullException>("imports[0]", () => options.WithImports(ImmutableArray.Create((string)null)));
// we only check if the specified name is a valid CLR namespace name, it might not be a valid C#/VB namespace name:
options.WithImports("");
options.WithImports("blah.");
options.WithImports("b\0lah");
options.WithImports(".blah");
}
}
}