コード例 #1
0
    public void Can_use_custom_composer_FredClient()
    {
        IVintageComposer   composerMock = new Mock <IVintageComposer>().Object;
        string             apiKey       = "secret";
        IServiceCollection container    = new ServiceCollection();

        container.AddLogging(builder => builder.AddSerilog());
        container.AddFredClient().UseAPIKey(apiKey).UseVintageComposer(x => composerMock);
        IServiceProvider services   = container.BuildServiceProvider();
        IFredClient      fredClient = services.GetService <IFredClient>();

        Assert.IsTrue(fredClient is JsonFredClient);
        Func <IServiceProvider, IVintageComposer> composerFactory = services.GetService <Func <IServiceProvider, IVintageComposer> >();
        IVintageComposer composer = composerFactory(services);

        Assert.IsTrue(composer.GetType().FullName == "Castle.Proxies.IVintageComposerProxy");
    }
コード例 #2
0
    public BaseFredClient(string apiKey, FredClientConfig config, IVintageComposer composer, HttpClient httpClient, ILogger <IFredClient> logger)
    {
        API_key         = "api_key=" + apiKey ?? throw new ArgumentNullException($"{nameof(apiKey)} can not be null.  Call UseAPIKey() when calling the FredClient service registration.  For example:  .AddFredClient().UseAPIKey(\"your API key here\") ");
        this.config     = config ?? throw new ArgumentNullException(nameof(config));
        this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
        this.composer   = composer ?? throw new ArgumentNullException(nameof(composer));

        if (httpClient.BaseAddress is null)
        {
            throw new Exception($"{nameof(httpClient)} BaseAddress must be set.  The default value is {FredClientConfig.BaseAPIURL}");
        }

        if (!httpClient.BaseAddress.OriginalString.EndsWith("/"))
        {
            httpClient.BaseAddress = new Uri(httpClient.BaseAddress.ToString() + "/");
        }

        Logger = logger ?? throw new ArgumentNullException(nameof(logger));
        concurrentRequestThrottle = new SemaphoreSlim(config.MaxConcurrentDownloads, config.MaxConcurrentDownloads);
        batchThrottle             = new BatchThrottleAsync(120, 60000); // block when we reach the per-minute request limit.
    }
コード例 #3
0
 public XMLFredClient(string apiKey, FredClientConfig config, IVintageComposer composer, HttpClient httpClient, ILogger <IFredClient> logger) : base(apiKey, config, composer, httpClient, logger)
 {
 }