public void GetExceptionLoggers_DelegatesToGetServices() { // Arrange IExceptionLogger expectedExceptionLogger = new Mock <IExceptionLogger>(MockBehavior.Strict).Object; IEnumerable <IExceptionLogger> expectedExceptionLoggers = new IExceptionLogger[] { expectedExceptionLogger }; Mock <ServicesContainer> mock = new Mock <ServicesContainer>(MockBehavior.Strict); mock.Setup(s => s.GetServices(typeof(IExceptionLogger))) .Returns(expectedExceptionLoggers); ServicesContainer services = mock.Object; // Act IEnumerable <IExceptionLogger> exceptionLoggers = ServicesExtensions.GetExceptionLoggers( services ); // Assert mock.Verify(s => s.GetServices(typeof(IExceptionLogger)), Times.Once()); Assert.NotNull(exceptionLoggers); IExceptionLogger exceptionLogger = Assert.Single(exceptionLoggers); Assert.Same(expectedExceptionLogger, exceptionLogger); }
public void GetValueProviderFactories_Throws_WhenServicesIsNull() { // Arrange ServicesContainer services = null; // Act & Assert Assert.ThrowsArgumentNull(() => ServicesExtensions.GetValueProviderFactories(services), "services"); }
public void Configure(DryIoc.IContainer container) { container.Resolve <ILoggerFactory>() .AddConsole(Configuration.GetSection("Logging")) .AddDebug(); ServicesExtensions.InitializeJobs(container); }
private HttpContent ContentFor( HttpRequestMessage request, SwaggerDocument swaggerDoc) { ContentNegotiationResult negotiationResult = ServicesExtensions.GetContentNegotiator(HttpRequestMessageExtensions.GetConfiguration(request).get_Services()).Negotiate(typeof(SwaggerDocument), request, this.GetSupportedSwaggerFormatters()); return((HttpContent) new ObjectContent(typeof(SwaggerDocument), (object)swaggerDoc, negotiationResult.get_Formatter(), negotiationResult.get_MediaType())); }
public void GetExceptionHandler_DelegatesToGetService() { // Arrange IExceptionHandler expectedExceptionHandler = new Mock <IExceptionHandler>(MockBehavior.Strict).Object; Mock <ServicesContainer> mock = new Mock <ServicesContainer>(MockBehavior.Strict); mock.Setup(s => s.GetService(typeof(IExceptionHandler))).Returns(expectedExceptionHandler); ServicesContainer services = mock.Object; // Act IExceptionHandler exceptionHandler = ServicesExtensions.GetExceptionHandler(services); // Assert mock.Verify(s => s.GetService(typeof(IExceptionHandler)), Times.Once()); Assert.Same(expectedExceptionHandler, exceptionHandler); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, IMemoryCache cache, IContainer container) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseStaticFiles(); if (env.IsDevelopment()) { app.UseMiniProfiler(o => { o.RouteBasePath = "~/profiler"; o.SqlFormatter = new StackExchange.Profiling.SqlFormatters.InlineFormatter(); o.Storage = new MemoryCacheStorage(cache, TimeSpan.FromMinutes(20)); }); } app.UseAuthentication(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}"); }); // Enable middleware to serve generated Swagger as a JSON endpoint app.UseSwagger(); // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.) app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1"); c.InjectStylesheet("/lib/swagger-ui-themes/themes/2.x/theme-flattop.css"); }); if (_modeOptions.IsLocal) { ServicesExtensions.InitializeJobs(container); } }
internal ISwaggerProvider GetSwaggerProvider(HttpRequestMessage swaggerRequest) { HttpConfiguration configuration = HttpRequestMessageExtensions.GetConfiguration(swaggerRequest); Dictionary <string, SecurityScheme> dictionary = this._securitySchemeBuilders.Any <KeyValuePair <string, SecuritySchemeBuilder> >() ? this._securitySchemeBuilders.ToDictionary <KeyValuePair <string, SecuritySchemeBuilder>, string, SecurityScheme>((Func <KeyValuePair <string, SecuritySchemeBuilder>, string>)(kvp => kvp.Key), (Func <KeyValuePair <string, SecuritySchemeBuilder>, SecurityScheme>)(kvp => kvp.Value.Build())) : (Dictionary <string, SecurityScheme>)null; List <IModelFilter> list1 = this._modelFilters.Select <Func <IModelFilter>, IModelFilter>((Func <Func <IModelFilter>, IModelFilter>)(factory => factory())).ToList <IModelFilter>(); List <IOperationFilter> list2 = this._operationFilters.Select <Func <IOperationFilter>, IOperationFilter>((Func <Func <IOperationFilter>, IOperationFilter>)(factory => factory())).ToList <IOperationFilter>(); foreach (Func <XPathDocument> xmlDocFactory in (IEnumerable <Func <XPathDocument> >) this._xmlDocFactories) { XPathDocument xmlDoc = xmlDocFactory(); list1.Insert(0, (IModelFilter) new ApplyXmlTypeComments(xmlDoc)); list2.Insert(0, (IOperationFilter) new ApplyXmlActionComments(xmlDoc)); } SwaggerGeneratorOptions options = new SwaggerGeneratorOptions(this._versionSupportResolver, this._schemes, (IDictionary <string, SecurityScheme>)dictionary, this._ignoreObsoleteActions, this._groupingKeySelector, this._groupingKeyComparer, this._customSchemaMappings, (IEnumerable <ISchemaFilter>) this._schemaFilters.Select <Func <ISchemaFilter>, ISchemaFilter>((Func <Func <ISchemaFilter>, ISchemaFilter>)(factory => factory())).ToList <ISchemaFilter>(), (IEnumerable <IModelFilter>)list1, this._ignoreObsoleteProperties, this._schemaIdSelector, this._describeAllEnumsAsStrings, this._describeStringEnumsInCamelCase, this._applyFiltersToAllSchemas, (IEnumerable <IOperationFilter>)list2, (IEnumerable <IDocumentFilter>) this._documentFilters.Select <Func <IDocumentFilter>, IDocumentFilter>((Func <Func <IDocumentFilter>, IDocumentFilter>)(factory => factory())).ToList <IDocumentFilter>(), this._conflictingActionsResolver); SwaggerGenerator swaggerGenerator = new SwaggerGenerator(ServicesExtensions.GetApiExplorer(configuration.get_Services()), configuration.SerializerSettingsOrDefault(), this._versionInfoBuilder.Build(), options); if (this._customProviderFactory == null) { return((ISwaggerProvider)swaggerGenerator); } return(this._customProviderFactory((ISwaggerProvider)swaggerGenerator)); }