コード例 #1
0
 public void Constructors()
 {
   var configurator = new ApiConfigurator();
   Assert.Equal(ApiDataFormat.Json, configurator.GetFormat());
   Assert.Null(configurator.GetApiKey());
   Assert.Null(configurator.GetAppKey());
 }
コード例 #2
0
    public void AppKey_Method()
    {
      Assert.Throws<ArgumentNullException>(() => new ApiConfigurator().AppKey(null));
      Assert.Throws<ArgumentException>(() => new ApiConfigurator().AppKey(string.Empty));

      var configurator = new ApiConfigurator();
      Assert.True(ReferenceEquals(configurator.AppKey("appKey"), configurator));
      Assert.Equal("appKey", configurator.GetAppKey());
    }
コード例 #3
0
ファイル: RuLaw.cs プロジェクト: prokhor-ozornin/RuLaw.NET
    /// <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());
    }