コード例 #1
0
        public void ShouldHandleIssue235()
        {
            string code =
                @"using AgileObjects.AgileMapper;
    public class TestClass
    {
        public TestClass()
        {
            IMapper mapper = Mapper.CreateNew();
        }
    }";

            string script =
                @"#r ""nuget: AgileObjects.AgileMapper, 0.23.1""
    #r ""TestLibrary.dll""
    
    using AgileObjects.AgileMapper;

    IMapper mapper = Mapper.CreateNew();
    var testClass = new TestClass();
    Console.WriteLine(""Hello World!"");";


            using (var disposableFolder = new DisposableFolder())
            {
                var projectFolder = Path.Combine(disposableFolder.Path, "TestLibrary");
                ProcessHelper.RunAndCaptureOutput("dotnet", new[] { "new classlib -n TestLibrary" }, disposableFolder.Path);
                ProcessHelper.RunAndCaptureOutput("dotnet", new[] { "add TestLibrary.csproj package AgileObjects.AgileMapper -v 0.23.0" }, projectFolder);
                File.WriteAllText(Path.Combine(projectFolder, "Class1.cs"), code);
                File.WriteAllText(Path.Combine(projectFolder, "script.csx"), script);
                ProcessHelper.RunAndCaptureOutput("dotnet", new[] { "build -c release -o ./" }, projectFolder);

                var dotnetScriptArguments = GetDotnetScriptArguments(Path.Combine(projectFolder, "script.csx"));
                var result = ProcessHelper.RunAndCaptureOutput("dotnet", dotnetScriptArguments);
                Assert.Contains("Hello World!", result.output);
            }
        }
コード例 #2
0
        public void ShouldRegisterToRunCsxScriptDirectly()
        {
            using (var scriptFolder = new DisposableFolder())
            {
                var(output, exitCode) = ScriptTestRunner.Default.Execute("init", scriptFolder.Path);
                Assert.True(exitCode == 0, output);

                var scriptPath = Path.Combine(scriptFolder.Path, "main.csx");
                if (ScriptEnvironment.Default.IsWindows)
                {
                    (output, exitCode) = ProcessHelper.RunAndCaptureOutput("reg.exe", @"query HKCU\Software\Classes\.csx");
                    Assert.Equal(0, exitCode);

                    (output, exitCode) = ProcessHelper.RunAndCaptureOutput("reg.exe", @"query HKCU\software\classes\dotnetscript\Shell\Open\Command");
                    Assert.Equal(0, exitCode);

                    Assert.Matches(new Regex(@" \b   REG_EXPAND_SZ                             # type
                                                [ ]+ ""%ProgramFiles%\\dotnet\\dotnet.exe""    # unexpanded %ProgramFiles% + quoted
                                                [ ]+ exec
                                                [ ]+ ""([A-Z]:|\\)\\(.+?)\\dotnet-script.dll"" # absolute + quoted
                                                [ ]+ ""%1""                                    # quoted
                                                [ ]+ --
                                                [ ]+ %\*                                       # unquoted
                                            ",
                                             RegexOptions.IgnoreCase |
                                             RegexOptions.CultureInvariant |
                                             RegexOptions.IgnorePatternWhitespace),
                                   output);
                }
                else
                {
                    var text = File.ReadAllText(scriptPath);
                    Assert.True(text.StartsWith("#!/usr/bin/env dotnet-script"), "should have shebang");
                    Assert.True(text.IndexOf("\r\n") < 0, "should have not have windows cr/lf");
                }
            }
        }
コード例 #3
0
        private (string output, int exitCode) ExecuteCodeInReleaseMode(string code)
        {
            var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments($"-c", new[] { "release", "eval", $"\"{code}\"" }));

            return(result);
        }
コード例 #4
0
        private (string output, int exitCode) Execute(string fixture, params string[] arguments)
        {
            var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments(Path.Combine("..", "..", "..", "TestFixtures", fixture), arguments));

            return(result);
        }
コード例 #5
0
        private static (string output, int exitCode) Execute(string args, string workingDirectory)
        {
            var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments(args), workingDirectory);

            return(result);
        }
コード例 #6
0
        public (string output, int exitCode) Execute(params string[] arguments)
        {
            var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments(arguments));

            return(result);
        }
コード例 #7
0
        public (string output, int exitCode) ExecuteCodeInReleaseMode(string code)
        {
            var result = ProcessHelper.RunAndCaptureOutput("dotnet", GetDotnetScriptArguments($"-c release eval \"{code}\""));

            return(result);
        }