Ejemplo n.º 1
0
    public void When_InvalidCodeSupplied_Then_CompilationFails()
    {
        string code = @"usi ng System;";

        CSharpCompilers.Compilation compilation = compiler.Compile(code);
        Assert.NotEmpty(compilation.GetErrors());
    }
Ejemplo n.º 2
0
    public void When_NamespaceNull_Then_RunFails()
    {
        CSharpCompilers.Compilation compilation = compiler.Compile(TestUtils.CODE);
        var e = Assert.Throws <RunError>(() => compilation.Run(new Compilation.RunOptions()));

        Assert.Equal(e.Message, "The namespace must not be blank");
    }
Ejemplo n.º 3
0
    public void When_VoidMethod_And_NoArgs_Then_RunSucceeds()
    {
        CSharpCompilers.Compilation compilation = compiler.Compile(TestUtils.CODE);
        var runOpts = TestUtils.builRunOpts().WithMethod(TestUtils.VOID_METHOD_NO_ARGS);
        var result  = compilation.Run(runOpts);

        Assert.Null(result);
    }
Ejemplo n.º 4
0
    public void When_NonVoidMethod_And_NoArgs_Then_RunSucceeds()
    {
        CSharpCompilers.Compilation compilation = compiler.Compile(TestUtils.CODE);
        var runOpts = TestUtils.builRunOpts().WithMethod(TestUtils.NON_VOID_METHOD_NO_ARGS);
        var result  = compilation.Run(runOpts);

        Assert.Equal(result, TestUtils.METHOD_RETURN_VALUE);
    }
Ejemplo n.º 5
0
    public void When_FieldWithSameNameExists_ButNotMethod_Then_RunFails()
    {
        CSharpCompilers.Compilation compilation = compiler.Compile(TestUtils.CODE);
        var runOpts = TestUtils.builRunOpts().WithMethod(TestUtils.FIELD);
        var e       = Assert.Throws <RunError>(() => compilation.Run(runOpts));

        Assert.Equal(e.Message,
                     $"Could not find method '{TestUtils.FIELD}' in class '{runOpts.GetClass()}' and namespace '{runOpts.GetNamespace()}'");
    }
Ejemplo n.º 6
0
    public void When_MethodDoesNotExist_Then_RunFails()
    {
        CSharpCompilers.Compilation compilation = compiler.Compile(TestUtils.CODE);
        var runOpts = TestUtils.builRunOpts().WithMethod("NonExistentMethod");
        var e       = Assert.Throws <RunError>(() => compilation.Run(runOpts));

        Assert.Equal(e.Message,
                     $"Could not find method 'NonExistentMethod' in class '{runOpts.GetClass()}' and namespace '{runOpts.GetNamespace()}'");
    }
Ejemplo n.º 7
0
    public void When_ClassEmpty_Then_RunFails()
    {
        CSharpCompilers.Compilation compilation = compiler.Compile(TestUtils.CODE);
        var e = Assert.Throws <RunError>(() => compilation.Run(
                                             new Compilation.RunOptions()
                                             .WithNamespace(TestUtils.NAMESPACE)
                                             .WithClass(string.Empty)));

        Assert.Equal(e.Message, "The class must not be blank");
    }
Ejemplo n.º 8
0
    public void When_CompilationErrors_And_RunCalled_Then_ExceptionThrown()
    {
        string code = @"usi ng System;";

        CSharpCompilers.Compilation compilation = compiler.Compile(code);
        var e = Assert.Throws <CompilationError>(() => compilation.Run(
                                                     new Compilation.RunOptions().WithNamespace("A").WithClass("B").WithMethod("C")));

        Assert.Equal(e.Message, String.Concat(compilation.GetErrors()));
    }
Ejemplo n.º 9
0
    public void When_MethodNull_Then_RunFails()
    {
        CSharpCompilers.Compilation compilation = compiler.Compile(TestUtils.CODE);
        var e = Assert.Throws <RunError>(() => compilation.Run(
                                             new Compilation.RunOptions()
                                             .WithNamespace(TestUtils.NAMESPACE)
                                             .WithClass(TestUtils.CLASS)));

        Assert.Equal(e.Message, "The method must not be blank");
    }
Ejemplo n.º 10
0
    public void When_InvalidCodeSupplied_Then_CompilationErrorsAreAccurate()
    {
        string code = @"usi ng System;";

        CSharpCompilers.Compilation compilation = compiler.Compile(code);
        Assert.Equal(4, compilation.GetErrors().ToArray().Length);
        Assert.True(compilation.GetErrors().Exists(e => e.Id == "CS1002"));
        Assert.True(compilation.GetErrors().Exists(e => e.Id == "CS0116"));
        Assert.True(compilation.GetErrors().Exists(e => e.Id == "CS1022"));
        Assert.True(compilation.GetErrors().Exists(e => e.Id == "CS0246"));
    }
Ejemplo n.º 11
0
    public void When_MethodHasArgs_Then_RunSucceeds()
    {
        CSharpCompilers.Compilation compilation = compiler.Compile(TestUtils.CODE);

        string firstArg  = "abcd";
        string secondArg = "-1234";

        var runOpts = TestUtils.builRunOpts()
                      .WithMethod(TestUtils.METHOD_WITH_ARGS)
                      .WithArgs(new string[] { firstArg, secondArg });
        var result = compilation.Run(runOpts);

        Assert.Equal(result, firstArg + secondArg);
    }
Ejemplo n.º 12
0
    public void TestCompile()
    {
        string   code     = File.ReadAllText(@"C:\Users\Ovidiu\Desktop\EventsToSpadNext\src\demo-scripts.cs");
        Compiler compiler = new SPADNextCompiler(@"E:\SPAD.neXt\SPAD.Interfaces.dll");

        CSharpCompilers.Compilation compilation = compiler.Compile(code);
        IEnumerable <Diagnostic>    errors      = compilation.GetErrors();

        if (errors.Count() > 0)
        {
            foreach (Diagnostic diagnostic in errors)
            {
                LOG.WriteLine($"\t{diagnostic.Id}: {diagnostic.GetMessage()}");
            }
            Assert.True(false, "Code compilation failed. See the test output logs for details.");
        }
    }
Ejemplo n.º 13
0
 public void When_ValidCodeSupplied_Then_CompilationSucceeds()
 {
     CSharpCompilers.Compilation compilation = compiler.Compile(TestUtils.CODE);
     Assert.Empty(compilation.GetErrors());
 }
Ejemplo n.º 14
0
 public void When_EmptyCodeSupplied_Then_CompilationSucceeds()
 {
     CSharpCompilers.Compilation compilation = compiler.Compile(string.Empty);
     Assert.Empty(compilation.GetErrors());
 }