예제 #1
0
 public static void Main(string[] args)
 {
     var config = new Nancy.Hosting.Self.HostConfiguration();
     config.UnhandledExceptionCallback += (ex) => {
         Console.WriteLine(ex);
     };
     var nancyHost = new Nancy.Hosting.Self.NancyHost(config, new Uri("http://localhost:7000"));
     nancyHost.Start();
     Console.ReadLine();
     nancyHost.Stop();
     System.Threading.Thread.Sleep(1000);
 }
예제 #2
0
        public void RunWebService()
        {
            int port = 50006;

            int.TryParse(BauerLib.Registry.ServicePort, out port);

            if (PortInUse(port))
            {
                log.ErrorFormat("Error {0} in use !", port);
                return;
            }

            string baseAddress = string.Format("http://localhost:{0}", port);

            Nancy.ViewEngines.DotLiquid.DotLiquidRegistrations r = new Nancy.ViewEngines.DotLiquid.DotLiquidRegistrations();
            DotLiquid.Template.NamingConvention = new DotLiquid.NamingConventions.CSharpNamingConvention();

            Nancy.Hosting.Self.HostConfiguration hostConfigs = new Nancy.Hosting.Self.HostConfiguration();
            // netsh http add urlacl url=http://+:50006/ user=EVERYONE
            // netsh http add urlacl url=http://+:50006/ user=JEDER
            hostConfigs.UrlReservations.CreateAutomatically = false;
            hostConfigs.RewriteLocalhost = true;

            int retries = 6;

            while (retries > 0)
            {
                try
                {
                    host = new Nancy.Hosting.Self.NancyHost(hostConfigs, new Uri(baseAddress));
                    host.Start();
                    retries = -1;
                }
                catch (Exception ex)
                {
                    log.Error("Error starting rest-service", ex);
                    retries--;
                    if (retries <= 3)
                    {
                        hostConfigs.UrlReservations.CreateAutomatically = true;
                    }
                    System.Threading.Thread.Sleep(500);
                }
            }
            log.InfoFormat("Running on {0}", baseAddress);

            if (Environment.UserInteractive)
            {
                System.Diagnostics.Process.Start(baseAddress);
            }
        }
예제 #3
0
        public void RunTests(IEnumerable <TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            var configuration = new Mocha.BddConfiguration(); //TODO: unhardcode
            var harnessFile   = "harness.html";

            var sources = tests
                          .Select(t => t.Source)
                          .Distinct();

            //TODO: allow multiple roots / multiple configs / multiple projects
            var rootPath = PathFinder.FindRootDirectoryForFile(sources.First());

            HarnessBuilder.CreateHarnessFile(configuration, sources, rootPath, harnessFile);

            var hostConfig = new Nancy.Hosting.Self.HostConfiguration()
            {
                RewriteLocalhost = true,
                UrlReservations  = new Nancy.Hosting.Self.UrlReservations()
                {
                    CreateAutomatically = true
                }
            };
            var port = "8081"; //TODO: unhardcode
            var uri  = String.Format("http://localhost:{0}", port);

            var host = new Nancy.Hosting.Self.NancyHost(
                new Uri(uri),
                new NancySettingsBootstrapper(rootPath),
                hostConfig
                );

            host.Start();

            //Run phantom per harness
            var harnessUri    = uri + "/" + harnessFile;
            var phantomrunner = new PhantomRunner(frameworkHandle, tests);
            var phantomResult = phantomrunner.Run(harnessUri);

            phantomResult.Wait();

            host.Stop();
        }