// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services .AddMvc(options => options.EnableEndpointRouting = false) .SetCompatibilityVersion(CompatibilityVersion.Latest) .AddMvcOptions(options => { options.ModelBinderProviders.Insert(0, new FilterModelBinderProvider()); }); services.Configure <ApiSettings>(Configuration.GetSection("ApiSettings")); services.AddSingleton <ILog>(sp => new FileLog(sp.GetService <IOptions <ApiSettings> >().Value.FileLogSettings)); services.AddSingleton <IImageProcessService, ImageProcessService>(); services.AddSingleton <IFiltersFactory>(sp => { var factory = new FiltersFactory(); factory.RegisterFilter("threshold", new ThresholdFilter(sp.GetService <ILog>())); factory.RegisterFilter("sepia", new SepiaFilter()); factory.RegisterFilter("grayscale", new GrayscaleFilter()); return(factory); }); services.AddSingleton(sp => { var resolver = new FilterByRouteResolver(sp.GetService <IFiltersFactory>()); resolver.AddRouteValidator(@"(?<FilterName>threshold)\((?<params>[0-9]{1,3})\)"); resolver.AddRouteValidator(@"(?<FilterName>sepia)"); resolver.AddRouteValidator(@"(?<FilterName>grayscale)"); return(resolver); }); services.AddSingleton <IFilterByRouteResolver>(sp => sp.GetService <FilterByRouteResolver>()); services.AddSingleton <IParamsFromRouteExtractor>(sp => sp.GetService <FilterByRouteResolver>()); }
public void IsRegistered_ShouldReturn_True_WhenFilterIsRegistered() { _factory.RegisterFilter("grayscale", _mockFilter); _factory.IsRegistered("grayscale").Should().BeTrue(); }