コード例 #1
0
        public void Format_Method()
        {
            var configurator = new ApiConfigurator();

            Assert.True(ReferenceEquals(configurator.Format(ApiDataFormat.Xml), configurator));
            Assert.Equal(ApiDataFormat.Xml, configurator.GetFormat());
        }
コード例 #2
0
        public void Constructors()
        {
            var configurator = new ApiConfigurator();

            Assert.Equal(ApiDataFormat.Json, configurator.GetFormat());
            Assert.Null(configurator.GetApiKey());
        }
コード例 #3
0
    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());
    }
コード例 #4
0
        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());
        }
コード例 #5
0
    /// <summary>
    ///   <para>Configures instance of client translator to be used for making requests to Yandex.Translator web service.</para>
    /// </summary>
    /// <param name="configurator">Delegate that generic translator's parameters and options to use.</param>
    /// <exception cref="ArgumentNullException">If <paramref name="configurator"/> is a <c>null</c> reference.</exception>
    /// <exception cref="ArgumentException">If <paramref name="configurator"/> is <see cref="string.Empty"/> string.</exception>
    public static IYandexTranslator Translator(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 Yandex Translator");
      }

      return new YandexTranslator(apiConfigurator.GetFormat(), apiConfigurator.GetApiKey());
    }
コード例 #6
0
        /// <summary>
        ///   <para>Configures instance of client translator to be used for making requests to Yandex.Translator web service.</para>
        /// </summary>
        /// <param name="configurator">Delegate that generic translator's parameters and options to use.</param>
        /// <exception cref="ArgumentNullException">If <paramref name="configurator"/> is a <c>null</c> reference.</exception>
        /// <exception cref="ArgumentException">If <paramref name="configurator"/> is <see cref="string.Empty"/> string.</exception>
        public static IYandexTranslator Translator(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 Yandex Translator");
            }

            return(new YandexTranslator(apiConfigurator.GetFormat(), apiConfigurator.GetApiKey()));
        }
コード例 #7
0
 public void Format_Method()
 {
   var configurator = new ApiConfigurator();
   Assert.True(ReferenceEquals(configurator.Format(ApiDataFormat.Xml), configurator));
   Assert.Equal(ApiDataFormat.Xml, configurator.GetFormat());
 }
コード例 #8
0
 public void Constructors()
 {
   var configurator = new ApiConfigurator();
   Assert.Equal(ApiDataFormat.Json, configurator.GetFormat());
   Assert.Null(configurator.GetApiKey());
 }