Example #1
0
        public void GivenHelloWorldScript_WhenConsoleTypeAndAssembliesAreAllowed_ThenTheVerificationShouldBeOk()
        {
            // Arrange
            var script = @"
namespace HelloWorld
{
    class Hello {         
        static void Main(string[] args)
        {
            System.Console.WriteLine(""Hello World!"");
        }
    }
}
";

            // Act
            var compilerSetup = new DefaultCompilerSetup();

            compilerSetup.AddAllowedTypes(new List <Type> {
                typeof(Console)
            }, true);

            var    verifier = new Verifier(compilerSetup);
            Action call     = () => verifier.Verify(script);

            // Assert
            call.Should().NotThrow();
        }
Example #2
0
        public void GivenHelloWorldScript_WhenOnlyConsoleTypeIsAllowed_ThenTheVerificationShouldFail()
        {
            // Arrange
            var script = @"
namespace HelloWorld
{
    class Hello {         
        static void Main(string[] args)
        {
            System.Console.WriteLine(""Hello World!"");
        }
    }
}
";

            // Act
            var compilerSetup = new DefaultCompilerSetup();

            compilerSetup.AddAllowedTypes(new List <Type> {
                typeof(Console)
            }, false);

            var    verifier = new Verifier(compilerSetup);
            Action call     = () => verifier.Verify(script);

            // Assert
            call.Should().Throw <ScriptVerificationException>().WithMessage(
                "(7,13): error CS0234: Der Typ- oder Namespacename \"Console\" ist im Namespace \"System\" nicht vorhanden. (Möglicherweise fehlt ein Assemblyverweis.)");
        }