public static ServiceCollection GetServiceCollectionWithContextAccessor() { var services = new ServiceCollection(); IHttpContextAccessor contextAccessor = new HttpContextAccessor(); services.AddInstance<IHttpContextAccessor>(contextAccessor); services.AddInstance<DiagnosticListener>(new DiagnosticListener("TestListener")); return services; }
public static ServiceCollection GetServiceCollectionWithContextAccessor() { var services = new ServiceCollection(); IHttpContextAccessor contextAccessor = new HttpContextAccessor(); services.AddInstance<IHttpContextAccessor>(contextAccessor); services.AddInstance<INotifier>(new Notifier(new ProxyNotifierMethodAdapter())); return services; }
public void InitializeDoesNotThrowIfRequestTelemetryIsUnavailable() { var ac = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() }; var initializer = new DomainNameRoleInstanceTelemetryInitializer(ac); initializer.Initialize(new RequestTelemetry()); }
public void CreateHttpContextSetsHttpContextAccessor() { // Arrange var accessor = new HttpContextAccessor(); var contextFactory = new HttpContextFactory(accessor); // Act var context = contextFactory.Create(new FeatureCollection()); // Assert Assert.True(ReferenceEquals(context, accessor.HttpContext)); }
public static IdentityServerContext Create(HttpContext context = null, IdentityServerOptions options = null) { var accessor = new HttpContextAccessor(); accessor.HttpContext = context ?? new DefaultHttpContext(); return new IdentityServerContext(accessor, options ?? new IdentityServerOptions()); }
public static TokenValidator CreateTokenValidator(ITokenHandleStore tokenStore = null, IProfileService profile = null) { if (profile == null) { profile = new TestProfileService(); } var clients = CreateClientStore(); var options = TestIdentityServerOptions.Create(); var accessor = new HttpContextAccessor(); accessor.HttpContext = new DefaultHttpContext(); var idsrvContext = new IdentityServerContext(accessor, options); var logger = new Logger<TokenValidator>(new LoggerFactory()); var validator = new TokenValidator( options: options, clients: clients, tokenHandles: tokenStore, customValidator: new DefaultCustomTokenValidator( profile: profile, clients: clients, logger: new Logger<DefaultCustomTokenValidator>(new LoggerFactory())), keyService: new DefaultSigningKeyService(options), logger: logger, context: idsrvContext); return validator; }
private IServiceCollection CreateServices(object diagnosticListener, HttpContext context, params ViewComponentDescriptor[] descriptors) { var httpContext = new HttpContextAccessor() { HttpContext = context }; var tempDataProvider = new SessionStateTempDataProvider(); var diagnosticSource = new DiagnosticListener("Microsoft.AspNet"); if (diagnosticListener != null) { diagnosticSource.SubscribeWithAdapter(diagnosticListener); } var services = new ServiceCollection(); services.AddInstance<DiagnosticSource>(diagnosticSource); services.AddSingleton<IOptions<MvcViewOptions>, TestOptionsManager<MvcViewOptions>>(); services.AddTransient<IViewComponentHelper, DefaultViewComponentHelper>(); services.AddSingleton<IViewComponentSelector, DefaultViewComponentSelector>(); services.AddSingleton<IViewComponentDescriptorCollectionProvider, DefaultViewComponentDescriptorCollectionProvider>(); services.AddSingleton<IViewComponentInvokerFactory, DefaultViewComponentInvokerFactory>(); services.AddSingleton<ITypeActivatorCache, DefaultTypeActivatorCache>(); services.AddSingleton<IViewComponentActivator, DefaultViewComponentActivator>(); services.AddInstance<IViewComponentDescriptorProvider>(new FixedSetViewComponentDescriptorProvider(descriptors)); services.AddSingleton<IModelMetadataProvider, EmptyModelMetadataProvider>(); services.AddInstance<ILoggerFactory>(NullLoggerFactory.Instance); services.AddInstance<ITempDataDictionary>(new TempDataDictionary(httpContext, tempDataProvider)); services.AddTransient<IHttpContextAccessor, HttpContextAccessor>(); return services; }
private static IServiceProvider GetServiceProvider() { var httpContext = new HttpContextAccessor() { HttpContext = new DefaultHttpContext() }; var serviceCollection = new ServiceCollection(); serviceCollection.AddInstance<IModelMetadataProvider>(new EmptyModelMetadataProvider()); var tempDataProvider = new SessionStateTempDataProvider(); serviceCollection.AddInstance<ITempDataDictionary>(new TempDataDictionary(httpContext, tempDataProvider)); return serviceCollection.BuildServiceProvider(); }