Ejemplo n.º 1
0
        static public void RunAsService(ParsedCommandLine commandArgs)
        {
#if NET462
            CreateWebHost(commandArgs.EndpointCollectionDirectory, AppDomain.CurrentDomain.BaseDirectory, commandArgs.Url).RunAsService();
#else
            Error.WriteLine("ERROR: Service mode not supported for .NET Core");
#endif
        }
Ejemplo n.º 2
0
 static public void RunAsService(ParsedCommandLine commandArgs)
 {
     CreateWebHost(commandArgs.EndpointCollectionDirectory, AppDomain.CurrentDomain.BaseDirectory, commandArgs.Url).RunAsService();
 }
Ejemplo n.º 3
0
        public static void Test(ParsedCommandLine commandArgs, EndpointCollection endpointCollection)
        {
            if (!TestRunner.HasTestSuite(endpointCollection.SourceDirectory))
            {
                Error.WriteLine("ERROR: No test suite found");
                return;
            }

            if (commandArgs.Diff && commandArgs.Only == null)
            {
                Error.WriteLine("ERROR: --diff can only be specified with --only");
                return;
            }

            var testRunner = new ConsoleTestRunner(endpointCollection);

            if (commandArgs.Url != null)
            {
                testRunner.Url = commandArgs.Url;
            }

            if (commandArgs.Only != null)
            {
                var indexes = ParseOnlyArgument(commandArgs.Only, (from testCase in testRunner.Tests select testCase.Name).ToArray());
                if (indexes.Length == 0)
                {
                    Error.WriteLine("ERROR: No testcases matches --only");
                }

                foreach (var index in indexes)
                {
                    if (commandArgs.Diff)
                    {
                        var diffTool = Environment.GetEnvironmentVariable("DIFFTOOL");
                        if (diffTool == null)
                        {
                            Error.WriteLine("ERROR: No diff tool configured. Set DIFFTOOL environment variable to point to executable.");
                            return;
                        }

                        var testCase = testRunner.Tests.ElementAt(index);
                        if (testCase.ExpectedResponseBody == null)
                        {
                            Error.WriteLine($"ERROR: Test case has no expected response body");
                            return;
                        }

                        var responseTuple = testCase.GetResponse(endpointCollection, testRunner.Now);
                        if (responseTuple.Item2 != null)
                        {
                            Error.WriteLine($"ERROR: {responseTuple.Item2}");
                            return;
                        }

                        var expectedFilename = Path.GetTempFileName();
                        var actualFilename   = Path.GetTempFileName();

                        File.WriteAllText(expectedFilename, testCase.ExpectedResponseBody);
                        File.WriteAllText(actualFilename, responseTuple.Item1);

                        StartExternalDiffTool(diffTool, expectedFilename, actualFilename);
                    }
                    else
                    {
                        if (commandArgs.ShowResponse)
                        {
                            testRunner.ShowResponse(index);
                        }
                        else
                        {
                            testRunner.ExecuteTestAndOutputResult(index);
                        }
                    }
                }
            }
            else
            {
                testRunner.TestAll(commandArgs.Stop, true);
            }
        }