Example #1
0
 /// <summary>Initializes a new instance of the <see cref="BingMapsClient"/> class.</summary>
 public BingMapsClient(
     IHttpClientFactory clientFactory,
     BingMapsOptions options)
 {
     _clientFactory = clientFactory;
     _options       = options;
 }
Example #2
0
        public async Task BingMapsClientWouldCallApi()
        {
            var handler = new MockHttpMessageHandler()
                          .Set("{\"resourceSets\": [{\"resources\": [{\"timeZoneAtLocation\": [{\"timeZone\": [{\"genericName\": \"FLE Standard Time\"}]}]}]}]}", "application/json");

            var httpClient = new HttpClient(handler);
            var options    = new BingMapsOptions("K");
            var factory    = Substitute.For <IHttpClientFactory>();
            var client     = new BingMapsClient(factory, options);

            factory.CreateClient("BingMapsClient").Returns(httpClient);

            var result = await client.QueryAsync("Varna");

            Assert.AreEqual("FLE Standard Time", result.GenericName);
        }
Example #3
0
        private static IServiceProvider BuildServiceProvider()
        {
            IConfigurationRoot config = new ConfigurationBuilder()
                                        .SetBasePath(Directory.GetCurrentDirectory())
                                        .AddJsonFile("appsettings.json")
                                        .AddUserSecrets <Program>(optional: true)
                                        .Build();

            BingMapsOptions bingOptions = config.GetSection("MagicMedia:BingMaps")
                                          .Get <BingMapsOptions>();

            var services = new ServiceCollection();

            services.AddMongoDbStore(config);

            services.AddFileSystemStore(config);
            services.AddCoreMediaServices(config);
            //services.AddBingMaps(bingOptions);

            services.AddDataSeaders();

            return(services.BuildServiceProvider());
        }
Example #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews()
            .AddRazorRuntimeCompilation();

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardedHeaders =
                    ForwardedHeaders.XForwardedFor |
                    ForwardedHeaders.XForwardedProto;
            });

            JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Clear();

            services.AddAuthentication(options =>
            {
                options.DefaultScheme          = CookieAuthenticationDefaults.AuthenticationScheme;
                options.DefaultChallengeScheme = "oidc";
            })
            .AddCookie(options =>
            {
                options.ExpireTimeSpan = TimeSpan.FromMinutes(60);
                options.Cookie.Name    = "media-sample";
            })
            .AddOpenIdConnect("oidc", options =>
            {
                options.Authority            = "http://localhost:5500";
                options.RequireHttpsMetadata = false;

                options.ClientSecret = "geCDNACu94a5DfZQ2Sm46DBjkSErAnNA";
                options.ClientId     = "Media.UI";
                options.ResponseType = "code";

                options.Scope.Clear();
                options.Scope.Add("openid");
                options.Scope.Add("profile");

                options.ClaimActions.MapAllExcept("iss", "nbf", "exp", "aud", "nonce", "iat", "c_hash");

                options.SaveTokens = true;
                options.Events     = new OpenIdConnectEvents
                {
                    OnRedirectToIdentityProvider = (ctx) =>
                    {
                        return(Task.CompletedTask);
                    },
                    OnTicketReceived = (ctx) =>
                    {
                        return(Task.CompletedTask);
                    }
                };

                options.TokenValidationParameters = new TokenValidationParameters
                {
                    NameClaimType = JwtClaimTypes.Name,
                    RoleClaimType = JwtClaimTypes.Role,
                };
            });

            services.Configure <CookiePolicyOptions>(options =>
            {
                options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
                options.OnAppendCookie        = cookieContext =>
                                                CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
                options.OnDeleteCookie = cookieContext =>
                                         CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
            });

            services.AddCoreMediaServices(Configuration);
            services.AddFaceDetection(Configuration);
            BingMapsOptions bingOptions = Configuration.GetSection("MagicMedia:BingMaps")
                                          .Get <BingMapsOptions>();

            services.AddFileSystemStore(Configuration);

            //services.AddBingMaps(bingOptions);

            services.AddMongoDbStore(Configuration);

            services.AddSingleton <SampleService>();
        }