public MakeManagerTest() { _contextAccessor = new Mock <IHttpContextAccessor>(); var context = new DefaultHttpContext(); var token = TokenProvider.Instance.GetToken(Guid.NewGuid().ToString()); context.Request.Headers["Token"] = token; _contextAccessor.Setup(x => x.HttpContext).Returns(context); var mapperConfig = MapperConfig.CreateMapperConfig(); _makeManager = new MakeManager(mapperConfig.CreateMapper(), _contextAccessor.Object); _modelManager = new ModelManager(mapperConfig.CreateMapper(), _contextAccessor.Object); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(); services.AddMvc(c => { c.Filters.Add(new ApiExceptionFilter()); c.Filters.Add(new AuthFilter()); }).SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSwaggerGen(c => { c.SwaggerDoc(_apiVersion, new Info { Title = "Car Dealers API", Version = _apiVersion }); c.AddSecurityDefinition("custom", new ApiKeyScheme() { In = "header", Name = "Token", Type = "apiKey" }); c.AddSecurityRequirement(new Dictionary <string, IEnumerable <string> > { { "custom", Enumerable.Empty <string>() } }); }); services.AddHttpContextAccessor(); services.AddSingleton <IMakeManager, MakeManager>(); services.AddSingleton <IDealerManager, DealerManager>(); services.AddSingleton <IModelManager, ModelManager>(); services.AddSingleton <ICarManager, CarManager>(); services.AddSingleton <IFileManager, FileManager>(); var mapperConfig = MapperConfig.CreateMapperConfig(); services.AddSingleton(mapperConfig.CreateMapper()); #if DEBUG services.AddTransient <Seed>(); #endif }