コード例 #1
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");
    }
コード例 #2
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);
    }
コード例 #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);
    }
コード例 #4
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()}'");
    }
コード例 #5
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()}'");
    }
コード例 #6
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");
    }
コード例 #7
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()));
    }
コード例 #8
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");
    }
コード例 #9
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);
    }