<commit_before>using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using TestStack.Seleno.Configuration.Contracts;
using TestStack.Seleno.Configuration.WebServers;
using TestStack.Seleno.PageObjects;
using TestStack.Seleno.PageObjects.Actions;

namespace TestStack.Seleno.Configuration
{
    /// <summary>
    /// The entry point for Seleno.
    /// </summary>
    public static class SelenoHost
    {
        /// <summary>
        /// The currently running seleno application.
        /// </summary>
        public static ISelenoApplication Host { get; internal set; }
       
        /// <summary>
        /// Begin a Seleno test for a Visual Studio web project.
        /// </summary>
        /// <param name="webProjectFolder">The name of the web project to run</param>
        /// <param name="portNumber">The port number to run the project under</param>
        /// <param name="configure">Any configuration changes you would like to make</param>
        public static void Run(string webProjectFolder, 
                               int portNumber, 
                               Action<IAppConfigurator> configure = null)
        {
            var webApplication = new WebApplication(ProjectLocation.FromFolder(webProjectFolder), portNumber);
            Run(webApplication, configure);
        }

        /// <summary>
        /// Begin a Seleno test for a web application.
        /// </summary>
        /// <param name="app">The web application to test</param>
        /// <param name="configure">Any configuration changes you would like to make</param>
        public static void Run(WebApplication app, Action<IAppConfigurator> configure)
        {
            Run(c =>
                {
                    c.ProjectToTest(app);
                    if (configure != null)
                        configure(c);
                }
            );
        }

        /// <summary>
        /// Begin a Seleno test.
        /// </summary>
        /// <param name="configure">Any configuration changes you would like to make</param>
        public static void Run(Action<IAppConfigurator> configure)
        {
            Action<IAppConfigurator> action = x =>
            {
                if (configure != null)
                    configure(x);
            };

            Host = CreateApplication(action);
        }

        private static ISelenoApplication CreateApplication(Action<IAppConfigurator> configure)
        {
            if (configure == null)
                throw new ArgumentNullException("configure");

            var configurator = new AppConfigurator();
            configure(configurator);
            Host = configurator.CreateApplication();
            Host.Initialize();

            return Host;
        }

        /// <summary>
        /// Navigate to the given controller action and return an initialised page object of the specified type.
        /// </summary>
        /// <typeparam name="TController">The controller to navigate to</typeparam>
        /// <typeparam name="TPage">The type of page object to initialise and return</typeparam>
        /// <param name="action">The controller action to navigate to</param>
        /// <returns>The initialised page object</returns>
        public static TPage NavigateToInitialPage<TController, TPage>(Expression<Action<TController>> action)
            where TController : Controller
            where TPage : UiComponent, new()
        {
            var navigator = Host.Container.Resolve<IPageNavigator>();
            return navigator.To<TController, TPage>(action);
        }
    }
}<commit_msg>Added a URL based NavigateToInitialPage overload for non-controller based navigation.<commit_after>using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using TestStack.Seleno.Configuration.Contracts;
using TestStack.Seleno.Configuration.WebServers;
using TestStack.Seleno.PageObjects;
using TestStack.Seleno.PageObjects.Actions;

namespace TestStack.Seleno.Configuration
{
    /// <summary>
    /// The entry point for Seleno.
    /// </summary>
    public static class SelenoHost
    {
        /// <summary>
        /// The currently running seleno application.
        /// </summary>
        public static ISelenoApplication Host { get; internal set; }
       
        /// <summary>
        /// Begin a Seleno test for a Visual Studio web project.
        /// </summary>
        /// <param name="webProjectFolder">The name of the web project to run</param>
        /// <param name="portNumber">The port number to run the project under</param>
        /// <param name="configure">Any configuration changes you would like to make</param>
        public static void Run(string webProjectFolder, 
                               int portNumber, 
                               Action<IAppConfigurator> configure = null)
        {
            var webApplication = new WebApplication(ProjectLocation.FromFolder(webProjectFolder), portNumber);
            Run(webApplication, configure);
        }

        /// <summary>
        /// Begin a Seleno test for a web application.
        /// </summary>
        /// <param name="app">The web application to test</param>
        /// <param name="configure">Any configuration changes you would like to make</param>
        public static void Run(WebApplication app, Action<IAppConfigurator> configure)
        {
            Run(c =>
                {
                    c.ProjectToTest(app);
                    if (configure != null)
                        configure(c);
                }
            );
        }

        /// <summary>
        /// Begin a Seleno test.
        /// </summary>
        /// <param name="configure">Any configuration changes you would like to make</param>
        public static void Run(Action<IAppConfigurator> configure)
        {
            Action<IAppConfigurator> action = x =>
            {
                if (configure != null)
                    configure(x);
            };

            Host = CreateApplication(action);
        }

        private static ISelenoApplication CreateApplication(Action<IAppConfigurator> configure)
        {
            if (configure == null)
                throw new ArgumentNullException("configure");

            var configurator = new AppConfigurator();
            configure(configurator);
            Host = configurator.CreateApplication();
            Host.Initialize();

            return Host;
        }

        /// <summary>
        /// Navigate to the given controller action and return an initialised page object of the specified type.
        /// </summary>
        /// <typeparam name="TController">The controller to navigate to</typeparam>
        /// <typeparam name="TPage">The type of page object to initialise and return</typeparam>
        /// <param name="action">The controller action to navigate to</param>
        /// <returns>The initialised page object</returns>
        public static TPage NavigateToInitialPage<TController, TPage>(Expression<Action<TController>> action)
            where TController : Controller
            where TPage : UiComponent, new()
        {
            ThrowIfHostNotInitialised();
            return Host.Container.Resolve<IPageNavigator>().To<TController, TPage>(action);
        }

        /// <summary>
        /// Navigate to the given URL and return an initialised page object of the specified type.
        /// </summary>
        /// <typeparam name="TPage">The type of page object to initialise and return</typeparam>
        /// <param name="relativeUrl">The URL to navigate to (relative to the base URL of the site)</param>
        /// <returns>The initialised page object</returns>
        public static TPage NavigateToInitialPage<TPage>(string relativeUrl) where TPage : UiComponent, new()
        {
            ThrowIfHostNotInitialised();
            return Host.Container.Resolve<IPageNavigator>().To<TPage>(relativeUrl);
        }

        private static void ThrowIfHostNotInitialised()
        {
            if (Host == null)
                throw new InvalidOperationException("You must call SelenoHost.Run(...) before using SelenoHost to navigate to a page.");
        }
    }
}
{'fraction_non_alphanumeric': 0.10097680097680098, 'fraction_numerical': 0.0, 'mean_word_length': 1.9742193173565723, 'pattern_counts': {'":': 0, '<': 98, '<?xml version=': 0, '>': 102, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5993670', 'n_tokens_mistral': 1998, 'n_tokens_neox': 1945, 'n_words': 583}