forked from scriptcs/scriptcs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSharpScriptInMemoryEngineTests.cs
More file actions
74 lines (63 loc) · 2.81 KB
/
CSharpScriptInMemoryEngineTests.cs
File metadata and controls
74 lines (63 loc) · 2.81 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
using System;
using System.Collections.Generic;
using System.Linq;
using Moq;
using ScriptCs.Contracts;
using ScriptCs.Engine.Roslyn;
using ScriptCs.Exceptions;
using Should;
using Xunit;
namespace ScriptCs.Tests
{
public class CSharpScriptInMemoryEngineTests
{
public class TheExecuteMethod
{
private IConsole _console = new Mock<IConsole>().Object;
private IObjectSerializer _serializer = new Mock<IObjectSerializer>().Object;
private Printers _printers;
public TheExecuteMethod()
{
_printers = new Printers(_serializer);
}
[Fact]
public void ShouldExposeExceptionThrownByScriptWhenErrorOccurs()
{
var scriptEngine = new CSharpScriptInMemoryEngine(new ScriptHostFactory(_console, _printers, new ScriptInfo()), new TestLogProvider());
// Arrange
var lines = new List<string>
{
"using System;",
@"throw new InvalidOperationException(""InvalidOperationExceptionMessage."");"
};
var code = string.Join(Environment.NewLine, lines);
var session = new ScriptPackSession(Enumerable.Empty<IScriptPack>(), new string[0]);
// Act
var result = scriptEngine.Execute(code, new string[0], new AssemblyReferences(), Enumerable.Empty<string>(),
session);
// Assert
var exception = Assert.Throws<InvalidOperationException>(() => result.ExecuteExceptionInfo.Throw());
exception.StackTrace.ShouldContain("Submission#0");
exception.Message.ShouldContain("InvalidOperationExceptionMessage");
}
[Fact]
public void ShouldExposeExceptionThrownByCompilation()
{
var scriptEngine = new CSharpScriptInMemoryEngine(new ScriptHostFactory(_console, _printers, new ScriptInfo()), new TestLogProvider());
// Arrange
var lines = new List<string>
{
"Sysasdasdasdtem;"
};
var code = string.Join(Environment.NewLine, lines);
var session = new ScriptPackSession(Enumerable.Empty<IScriptPack>(), new string[0]);
// Act
var result = scriptEngine.Execute(code, new string[0], new AssemblyReferences(), Enumerable.Empty<string>(),
session);
// Assert
var exception = Assert.Throws<ScriptCompilationException>(() => result.CompileExceptionInfo.Throw());
exception.Message.ShouldContain("error CS0103: The name 'Sysasdasdasdtem' does not exist in the current context");
}
}
}
}