public void Configuration(IAppBuilder appBuilder) { var config = new HttpConfiguration(); // DI var settingsContainer = new WebApplicationSettings(); var container = Bootstrapper.ConfigureUnity(settingsContainer); config.DependencyResolver = new UnityResolver(container); // turn on CORS support config.EnableCors(new EnableCorsAttribute("*", "*", "*")); // default web api config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}", new { id = RouteParameter.Optional }); // configure entity framework DbConfiguration.SetConfiguration(new ODataDbConfiguration()); // register odata models var httpServer = new HttpServer(config); var modelRegistrator = container.Resolve <ODataModelRegistrator>(); modelRegistrator.RegisterModels(httpServer); appBuilder.UseWebApi(httpServer); }
/// <summary> /// Construct a new handler for GetWebClientInfo. /// </summary> /// <param name="applicationSettings">Application settings pulled from configuration</param> /// <param name="httpContextAccessor">Accessor for the current httpContext</param> /// <param name="antiforgery">The ASP.NET antiForgery object</param> /// <param name="currentUserAccessor">UI-friendly user name</param> public Handler(WebApplicationSettings applicationSettings, IHttpContextAccessor httpContextAccessor, IAntiforgery antiforgery, ICurrentUserAccessor currentUserAccessor) { _applicationSettings = applicationSettings; _httpContextAccessor = httpContextAccessor; _antiForgery = antiforgery; _currentUserAccessor = currentUserAccessor; }
public void WebApplicationSettings_has_parameterless_constructor_for_aspnet_options() { var appSettings = new WebApplicationSettings() { Name = "Something", BaseUrl = "Something" }; appSettings.Validate(); Assert.True(appSettings is not null); }
public static RemoteWebDriver CreateDriver(WebApplicationSettings settings) { var driver = CreateDriverByBrowser(settings); if (settings.RunMode == RunMode.Minimized) { driver.Manage().Window.Minimize(); } if (settings.RunMode == RunMode.Maximized) { driver.Manage().Window.Maximize(); } return(driver); }
public async Task GetWebClientInfo_return_client_app_info() { var applicationSettings = new WebApplicationSettings() { Name = "AppName" }; var currentUserAccessorMock = new Mock <ICurrentUserAccessor>(); currentUserAccessorMock .Setup(mock => mock.User) .Returns(new DomainUser("UserName", new[] { "policy1", "policy2" })); var contextMock = new Mock <HttpContext>(); var contextAccessorMock = new Mock <IHttpContextAccessor>(); contextAccessorMock .Setup(mock => mock.HttpContext) .Returns(contextMock.Object); var antiforgeryMock = new Mock <IAntiforgery>(); antiforgeryMock .Setup(mock => mock.GetAndStoreTokens(It.IsAny <HttpContext>())) .Returns(new AntiforgeryTokenSet("request-token", "cookie-token", "formFieldName", "header-name")); var loggerMock = new Mock <ILogger <GetWebClientInfo.ResponseLogger> >(); var result = await new GetWebClientInfo.Handler(applicationSettings, contextAccessorMock.Object, antiforgeryMock.Object, currentUserAccessorMock.Object) .AddPostProcessor(new GetWebClientInfo.ResponseLogger(loggerMock.Object)) .Handle(new GetWebClientInfo.Request()); Assert.True(result.IsSuccess); Assert.NotNull(result.Value); var appInfo = result.Value; Assert.Equal("AppName", appInfo.ApplicationName); Assert.Equal("UserName", appInfo.User.Login); Assert.Equal(new[] { "policy1", "policy2" }, appInfo.User.AuthorizedAs); Assert.Equal("header-name", appInfo.AntiforgeryTokenHeaderName); Assert.Equal("request-token", appInfo.AntiforgeryToken); }
private static RemoteWebDriver CreateDriverByBrowser(WebApplicationSettings settings) { switch (settings.Browser) { case WebBrowser.Firefox: { var options = new FirefoxOptions { AcceptInsecureCertificates = settings.AcceptInsecureCertificates }; if (settings.RunMode == RunMode.Headless) { options.AddArgument("--headless"); } return(new FirefoxDriver(options)); } case WebBrowser.Chrome: { var options = new ChromeOptions { AcceptInsecureCertificates = settings.AcceptInsecureCertificates }; if (settings.RunMode == RunMode.Headless) { options.AddArgument("--headless"); } else if (settings.RunMode == RunMode.Maximized) { options.AddArgument("--start-maximized"); } return(new ChromeDriver(options)); } default: { throw new Exception("Unsupported browser"); } } }
public ExampleApplicationFixture() { var settings = new WebApplicationSettings { Browser = WebBrowser.Chrome, RunMode = RunMode.Headless }; _host = Host.CreateDefaultBuilder() .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup <Startup>(); webBuilder.UseUrls(settings.Url); }) .Build(); _host.Start(); _app = new ExampleApplication(settings); }
public ExampleApplication(WebApplicationSettings settings = null) : base(settings) { }