public static IServiceCollection AddHubSpotClient(this IServiceCollection services, Action <IHubSpotClientConfigurator> configuration = null)
        {
            _ = services ?? throw new ArgumentNullException(nameof(services));

            var configurator = new HubSpotClientConfigurator();

            configuration?.Invoke(configurator);

            services.AddHttpRestClient(HttpClientConfigurationName, builder =>
            {
                builder.ConfigureHttpClient(http =>
                {
                    http.BaseAddress = HttpHubSpotClient.DefaultApiEndpoint;
                });

                builder.ConfigureSerialization(HttpHubSpotClient.ConfigureJsonSerializer);

                configurator.ApplyHttpClientBuilderConfigurations(builder);
            });

            configurator.ApplyServiceConfigurations(services);

            services.AddTransient <IHubSpotClient, HttpHubSpotClient>();

            return(services);
        }
예제 #2
0
        public void Registered_httpClientBuilder_actions_are_applied(HubSpotClientConfigurator sut, Action <IHttpClientBuilder> action, IHttpClientBuilder builder)
        {
            sut.AddHttpClientBuilderConfiguration(action);

            sut.ApplyHttpClientBuilderConfigurations(builder);

            Mock.Get(action).Verify(p => p(builder));
        }
예제 #3
0
        public void Registered_service_actions_are_applied(HubSpotClientConfigurator sut, Action <IServiceCollection> action, ServiceCollection services)
        {
            sut.AddServiceConfiguration(action);

            sut.ApplyServiceConfigurations(services);

            Mock.Get(action).Verify(p => p(services));
        }
        public void UseOAuthAuthentication_registers_needed_services(HubSpotClientConfigurator configurator, OAuthOptions apiKeyOptions, ServiceCollection services)
        {
            var configurationBuilder = new ConfigurationBuilder();

            configurationBuilder.AddObject(apiKeyOptions);

            var configuration = configurationBuilder.Build();

            configurator.UseOAuthAuthentication(configuration);

            configurator.ApplyServiceConfigurations(services);

            var serviceProvider = services.BuildServiceProvider();

            Assert.Multiple(() =>
            {
                Assert.That(() => serviceProvider.GetRequiredService <IOptions <OAuthOptions> >(), Throws.Nothing);

                Assert.That(() => serviceProvider.GetRequiredService <OAuthHubSpotAuthenticator>(), Throws.Nothing);
            });
        }