示例#1
0
        /// <summary>
        /// Adds the <see cref="HttPlaceholderClient"/> to the service collection.
        /// </summary>
        /// <param name="serviceCollection">The service collection the client should be added to.</param>
        /// <param name="configAction">An action to configure the client.</param>
        /// <returns>The <see cref="IServiceCollection"/>.</returns>
        public static IServiceCollection AddHttPlaceholderClient(
            this IServiceCollection serviceCollection,
            Action <HttPlaceholderClientConfiguration> configAction = null)
        {
            var config = new HttPlaceholderClientConfiguration();

            configAction?.Invoke(config);
            config.Validate();
            return(serviceCollection.RegisterHttpClient(config));
        }
示例#2
0
        /// <summary>
        /// Method for creating the <see cref="IHttPlaceholderClient"/>.
        /// </summary>
        /// <param name="config">The configuration of the client.</param>
        /// <returns>The <see cref="IHttPlaceholderClient"/>.</returns>
        public static IHttPlaceholderClient CreateHttPlaceholderClient(HttPlaceholderClientConfiguration config)
        {
            config.Validate();
            if (_httpClient == null)
            {
                _httpClient = new HttpClient();
                _httpClient.ApplyConfiguration(config);
            }

            return(new HttPlaceholderClient(_httpClient));
        }
示例#3
0
    public void Validate_RootUrlEmpty_ShouldThrowArgumentException()
    {
        // Arrange
        var config = new HttPlaceholderClientConfiguration {
            RootUrl = string.Empty
        };

        // Act
        var exception = Assert.ThrowsException <ArgumentException>(() => config.Validate());

        // Assert
        Assert.AreEqual("No value set for RootUrl in HttPlaceholder configuration.", exception.Message);
    }