protected BaseFixture() { var serviceCollection = new ServiceCollection(); //mock the hosting env var hostingEnvironment = new Mock <IHostingEnvironment>(); hostingEnvironment.Setup(x => x.ApplicationName) .Returns("Hosting:UnitTestEnvironment"); hostingEnvironment.Setup(x => x.EnvironmentName) .Returns(ApplicationConfig.TestEnvironmentName); hostingEnvironment.Setup(x => x.ContentRootPath) .Returns(AppDomain.CurrentDomain.BaseDirectory); hostingEnvironment.Setup(x => x.ContentRootFileProvider) .Returns(new LocalFileProvider(hostingEnvironment.Object)); //mock httpcontext var httpContextAccessor = new Mock <IHttpContextAccessor>(); var httpContext = new DefaultHttpContext(); httpContextAccessor.Setup(accessor => accessor.HttpContext).Returns(httpContext); serviceCollection.AddSingleton <IHostingEnvironment>(provider => hostingEnvironment.Object); serviceCollection.AddSingleton <IHttpContextAccessor>(provider => httpContextAccessor.Object); serviceCollection.AddSingleton <IConfiguration>(new TestConfiguration()); serviceCollection.AddSingleton <IDatabaseSettings>(new TestDbInit.TestDatabaseSettings()); ApplicationEngine.ConfigureServices(serviceCollection, hostingEnvironment.Object); }
public IServiceProvider ConfigureServices(IServiceCollection services) { //swagger services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "EvenCart Api Documentation", Version = ApplicationConfig.ApiVersion }); c.CustomSchemaIds(x => x.FullName); c.ResolveConflictingActions(x => x.First()); if (File.Exists($"../Documentation/{ApplicationConfig.ApiVersion}/XmlComments.xml")) { c.IncludeXmlComments($"../Documentation/{ApplicationConfig.ApiVersion}/XmlComments.xml", true); c.IncludeXmlComments($"../Documentation/{ApplicationConfig.ApiVersion}/XmlComments.Infrastructure.xml", true); c.IncludeXmlComments($"../Documentation/{ApplicationConfig.ApiVersion}/XmlComments.Data.xml", true); } c.SwaggerGeneratorOptions.DocInclusionPredicate = (s, description) => description.ActionDescriptor.AttributeRouteInfo?.Name?.StartsWith("api_") ?? false; c.ParameterFilter <SwaggerCommonFilter>(); c.DocumentFilter <SwaggerCommonFilter>(); c.OperationFilter <SwaggerCommonFilter>(); c.SchemaFilter <SwaggerCommonFilter>(); }); return(ApplicationEngine.ConfigureServices(services, _hostingEnvironment)); }