Пример #1
0
    /// <summary>
    ///   <para>Initializes a caller object to perform web requests to RuLaw API.</para>
    /// </summary>
    /// <param name="configurator">Delegate to perform API setup process.</param>
    /// <exception cref="ArgumentNullException">If <paramref name="configurator"/> is a <c>null</c> reference.</exception>
    public static IApiCaller API(Action<IApiConfigurator> configurator)
    {
      Assertion.NotNull(configurator);

      var apiConfigurator = new ApiConfigurator();
      configurator(apiConfigurator);

      if (apiConfigurator.GetApiKey().IsEmpty())
      {
        throw new InvalidOperationException("API Key was not specified when configuring API caller");
      }

      return new ApiCaller(apiConfigurator.GetFormat(), apiConfigurator.GetApiKey(), apiConfigurator.GetAppKey());
    }
 public void Constructors()
 {
   var configurator = new ApiConfigurator();
   Assert.Equal(ApiDataFormat.Json, configurator.GetFormat());
   Assert.Null(configurator.GetApiKey());
   Assert.Null(configurator.GetAppKey());
 }
    public void ApiKey_Method()
    {
      Assert.Throws<ArgumentNullException>(() => new ApiConfigurator().ApiKey(null));
      Assert.Throws<ArgumentException>(() => new ApiConfigurator().ApiKey(string.Empty));

      var configurator = new ApiConfigurator();
      Assert.True(ReferenceEquals(configurator.ApiKey("apiKey"), configurator));
      Assert.Equal("apiKey", configurator.GetApiKey());
    }