Skip to content

Commit d6fcf15

Browse files
author
Bernt Røskar Brenna
committed
Newtonsoft default script assembly reference
1 parent e117280 commit d6fcf15

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

UnitTests/TestDynamicResponse.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,30 @@ public async Task UsingSystemIO()
112112
[Fact]
113113
public async Task UsingSystemXmlLinq()
114114
{
115-
Assert.Equal("OK", await EvalAsync("using System.Xml.Linq; return \"OK\";"));
115+
await AssertScriptCanIncludeUsingStatementAsync("System.Xml.Linq");
116116
}
117117

118118
[Fact]
119119
public async Task UsingRegex()
120120
{
121-
Assert.Equal("OK", await EvalAsync("using System.Text.RegularExpressions; return \"OK\";"));
121+
await AssertScriptCanIncludeUsingStatementAsync("System.Text.RegularExpressions");
122122
}
123123

124124
[Fact]
125125
public async Task UsingSystemDiagnosticsDebug()
126126
{
127-
Assert.Equal("OK", await EvalAsync("using System.Diagnostics; Debug.Assert(true); return \"OK\";"));
127+
await AssertScriptCanIncludeUsingStatementAsync("System.Diagnostics");
128+
}
129+
130+
[Fact]
131+
public async Task UsingNewtonsoftJson()
132+
{
133+
await AssertScriptCanIncludeUsingStatementAsync("Newtonsoft.Json");
134+
}
135+
136+
private async Task AssertScriptCanIncludeUsingStatementAsync(string namespaceName)
137+
{
138+
Assert.Equal("OK", await EvalAsync($"using {namespaceName}; return \"OK\";"));
128139
}
129140

130141
[Fact]

netmockery/DynamicResponseCreator.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public override async Task<string> GetBodyAsync(RequestInfo requestInfo)
4141
MetadataReference.CreateFromFile(typeof(Enumerable).GetTypeInfo().Assembly.Location), // System.Linq
4242
MetadataReference.CreateFromFile(typeof(System.Xml.Linq.XElement).GetTypeInfo().Assembly.Location), // System.Xml.Linq
4343
MetadataReference.CreateFromFile(typeof(System.IO.File).GetTypeInfo().Assembly.Location),
44-
MetadataReference.CreateFromFile(typeof(System.Diagnostics.Debug).GetTypeInfo().Assembly.Location)
44+
MetadataReference.CreateFromFile(typeof(System.Diagnostics.Debug).GetTypeInfo().Assembly.Location),
45+
MetadataReference.CreateFromFile(typeof(Newtonsoft.Json.JsonConvert).GetTypeInfo().Assembly.Location)
4546
);
4647

4748
var script = CSharpScript.Create<string>(
@@ -89,7 +90,8 @@ public override async Task<string> GetBodyAsync(RequestInfo requestInfo)
8990
MetadataReference.CreateFromFile(typeof(System.Xml.Linq.XElement).GetTypeInfo().Assembly.Location), // System.Xml.Linq
9091
MetadataReference.CreateFromFile(typeof(System.IO.File).GetTypeInfo().Assembly.Location),
9192
MetadataReference.CreateFromFile(typeof(System.Diagnostics.Debug).GetTypeInfo().Assembly.Location),
92-
MetadataReference.CreateFromFile(typeof(System.Text.RegularExpressions.Regex).GetTypeInfo().Assembly.Location)
93+
MetadataReference.CreateFromFile(typeof(System.Text.RegularExpressions.Regex).GetTypeInfo().Assembly.Location),
94+
MetadataReference.CreateFromFile(typeof(Newtonsoft.Json.JsonConvert).GetTypeInfo().Assembly.Location)
9395
);
9496

9597
var script = CSharpScript.Create<string>(

0 commit comments

Comments
 (0)