public void Format_Method() { var configurator = new ApiConfigurator(); Assert.True(ReferenceEquals(configurator.Format(ApiDataFormat.Xml), configurator)); Assert.Equal(ApiDataFormat.Xml, configurator.GetFormat()); }
public void Constructors() { var configurator = new ApiConfigurator(); Assert.Equal(ApiDataFormat.Json, configurator.GetFormat()); Assert.Null(configurator.GetApiKey()); }
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()); }
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()); }
/// <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()); }
/// <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())); }