Esempio n. 1
0
        public IServiceProvider ConfigureServices(IServiceCollection services)
        {
            // MVC
            services.AddMvc(
                options => options.Filters.Add(new CorsAuthorizationFilterFactory(_defaultCorsPolicyName))
                );

            IdentityRegistrar.Register(services);
            AuthConfigurer.Configure(services, _appConfiguration);

            HttpClientRegistrar.Register(services);
            //services.AddSignalR();

            // Configure CORS for angular2 UI
            services.AddCors(
                options => options.AddPolicy(
                    _defaultCorsPolicyName,
                    builder => builder
                    .WithOrigins(
                        // App:CorsOrigins in appsettings.json can contain more than one address separated by comma.
                        _appConfiguration["App:CorsOrigins"]
                        .Split(",", StringSplitOptions.RemoveEmptyEntries)
                        .Select(o => o.RemovePostFix("/"))
                        .ToArray()
                        )
                    .AllowAnyHeader()
                    .AllowAnyMethod()
                    .AllowCredentials()
                    )
                );

            // Swagger - Enable this line and the related lines in Configure method to enable swagger UI
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new Info {
                    Title = "TripMaker API", Version = "v1"
                });
                options.DocInclusionPredicate((docName, description) => true);

                // Define the BearerAuth scheme that's in use
                options.AddSecurityDefinition("bearerAuth", new ApiKeyScheme()
                {
                    Description = "JWT Authorization header using the Bearer scheme. Example: \"Authorization: Bearer {token}\"",
                    Name        = "Authorization",
                    In          = "header",
                    Type        = "apiKey"
                });
                // Assign scope requirements to operations based on AuthorizeAttribute
                options.OperationFilter <SecurityRequirementsOperationFilter>();
            });

            // Configure Abp and Dependency Injection
            return(services.AddAbp <TripMakerWebHostModule>(
                       // Configure Log4Net logging
                       options => options.IocManager.IocContainer.AddFacility <LoggingFacility>(
                           f => f.UseAbpLog4Net().WithConfig("log4net.config")
                           )
                       ));
        }
Esempio n. 2
0
        public void ShouldRegisterUrlWithTRailedSlash(string url, string expected)
        {
            //Arrange
            var srvColl = new ServiceCollection();

            HttpClientRegistrar.Register(srvColl, new ApiClientsOptions
            {
                List = new Dictionary <string, ApiConnectionOptions>
                {
                    { "key", new ApiConnectionOptions {
                          Url = url
                      } }
                }
            });

            var srvProvider       = srvColl.BuildServiceProvider();
            var httpClientFactory = srvProvider.GetService <IHttpClientFactory>();

            //Act
            var httpClient = httpClientFactory.CreateClient("key");

            //Assert
            Assert.Equal(expected, httpClient.BaseAddress.AbsoluteUri);
        }