Пример #1
0
        public void It_provides_errors_for_missing_type()
        {
            using (var consoleState = new PreserveConsoleState())
            {
                var referencedCompilation = Compile(@"
public class C
{ 
}");

                var text  = @"
class D
{
    public static void Main()
    {
        C c= new C();
    }
}";
                var other = Compile(text, referencedCompilation.ToMetadataReference());


                using (var stream = new MemoryStream())
                {
                    other.Emit(peStream: stream);
                    var encodedAssembly = System.Convert.ToBase64String(stream.ToArray());

                    var runRequest = new WasmCodeRunnerRequest()
                    {
                        Succeeded      = true,
                        Base64Assembly = encodedAssembly
                    };

                    var response = CodeRunner.ExecuteRunRequest(runRequest, 1);

                    response.Data.RunnerException.Should().Match("*Missing type `C`*");
                    consoleState.OutputIsRedirected.Should().BeFalse();
                }
            }
        }
Пример #2
0
        public void It_returns_an_error_if_there_is_no_entry_point()
        {
            using (var consoleState = new PreserveConsoleState())
            {
                var compilation = Compile("class C {}");

                using (var stream = new MemoryStream())
                {
                    compilation.Emit(peStream: stream);
                    var encodedAssembly = Convert.ToBase64String(stream.ToArray());

                    var runRequest = new WasmCodeRunnerRequest()
                    {
                        Succeeded      = true,
                        Base64Assembly = encodedAssembly
                    };

                    var output = CodeRunner.ExecuteRunRequest(runRequest, 1).Data.Output;
                    output.Single().Should().Be("error CS5001: Program does not contain a static 'Main' method suitable for an entry point");
                    consoleState.OutputIsRedirected.Should().BeFalse();
                }
            }
        }