public void StartWebServer_PortNumberIsZero_PortNumberAvailableInWebServerContextNotImplemented() { // arrange WebServerConfiguration configuration = GetValidCassisniContext(); configuration.PortNumber = 0; _webServer = new WebServer(configuration); // act try { Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : about to start server"); _webServer.Start(); Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : server has been started"); } finally { _webServer.Stop(); Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : stop was called"); } // assert }
public void StartWebServer_ValidContextSupplied_WebServerStartedAndProcessHostingServiceIsReturned() { // arrange WebServerConfiguration configuration = GetValidCassisniContext(); try { // act Assert.That(Process.GetProcessesByName(_expectedProcessName).Length, Is.EqualTo(0)); _webServer = new WebServer(configuration); Assert.That(_webServer, Is.Not.Null); Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : about to start server"); _webServer.Start(); Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : server has been started"); Assert.That(Process.GetProcessesByName(_expectedProcessName).Length, Is.EqualTo(1)); string requestedUri = @"http://localhost:" + configuration.PortNumber + "/" + configuration.DefaultWebPageFileName; var request = (HttpWebRequest)WebRequest.Create(requestedUri); WebResponse response = request.GetResponse(); Assert.That(response, Is.Not.Null); Stream responseStream = response.GetResponseStream(); string theContent = GetContent(responseStream).ToString(); // assert Assert.That(theContent.Contains("Login Page"), Is.True); } finally { _webServer.Stop(); Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : stop was called"); } }
public void StopWebServer_WebServerStarted_WebServerStoppedSuccessfully() { KillAllCassiniProcesses(); Assert.That(Process.GetProcessesByName(_expectedProcessName).Length, Is.EqualTo(0)); try { WebServerConfiguration configuration = GetValidCassisniContext(); _webServer = new WebServer(configuration); _webServer.Start(); Assert.That(Process.GetProcessesByName(_expectedProcessName).Length, Is.EqualTo(1)); _webServer.Stop(); Thread.Sleep(2000); Assert.That(Process.GetProcessesByName(_expectedProcessName).Length, Is.EqualTo(0)); } catch (Exception ex) { Assert.Fail(ex.ToString()); } finally { KillAllCassiniProcesses(); } }
public void StartListening(IGablarskiServerContext context) { var sstore = new MemorySessionStore { ExpireTime = 15 }; server = new HttpServer.HttpServer(sstore); ConnectionManager cmanager = new ConnectionManager(sstore); cmanager.ConnectionProvider = this; cmanager.Server = server; server.Add(new QueryModule(cmanager)); WebServerConfiguration config = (WebServerConfiguration)ConfigurationManager.GetSection("webserver"); if (config != null && config.Theme != null) { server.Add(new FileResourceModule(config.Theme.Path)); server.Add(new LoginModule(cmanager)); server.Add(new ChannelModule(cmanager)); server.Add(new UserModule(cmanager)); } server.Start(IPAddress.Any, this.Port); }
public ApplicationConfiguration() { Editor = new EditorConfiguration(); Git = new GitConfiguration(); Images = new ImagesConfiguration(); MarkdownOptions = new MarkdownOptionsConfiguration(); WindowPosition = new WindowPositionConfiguration(); FolderBrowser = new FolderBrowserConfiguration(); ApplicationUpdates = new ApplicationUpdatesConfiguration(); PdfOutputWindow = new PdfOutputConfiguration(); WebServer = new WebServerConfiguration(); System = new SystemConfiguration(); OpenDocuments = new List <OpenFileDocument>(); // Make sure common folder points at AppData\Markdown Monster or PortableSettings InternalCommonFolder = FindCommonFolder(); CommonFolder = InternalCommonFolder; LastFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); PreviewSyncMode = PreviewSyncMode.EditorToPreview; AutoSaveBackups = true; AutoSaveDocuments = false; RecentDocumentsLength = 10; RememberLastDocumentsLength = 5; //BugReportUrl = "https://markdownmonster.west-wind.com/bugreport/bugreport.ashx?method=ReportBug"; //BugReportUrl = "http://localhost.fiddler/MarkdownMonster/bugreport/bugreport.ashx?method=ReportBug"; //TelemetryUrl = "https://markdownmonster.west-wind.com/bugreport/bugreport.ashx?method=Telemetry"; ApplicationTheme = Themes.Dark; PreviewTheme = "Dharkan"; EditorTheme = "vscodedark"; DefaultCodeSyntax = "csharp"; PreviewHttpLinksExternal = true; UseMachineEncryptionKeyForPasswords = true; TerminalCommand = "powershell.exe"; TerminalCommandArgs = "-noexit -command \"cd '{0}'\""; OpenFolderCommand = "explorer.exe"; WebBrowserPreviewExecutable = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Google\Chrome\Application\chrome.exe"); UseSingleWindow = true; IsPreviewVisible = true; IsDocumentOutlineVisible = true; OpenInPresentationMode = false; AlwaysUsePreviewRefresh = false; }
public static HttpOutputByteStream createByteStream( WebServerConfiguration aConfig, StartSession aStartSession, StartSession aStopSession, WriteClientIP aWriteClientIP) { return(new HttpOutputByteStream(aConfig, aStartSession, aStopSession, aWriteClientIP)); }
private WebServerConfiguration BuildWebServerConfiguration() { var config = BuildConfig(); var batch = new WebServerConfiguration(); config.GetSection("webserver").Bind(batch); return(batch); }
private HttpOutputByteStream( WebServerConfiguration aConfig, StartSession aStartSession, StartSession aStopSession, WriteClientIP aWriteClientIP) { mWebServer = new WebServer(aConfig, aStartSession, aStopSession, aWriteClientIP); mWebServer.Start(); }
private void StartServer() { webConf = new WebServerConfiguration(); webConf.IPAddress = IPAddress.Any; webConf.Port = DefaultSettings.BrokerPort; webServer = new WebServer(webConf); webServer.OnLogEvent += Log; webServer.Start(); }
public void Setup() { config = new WebServerConfiguration(); context = new FakeWebContext( null, null, Mock.Of <IFileSystem>(), new TimeMachine(), config); hstsPolicy = new HstsPolicy(); }
public void Setup() { fileSystem = MockRepository.GenerateStub <IFileSystem>(); configuration = new WebServerConfiguration(); ITimeService timeService = MockRepository.GenerateStub <ITimeService>(); timeService.Stub(x => x.CurrentTime).Return(new DateTime(2014, 06, 16, 20, 07, 00)); context = new FakeWebContext(null, null, fileSystem, timeService, configuration); }
/// <summary> /// New WebServer /// </summary> /// <param name="webServerConf">WebServer Configuration</param> public WebServer( WebServerConfiguration webServerConf, StartSession aStartSession, StartSession aStopSession, WriteClientIP aWriteClientIP) { this.Configuration = webServerConf; mStartSession += aStartSession; mStopSession += aStopSession; mWriteClientIP += aWriteClientIP; }
public void WebServerConfigurationTests_Execute__IsWebServerEnabled_and_isWebServerSslEnabled() { //----------------Arrange-------------------- ConfigurationManager.AppSettings.Set("webServerEnabled", "True"); ConfigurationManager.AppSettings.Set("webServerSslEnabled", "True"); var mockWriter = new Mock <IWriter>(); var mockFileWrapper = new Mock <IFile>(); //----------------Act------------------------ var webServerConfig = new WebServerConfiguration(mockWriter.Object, mockFileWrapper.Object); webServerConfig.Execute(); //----------------Assert--------------------- Assert.IsTrue(webServerConfig.IsWebServerEnabled); Assert.IsTrue(webServerConfig.IsWebServerSslEnabled); }
public void WebServerConfigurationTests_Execute__IsWebServerEnabled_True() { //----------------Arrange-------------------- ConfigurationManager.AppSettings.Set("webServerPort", "80"); ConfigurationManager.AppSettings.Set("webServerEnabled", "true"); var mockWriter = new Mock <IWriter>(); var mockFileWrapper = new Mock <IFile>(); //----------------Act------------------------ var webServerConfig = new WebServerConfiguration(mockWriter.Object, mockFileWrapper.Object); webServerConfig.Execute(); var endPoints = webServerConfig.EndPoints; Assert.AreEqual(1, endPoints.Length); Assert.AreEqual("http://*:80/", endPoints[0].Url); }
private static WebServerConfiguration GetValidCassisniContext() { string codeBasePath = string.Format(@"{0}/Resources/UltiDevCassinWebServer2a.exe", Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase)); UriBuilder uri = new UriBuilder(codeBasePath); string executableFilePath = Uri.UnescapeDataString(uri.Path).Replace('/', '\\'); var webServerConfiguration = new WebServerConfiguration { CassiniExecutableFilePath = executableFilePath, DefaultWebPageFileName = "default.aspx", OpenDefaultPageAutomatically = true, PortNumber = 8765, WebSiteRootFolder = Path.GetFullPath(@"..\..\..\TestingLoginWithWatin") }; return(webServerConfiguration); }
public void StopWebServer_WebServerNotStarted_NoExceptionThrown() { // arrange WebServerConfiguration configuration = GetValidCassisniContext(); _webServer = new WebServer(configuration); // act try { _webServer.Stop(); Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : stop was called"); } catch { Assert.Fail("Calling stop on a server that wasn't started caused an exception."); } }
public void WebServerConfigurationTests_Execute_WebServerSslPort_Invalid_ExpectException() { //----------------Arrange-------------------- ConfigurationManager.AppSettings.Set("webServerPort", "80"); ConfigurationManager.AppSettings.Set("webServerSslPort", "asdfddd"); ConfigurationManager.AppSettings.Set("webServerEnabled", "true"); ConfigurationManager.AppSettings.Set("webServerSslEnabled", "true"); var mockWriter = new Mock <IWriter>(); var mockFileWrapper = new Mock <IFile>(); //----------------Act------------------------ var webServerConfig = new WebServerConfiguration(mockWriter.Object, mockFileWrapper.Object); webServerConfig.Execute(); //----------------Assert--------------------- mockWriter.Verify(a => a.Fail("Server initialization failed", It.IsAny <ArgumentException>()), Times.Once); }
private bool StartServer() { try { var rnd = new Random(); webConf = new WebServerConfiguration(); webConf.IPAddress = IPAddress.Any; webConf.Port = 8000 + rnd.Next(99); webServer = new SubscriberWebServer(webConf); webServer.OnLogEvent += Log; webServer.OnNotifyPosition += OnPostionUpdate; webServer.Start(); return(true); } catch { return(false); }; }
public void StartWebServer_CassisniDefaultWebPageFilePathInvalid_ExceptionThrown() { // arrange WebServerConfiguration configuration = GetValidCassisniContext(); configuration.DefaultWebPageFileName = @"ThisFileNameIsInvalid.aspx"; _webServer = new WebServer(configuration); // act try { Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : about to start server"); _webServer.Start(); Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : server has been started"); } finally { _webServer.Stop(); Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : stop was called"); } }
public void StartWebServer_CassisniWebSiteRootFolderInvalid_ExceptionThrown() { // arrange WebServerConfiguration configuration = GetValidCassisniContext(); configuration.WebSiteRootFolder = @"C:\This directory does not exist"; _webServer = new WebServer(configuration); // act try { Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : about to start server"); _webServer.Start(); Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : server has been started"); } finally { _webServer.Stop(); Trace.WriteLine(MethodBase.GetCurrentMethod().Name + " : stop was called"); } }
public SyborgTestHttpModuleAppHost() { IFileSystem fileSystem = new WindowsFileSystem(); IApplicationInfo applicationInfo = new ApplicationInfo(); ITimeService timeService = new RealTimeService(); IRazorCompiler razorCompiler = new InMemoryRazorCompiler(); IRazorViewRenderingEngine viewRenderingEngine = new RazorViewRenderingEngine(fileSystem, razorCompiler); IWebServerConfiguration config = new WebServerConfiguration(); FileMimeTypesMap fileMimeTypesMap = new FileMimeTypesMap().RegisterStandardMimeTypes(); Initialize(config, fileSystem, applicationInfo, timeService, fileMimeTypesMap, viewRenderingEngine); IFileCache fileCache = new FileCache(); string webAppRootDir; if (!WebServerConfiguration.WebServerDevelopmentMode) { #if NCRUNCH webAppRootDir = @"D:\hg\ScalableMaps\WebApp\ScalableMaps\ScalableMaps.Web2"; #else webAppRootDir = ApplicationInfo.GetAppDirectoryPath(".."); #endif } else { webAppRootDir = ApplicationInfo.GetAppDirectoryPath(".."); } ContentCommand contentCommand = RegisterWebContent(webAppRootDir, fileCache, config); TestStreamCommand streamCommand = new TestStreamCommand(); AddRoute(new RegexWebRequestRoute("^Content/(?<path>.+)$", HttpMethod.GET, contentCommand)); AddRoute(new RegexWebRequestRoute("^stream/(?<path>.+)$", HttpMethod.GET, streamCommand)); AddPolicies(new IWebPolicy[] { new SecureResponseHeadersPolicy() }); }
public void WebServerConfigurationTests_Execute_WebServerPort_IsEmptyOrNull_ExpectExeption() { //----------------Arrange-------------------- string expectedUsageStats = "33.33"; string expectedPort = ""; string expectedSslPort = "55"; ConfigurationManager.AppSettings.Set("CollectUsageStats", expectedUsageStats); ConfigurationManager.AppSettings.Set("webServerPort", expectedPort); ConfigurationManager.AppSettings.Set("webServerSslPort", expectedSslPort); ConfigurationManager.AppSettings.Set("webServerEnabled", "true"); var mockWriter = new Mock <IWriter>(); var mockFileWrapper = new Mock <IFile>(); //----------------Act------------------------ var webServerConfig = new WebServerConfiguration(mockWriter.Object, mockFileWrapper.Object); webServerConfig.Execute(); //----------------Assert--------------------- mockWriter.Verify(a => a.Fail("Server initialization failed", It.IsAny <ArgumentException>()), Times.Once); }
public void Setup() { IFileSystem fileSystem = new WindowsFileSystem(); IApplicationInfo applicationInfo = new ApplicationInfo(); ITimeService timeService = new RealTimeService(); ISignal serverStopSignal = new ManualResetSignal(false); IWebServerConfiguration configuration = new WebServerConfiguration(); IRazorCompiler razorCompiler = new InMemoryRazorCompiler(); IRazorViewRenderingEngine viewRenderingEngine = new RazorViewRenderingEngine(fileSystem, razorCompiler); IWebServerController webServerController = new WebServerController(serverStopSignal); IFileMimeTypesMap fileMimeTypesMap = new FileMimeTypesMap(); IFileCache fileCache = new FileCache(); List <IWebRequestRoute> routes = new List <IWebRequestRoute>(); string contentRootDirectory = Path.Combine(TestContext.CurrentContext.TestDirectory, "sample-content"); ContentCommand contentCommand = new ContentCommand(contentRootDirectory, fileSystem, fileCache); routes.Add(new RegexWebRequestRoute("^content/(?<path>.+)$", HttpMethod.GET, contentCommand)); // ReSharper disable once CollectionNeverUpdated.Local List <IWebPolicy> policies = new List <IWebPolicy>(); const string ExternalUrl = "http://localhost"; const int Port = 12345; testServiceUrl = "{0}:{1}/".Fmt(ExternalUrl, Port); host = new TestHost( configuration, ExternalUrl, Port, null, fileSystem, applicationInfo, timeService, viewRenderingEngine, fileMimeTypesMap, webServerController, routes, policies); host.Start(); IWebConfiguration webConfiguration = new WebConfiguration("Syborg.Tests"); restClientFactory = new RestClientFactory(webConfiguration); }
public void WebServerConfigurationTests_Execute_IsWebServerEnabled_False() { //----------------Arrange-------------------- string expectedUsageStats = "33.33"; string expectedPort = "44"; string expectedSslPort = "55"; ConfigurationManager.AppSettings.Set("CollectUsageStats", expectedUsageStats); ConfigurationManager.AppSettings.Set("webServerPort", expectedPort); ConfigurationManager.AppSettings.Set("webServerSslPort", expectedSslPort); var mockWriter = new Mock <IWriter>(); var mockFileWrapper = new Mock <IFile>(); //----------------Act------------------------ var webServerConfig = new WebServerConfiguration(mockWriter.Object, mockFileWrapper.Object); webServerConfig.Execute(); //----------------Assert--------------------- Assert.AreEqual(expectedUsageStats, GlobalConstants.CollectUsageStats); Assert.AreEqual(expectedPort, GlobalConstants.WebServerPort); Assert.AreEqual(expectedSslPort, GlobalConstants.WebServerSslPort); Assert.IsFalse(webServerConfig.IsWebServerEnabled); }
/// <summary> /// Adds the runtime services to the instance. /// </summary> /// <param name="services">The services.</param> public void ConfigureServices(IServiceCollection services) { services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); services.AddSingleton <IConfiguration>(this.Configuration); services.AddSingleton <ITelemetryInitializer, TelemetryUserAndSessionContext>(); services.AddApplicationInsightsTelemetry(); services.AddOptions(); services.Configure <IdentityProviderConfiguration>(options => { Configuration.GetSection("azuread").Bind(options); IdentityProviderConfiguration.Validate(options); }); services.Configure <SearchConfiguration>(options => { Configuration.GetSection("search").Bind(options); SearchConfiguration.Validate(options); }); services.Configure <CosmosConfiguration>(options => { Configuration.GetSection("documents").Bind(options); CosmosConfiguration.Validate(options); }); services.Configure <StorageConfiguration>((config) => { Configuration.GetSection("storage").Bind(config); StorageConfiguration.Validate(config); }); services.Configure <WebServerConfiguration>(options => { Configuration.GetSection("webserver").Bind(options); WebServerConfiguration.Validate(options); }); services.Configure <BatchConfiguration>((config) => { Configuration.GetSection("batch").Bind(config); BatchConfiguration.Validate(config); }); var armTemplatesMap = Configuration.GetSection("armTemplates").Get <ArmTemplatesMap>(); services.AddSingleton(armTemplatesMap); var staticAssetsMap = Configuration.GetSection("staticAssets").Get <StaticAssetsMap>(); services.AddSingleton(staticAssetsMap); services.AddMemoryCache(); services.AddCors(options => { options.AddPolicy("DefaultPolicy", builder => builder.AllowAnyOrigin() .WithMethods("GET", "POST", "PUT", "DELETE") .AllowAnyHeader() .AllowCredentials()); }); services.AddResponseCompression(opt => { opt.EnableForHttps = true; }); services.AddMvc() .AddMvcOptions(options => { options.Filters.Add(new TelemetryExceptionFilter(new LoggerFactory())); }) .AddJsonOptions(options => { options.SerializerSettings.Converters.Add(new StringEnumConverter { CamelCaseText = true }); }); services.AddScoped <DatasetSearchService>(); services.AddScoped <FileSearchService>(); services.AddScoped <DatasetStorageService>(); services.AddScoped <DatasetOwnersService>(); services.AddScoped <DatasetEditStorageService>(); services.AddScoped <UserDataStorageService>(); services.AddScoped <FileStorageService>(); services.AddScoped <LicenseStorageService>(); services.AddScoped <ValidationService>(); services.AddScoped <SasTokenService>(); services.AddScoped <GenerateFilePreview>(); services.AddScoped <CurrentUserService>(); services.AddScoped <ApplicationJobs>(); if (this.UseSwagger) { services.UseSwagger(this.Configuration); } services .AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(options => { var tenantName = Configuration["AzureAD:Tenant"].Split('.').First(); var policyName = Configuration["AzureAD:Policy"]; var audience = Configuration["AzureAD:Audience"]; options.MetadataAddress = $"https://{tenantName}.b2clogin.com/{tenantName}.onmicrosoft.com/{policyName}/v2.0/.well-known/openid-configuration"; options.Audience = audience; options.Events = new JwtBearerEvents { OnAuthenticationFailed = context => { var ctx = context; return(Task.FromResult(0)); }, }; }); }
public void PassesValidation() { var config = BuildWebServerConfiguration(); WebServerConfiguration.Validate(config); }
public KestrelConfiguration(IOptions <WebServerConfiguration> configuration) { _configuration = configuration.Value; }
/// <summary> /// New WebServer /// </summary> /// <param name="webServerConf">WebServer Configuration</param> public WebServer(WebServerConfiguration webServerConf) { this.Configuration = webServerConf; }
public static IMFByteStream createByteStream(WebServerConfiguration aConfig) { return(new HttpOutputByteStream(aConfig)); }
private HttpOutputByteStream(WebServerConfiguration aConfig) { mWebServer = new WebServer(aConfig); mWebServer.Start(); }