public void DeployNavigateAndFindDomElementTest() { // Arrange const string webSiteName = "TestEasyWebSite"; var server = WebServer.Create(); var appInfo = server.CreateWebApplication(webSiteName); server.DeployWebApplication(appInfo.Name, new List <DeploymentItem> { new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName } }); using (var browserManager = new BrowserManager()) { var browser = browserManager.CreateBrowser(); // Act browser.Navigate().GoToUrl(appInfo.VirtualPath + "/default.html"); // Assert Assert.AreEqual("[This is my label]", browser.FindElement(By.Id("myLabel")).Text); } }
public void Init() { var url = "http://localhost:12345/"; // Create Webserver and attach LocalSession and Static // files module and CORS enabled server = WebServer.Create(url); server.RegisterModule(new FallbackModule((context, cancel) => { lastRequest = context.Request; if (lastRequest.Url.ToString().EndsWith("echo")) { lastRequest.InputStream.CopyTo(context.Response.OutputStream); } else { using (var reader = new StreamReader(lastRequest.InputStream)) { reader.ReadToEnd(); } var responseBytes = Encoding.UTF8.GetBytes(dummyResponse); context.Response.OutputStream.Write(responseBytes, 0, responseBytes.Length); } return(true); })); serverCancel = new CancellationTokenSource(); serverTask = server.RunAsync(serverCancel.Token); }
public void SpecifyingBrowserCompatibilityModeForIe() { // Arrange const string webSiteName = "TestEasyWebSite"; // create Virtual Application and deploy files WebServer server = WebServer.Create(); WebApplicationInfo appInfo = server.CreateWebApplication(webSiteName); server.DeployWebApplication(appInfo.Name, new List <DeploymentItem> { new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName } }); server.SetCustomHeaders( Path.Combine(appInfo.PhysicalPath, "web.config"), new Dictionary <string, string> { { "X-UA-Compatible", " IE=8" } }); // create browser object using config settings using (var browserManager = new BrowserManager()) { var browser = browserManager.CreateBrowser(BrowserType.Ie, false); // Act browser.Navigate().GoToUrl(appInfo.VirtualPath + "/default.html"); // Assert Assert.AreEqual("[This is my label]", browser.FindElement(By.Id("myLabel")).Text); } }
public void FluentWithWebSockets() { var webServer = WebServer.Create(_webServerUrl) .WithWebSocket(typeof(FluentTest).GetTypeInfo().Assembly); Assert.AreEqual(webServer.Modules.Count, 1, "It has 1 modules loaded"); Assert.IsNotNull(webServer.Module <WebSocketsModule>(), "It has WebSocketsModule"); webServer.Dispose(); }
public void FluentWithStaticFolder() { var webServer = WebServer.Create(WebServerUrl) .WithLocalSession() .WithStaticFolderAt(RootPath); Assert.AreEqual(webServer.Modules.Count, 2, "It has 2 modules loaded"); Assert.IsNotNull(webServer.Module <StaticFilesModule>(), "It has StaticFilesModule"); Assert.AreEqual(webServer.Module <StaticFilesModule>().FileSystemPath, RootPath, "StaticFilesModule root path is equal to RootPath"); }
public void FluentWithVirtualPaths() { var webServer = WebServer.Create(_webServerUrl) .WithVirtualPaths(_commonPaths); Assert.IsNotNull(webServer); Assert.AreEqual(webServer.Modules.Count, 1, "It has 1 modules loaded"); Assert.IsNotNull(webServer.Module <StaticFilesModule>(), "It has StaticFilesModule"); Assert.AreEqual(webServer.Module <StaticFilesModule>().VirtualPaths.Count, 3, "It has 3 Virtual Paths"); }
public void FluentWithWebApi() { var webServer = WebServer.Create(_webServerUrl) .WithWebApi(typeof(FluentTest).GetTypeInfo().Assembly); Assert.AreEqual(webServer.Modules.Count, 1, "It has 1 modules loaded"); Assert.IsNotNull(webServer.Module <WebApiModule>(), "It has WebApiModule"); Assert.AreEqual(webServer.Module <WebApiModule>().ControllersCount, 4, "It has four controllers"); (webServer as IDisposable)?.Dispose(); }
public void WhenCreate_IfTypeIsUnknown_ShouldThrow() { // Arrange // Act var exception = Assert.Throws <NotSupportedException>( () => WebServer.Create("UnknownType", "", new WebServerSettings(), _dependencies)); // Assert Assert.Equal(string.Format("WebServer type is unsupported '{0}', type info: '{1}'. Make sure your web server type is registered in webServerTypes collection in default.config or testsuite.config.", "UnknownType", ""), exception.Message); }
public void Start() { Instances.Add(State, this); _serverSource = new CancellationTokenSource(); WebServer server = AdaptWebServer(WebServer.Create(ServerUri)); server.RegisterModule(new ResourceFilesModule(typeof(ImplictGrantAuth).Assembly, $"SpotifyAPI.Web.Auth.Resources.{_folder}")); #pragma warning disable 4014 server.RunAsync(_serverSource.Token); #pragma warning restore 4014 }
public void FluentWithWebApi() { var webServer = WebServer.Create(WebServerUrl) .WithWebApi(typeof(FluentTest).Assembly); Assert.AreEqual(webServer.Modules.Count, 1, "It has 1 modules loaded"); Assert.IsNotNull(webServer.Module <WebApiModule>(), "It has WebApiModule"); Assert.AreEqual(webServer.Module <WebApiModule>().ControllersCount, 3, "It has three controllers"); webServer.Dispose(); }
public void WhenCreate_IfCustomWebserver_ShouldCreate() { // Arrange _mock.MockWebServer() .MockWebServerInstantiateFromCurrentAssembly(); // Act var server = WebServer.Create(_mock.MockWebServerName, "", null, _dependencies); // Assert Assert.Equal(_mock.MockWebServerName, server.Type); }
public void Start() { if (webServer != null) { throw new InvalidOperationException("WebServer is already started!"); } webServer = WebServer .Create(url) .WithStaticFolderAt(htmlPath); Task.Run(() => webServer.RunAsync()); }
public string Deploy(string applicationName, KatanaWebConfiguration webConfig) { this.WebServer = WebServer.Create(GetWebServerType()); string uniqueAppName = this.WebServer.DefaultWebSite.GetUniqueApplicaionName(applicationName); string appPhysicalPath = Path.Combine(this.WebServer.RootPhysicalPath, uniqueAppName); this.Application = this.WebServer.DefaultWebSite.Applications.Add("/" + uniqueAppName, appPhysicalPath); this.Application.Deploy(GetAssembliesInCurrentDirectory(), "bin"); this.Application.Deploy("web.config", webConfig.GetWebConfigurationContent()); this.WebServer.ServerManager.CommitChanges(); return(this.WebServer.DefaultWebSite.GetHttpVirtualPath() + this.Application.Path); }
public void FluentLoadWebApiControllers() { var webServer = WebServer.Create(Resources.ServerAddress) .WithWebApi(); webServer.Module <WebApiModule>().LoadApiControllers(typeof(FluentTest).Assembly); Assert.AreEqual(webServer.Modules.Count, 1, "It has 1 modules loaded"); Assert.IsNotNull(webServer.Module <WebApiModule>(), "It has WebApiModule"); Assert.AreEqual(webServer.Module <WebApiModule>().ControllersCount, 2, "It has two controllers"); webServer.Dispose(); }
public void Start() { Instances.Add(State, this); _serverSource = new CancellationTokenSource(); _server = WebServer.Create(ServerUri, RoutingStrategy.Regex); _server.RegisterModule(new WebApiModule()); AdaptWebServer(_server); _server.RegisterModule(new ResourceFilesModule(typeof(T).Assembly, $"SpotifyAPI.Web.Auth.Resources.{_folder}")); #pragma warning disable 4014 _server.RunAsync(_serverSource.Token); #pragma warning restore 4014 }
public void SetupWebsite() { // common logic to arrange the test website _server = WebServer.Create(); _appInfo = _server.CreateWebApplication("TestEasyWAP"); _server.DeployWebApplication(_appInfo.Name, new List <DeploymentItem> { new DeploymentItem { Type = DeploymentItemType.Directory, Path = WebSiteName } }); }
public void WhenCreate_IfWebServerFromCustomAssembly_ShouldCreate() { // Arrange _mock.MockWebServerFromCustomAssembly() .MockWebServerInstantiateFromCustomAssembly(); // Act var exception = Assert.Throws <NotSupportedException>( () => WebServer.Create(_mock.MockWebServerName, "", new WebServerSettings(), _dependencies)); // Assert Assert.Equal(string.Format("WebServer type is unsupported '{0}', type info: '{1}'. Make sure your web server type is registered in webServerTypes collection in default.config or testsuite.config.", _mock.MockWebServerName, _mock.MockWebServerType + ", " + _mock.MockCustomAssemblyName), exception.Message); }
public void WhenCreate_IfIisExpressNotRegistered_ShouldUseItAutomatically() { // Arrange _mock.MockWebServerIisInConfig() .MockWebServerInstantiateFromCurrentAssembly(); // Act var exception = Assert.Throws <NotSupportedException>( () => WebServer.Create("IISExpress", "", new WebServerSettings(), _dependencies)); // Assert Assert.Equal(string.Format("WebServer type is unsupported '{0}', type info: '{1}'. Make sure your web server type is registered in webServerTypes collection in default.config or testsuite.config.", "IISExpress", "TestEasy.WebServer.WebServerIisExpress"), exception.Message); }
public WebServerAndBrowsersSngleWebsitesTest() { if (Server == null) { Server = WebServer.Create(); AppInfo = Server.CreateWebApplication(WebSiteName); Server.DeployWebApplication(AppInfo.Name, new List <DeploymentItem> { new DeploymentItem { Type = DeploymentItemType.Directory, Path = WebSiteName } }); } }
public void MultipleBrowsersTest() { // Arrange const string webSiteName = "TestEasyWAP"; // Create server object WebServerSettings settings = new WebServerSettings { HostName = Environment.MachineName, // machine anme or empty (in this case localhost will be used) RootPhysicalPath = TestEasyHelpers.Tools.GetUniqueTempPath(webSiteName) // needed only when web server type is IISExpress }; WebServer server = WebServer.Create("IISExpress", settings); WebApplicationInfo appInfo = server.CreateWebApplication(webSiteName); server.DeployWebApplication(appInfo.Name, new List <DeploymentItem> { new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName } }); server.BuildWebApplication(webSiteName); // create browser object using (BrowserManager browserManager = new BrowserManager()) { List <IWebDriver> myBrowsers = new List <IWebDriver> { browserManager.CreateBrowser(remote: false), browserManager.CreateBrowser(remote: false), browserManager.CreateBrowser(remote: false) }; foreach (var browser in myBrowsers) { // Act browser.Navigate().GoToUrl(appInfo.VirtualPath + "/SamplePostWebForm.aspx"); browser.FindElement(By.Id("Button1")).Click(); browser.WaitForPageLoaded(); // Assert Assert.AreEqual("[Clicked!]", browser.FindElement(By.Id("TextBox1")).GetAttribute("value")); } } }
public void FluentWithVirtualPaths() { var paths = new Dictionary <string, string> { { "/Server/web", TestHelper.SetupStaticFolder() }, { "/Server/api", TestHelper.SetupStaticFolder() }, { "/Server/database", TestHelper.SetupStaticFolder() } }; var webServer = WebServer.Create(WebServerUrl) .WithVirtualPaths(paths); Assert.IsNotNull(webServer); Assert.AreEqual(webServer.Modules.Count, 1, "It has 1 modules loaded"); Assert.IsNotNull(webServer.Module <StaticFilesModule>(), "It has StaticFilesModule"); Assert.AreEqual(webServer.Module <StaticFilesModule>().VirtualPaths.Count, 3, "It has 3 Virtual Paths"); }
/// <summary> /// Load WebServer instance /// </summary> /// <param name="args"></param> private static void Main(string[] args) { var options = new Options(); Console.WriteLine("Unosquare.Labs.EmbedIO Web Server"); if (!Parser.Default.ParseArguments(args, options)) { return; } Console.WriteLine(" Command-Line Utility: Press any key to stop the server."); var serverUrl = "http://localhost:" + options.Port + "/"; using ( var server = options.NoVerbose ? WebServer.Create(serverUrl) : WebServer.CreateWithConsole(serverUrl)) { if (Properties.Settings.Default.UseLocalSessionModule) { server.WithLocalSession(); } server.EnableCors().WithStaticFolderAt(options.RootPath, defaultDocument: Properties.Settings.Default.HtmlDefaultDocument); server.Module <StaticFilesModule>().DefaultExtension = Properties.Settings.Default.HtmlDefaultExtension; server.Module <StaticFilesModule>().UseRamCache = Properties.Settings.Default.UseRamCache; if (options.ApiAssemblies != null && options.ApiAssemblies.Count > 0) { foreach (var api in options.ApiAssemblies) { server.Log.DebugFormat("Registering Assembly {0}", api); LoadApi(api, server); } } // start the server server.RunAsync(); Console.ReadKey(true); } }
public void DeployNavigateAndUploadFileTest() { // Arrange const string webSiteName = "TestEasyWAP"; var server = WebServer.Create(); var appInfo = server.CreateWebApplication(webSiteName); server.DeployWebApplication(appInfo.Name, new List <DeploymentItem> { new DeploymentItem { Type = DeploymentItemType.Directory, Path = webSiteName } }); server.BuildWebApplication(webSiteName); var fileToUpload = @"c:\temp\tempfile.txt"; if (!File.Exists(fileToUpload)) { if (!Directory.Exists(@"c:\temp")) { Directory.CreateDirectory(@"c:\temp"); } File.WriteAllText(fileToUpload, "some content"); } using (var browserManager = new BrowserManager()) { var browser = browserManager.CreateBrowser(); // Act browser.Navigate().GoToUrl(appInfo.VirtualPath + "/SamplePostWebForm.aspx"); browser.FindElement(By.Id("fileUpload")).SendKeys(fileToUpload); browser.FindElement(By.XPath("//input[@name='Button1']")).Click(); browser.WaitForPageLoaded(); // Assert Assert.AreEqual("[Clicked!]", browser.FindElement(By.Id("TextBox1")).GetAttribute("value")); } }
public void WhenCreate_IfCustomWebserverAndWebSiteProvided_ShouldCreate() { // Arrange _mock.MockWebServer() .MockWebServerInstantiateFromCurrentAssembly() .MockWebServerCreateWithWebSiteProvided() .MockWebServerCreate_RemoteFalse(); TestEasyHelpers.Tools = _mock.ToolsHelper.Object; // Act var settings = new WebServerSettings(); var server = WebServer.Create(_mock.MockWebServerName, _mock.MockCreateWebSiteName, settings, _dependencies); // Assert Assert.Equal(_mock.MockWebServerName, server.Type); Assert.Equal(_mock.MockCreateWebSiteName, settings.WebAppName); Assert.Equal("localhost", settings.HostName); Assert.Equal(100000, settings.StartupTimeout); }
public WebServer CreateWebServer(string websiteName = "") { var webServerType = (WebServerType)Enum.Parse(typeof(WebServerType), TestEasyConfig.WebServer.Type); if (TestEasyConfig.Client.Remote && webServerType == WebServerType.IISExpress) { throw new NotSupportedException("For tests using remote browsers, IISExpress web server type is not supported at this moment."); } var settings = new WebServerSettings { HostName = TestEasyConfig.Client.Remote ? Environment.MachineName : "", RootPhysicalPath = (webServerType == WebServerType.IISExpress) ? TestEasyUtils.GetUniqueTempPath(websiteName) : "" }; return(WebServer.Create(webServerType, settings)); }
private void CreateWebServer(string deployPath, string connectionString) { const int MaxRetries = 3; int attempt = 0; while (true) { try { _webServer = WebServer.Create("iisexpress"); _webApplicationInfo = _webServer.CreateWebApplication(ApplicationName); _webServer.DeployWebApplication(_webApplicationInfo.Name, new List <DeploymentItem> { new DeploymentItem { Type = DeploymentItemType.Directory, Path = deployPath } }); _webConfigFilePath = Path.Combine(_webServer.RootPhysicalPath, ApplicationName, "web.config"); SetStorageConnectionString(connectionString); _virtualPath = _webApplicationInfo.VirtualPath; return; } catch { if (attempt++ < MaxRetries) { // Swallow any startup errors and retry after a short // period // We're seeing some File IO issues from TestEasy that look // like timing issues Thread.Sleep(2000); } else { // We're unable to create the server even after retries throw; } } } }
public void Init() { var url = "http://localhost:12346/"; // Create Webserver and attach LocalSession and Static // files module and CORS enabled server = WebServer.Create(url); server.RegisterModule(new FallbackModule((context, cancel) => { lastRequest = context.Request; string endpoint = lastRequest.RawUrl.Substring(1); bool redirect = endpoint.StartsWith("redirect/"); if (redirect) { endpoint = endpoint.Substring("redirect/".Length); } if (Regex.Matches(endpoint, "^[1-5][0-9][0-9]$").Count > 0) { context.Response.StatusCode = int.Parse(endpoint); switch (context.Response.StatusCode) { case 301: context.Response.Headers.Add("Location: /redirect/200"); break; case 302: context.Response.Headers.Add("Location: /doesnotexist"); break; } } else { context.Response.StatusCode = 404; } string valueName = redirect ? "redirect" : "statusCode"; var responseBytes = Encoding.UTF8.GetBytes($"{{{valueName}: {context.Response.StatusCode}}}"); context.Response.OutputStream.Write(responseBytes, 0, responseBytes.Length); return(true); })); serverCancel = new CancellationTokenSource(); serverTask = server.RunAsync(serverCancel.Token); }
/// <summary> /// Entry point /// </summary> /// <param name="args"></param> private static void Main(string[] args) { try { Console.WriteLine("Do you want to run EmbedIO as OWIN Server? (y/n)"); var response = Console.ReadLine(); if (response != null && response.ToLower() == "y") { var options = new StartOptions { ServerFactory = OwinServerFactory.ServerFactoryName, Port = 4578 }; using (WebApp.Start <Startup>(options)) { "Running a http server on port {options.Port}".Info(nameof(Program)); Console.ReadKey(); } } else { using (var webServer = WebServer .Create("http://localhost:4578") .WithWebApi(typeof(PeopleController).Assembly) .UseOwin((owinApp) => owinApp .UseDirectoryBrowser() .UseRazor(Startup.InitRoutes))) { webServer.RunAsync(); Console.ReadKey(); } } } catch (Exception ex) { ex.Log(nameof(Program)); Console.ReadKey(); } }
public HttpServer(IPAddress ip, int port) { //Log.Info(m => m("Server start")); _cts = new CancellationTokenSource(); _webServer = WebServer.Create( new UriBuilder { Scheme = "http", Host = ip.ToString(), Port = port, Path = "/" }.ToString() ); _webServer.RegisterModule(new RequestDispatcher()); _webServer?.RunAsync(_cts.Token); }
public void FluentWithStaticFolder() { var webServer = WebServer.Create(WebServerUrl) .WithLocalSession() .WithStaticFolderAt(RootPath); Assert.AreEqual(webServer.Modules.Count, 2, "It has 2 modules loaded"); Assert.IsNotNull(webServer.Module <StaticFilesModule>(), "It has StaticFilesModule"); Assert.AreEqual(webServer.Module <StaticFilesModule>().FileSystemPath, RootPath, "StaticFilesModule root path is equal to RootPath"); webServer.RunAsync(); var request = (HttpWebRequest)WebRequest.Create(WebServerUrl); using (var response = (HttpWebResponse)request.GetResponse()) { Assert.AreEqual(response.StatusCode, HttpStatusCode.OK, "Status Code OK"); } webServer.Dispose(); }