public void ConstructorDefaultTest() { var request = new LanguagesRequest(); Assert.IsTrue(request.IsSsl); Assert.IsNull(request.Target); Assert.AreEqual(Model.Base, request.Model); }
public void GetQueryStringParametersTest() { var request = new LanguagesRequest { Key = "abc", Target = Language.Afrikaans }; Assert.DoesNotThrow(() => request.GetQueryStringParameters()); }
public void LanguagesWhenTargetIsNullTest() { var request = new LanguagesRequest { Key = this.ApiKey, Target = null }; var exception = Assert.Throws <ArgumentException>(() => GoogleTranslate.Languages.Query(request)); Assert.AreEqual(exception.Message, "Target is required"); }
public void LanguagesWhenKeyIsStringEmptyTest() { var request = new LanguagesRequest { Key = string.Empty, Target = Language.English }; var exception = Assert.Throws <ArgumentException>(() => GoogleTranslate.Languages.Query(request)); Assert.AreEqual(exception.Message, "Key is required"); }
public void LanguagesWhenAsyncTest() { var request = new LanguagesRequest { Key = this.ApiKey, Target = Language.English }; var result = GoogleTranslate.Languages.QueryAsync(request).Result; Assert.IsNotNull(result); Assert.AreEqual(Status.Ok, result.Status); }
public void GetUriTest() { var request = new LanguagesRequest { Key = "abc", Target = Language.Afrikaans }; var uri = request.GetUri(); Assert.IsNotNull(uri); Assert.AreEqual($"/language/translate/v2/languages?key={request.Key}&target={request.Target.GetValueOrDefault().ToCode()}&model={request.Model.ToString().ToLower()}", uri.PathAndQuery); }
/// <summary> /// Gets the languages asynchronous. /// </summary> /// <param name="search">The search.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>IEnumerable<ILanguage>.</returns> public async Task <IEnumerable <ILanguage> > GetLanguagesAsync(string search, CancellationToken cancellationToken) { var request = new LanguagesRequest { Key = _apiKey }; if (!string.IsNullOrWhiteSpace(search)) { request.Search = search; } var response = await Execute <LanguagesRequest, LanguagesResponse>(request, cancellationToken).ConfigureAwait(false); return(response.Languages); }
public void GetQueryStringParametersWhenKeyIsStringEmptyTest() { var request = new LanguagesRequest { Key = string.Empty }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.AreEqual(exception.Message, "'Key' is required"); }
public void GetQueryStringParametersWhenTargetIsNullTest() { var request = new LanguagesRequest { Key = this.ApiKey, Target = null }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.AreEqual(exception.Message, "Target is required"); }
public void GetQueryStringParametersWhenKeyIsNullTest() { var request = new LanguagesRequest { Key = null, Target = Language.Afrikaans }; var exception = Assert.Throws <ArgumentException>(() => { var parameters = request.GetQueryStringParameters(); Assert.IsNull(parameters); }); Assert.AreEqual(exception.Message, "Key is required"); }
public void GetQueryStringParametersTest() { var request = new LanguagesRequest { Key = "key" }; var queryStringParameters = request.GetQueryStringParameters(); Assert.IsNotNull(queryStringParameters); var key = queryStringParameters.FirstOrDefault(x => x.Key == "key"); var keyExpected = request.Key; Assert.IsNotNull(key); Assert.AreEqual(keyExpected, key.Value); }
public void LanguagesTest() { var request = new LanguagesRequest { Key = this.ApiKey }; var result = GoogleTranslate.Languages.Query(request); Assert.IsNotNull(result); Assert.AreEqual(Status.Ok, result.Status); var languages = result.Data.Languages; Assert.IsNotNull(languages); Assert.AreEqual(111, languages.Count()); }
public void LanguagesWhenAsyncAndCancelledTest() { var request = new LanguagesRequest { Key = this.ApiKey, Target = Language.English }; var cancellationTokenSource = new CancellationTokenSource(); var task = GoogleTranslate.Languages.QueryAsync(request, cancellationTokenSource.Token); cancellationTokenSource.Cancel(); var exception = Assert.Throws <OperationCanceledException>(() => task.Wait(cancellationTokenSource.Token)); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "The operation was canceled."); }
public void LanguagesWhenTargetIsNullTest() { var request = new LanguagesRequest { Key = this.ApiKey, Target = null }; var exception = Assert.Throws <AggregateException>(() => GoogleTranslate.Languages.QueryAsync(request).Wait()); Assert.IsNotNull(exception); var innerException = exception.InnerException; Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException), innerException.GetType()); Assert.AreEqual(innerException.Message, "Target is required"); }
public void LanguagesWhenKeyIsStringEmptyTest() { var request = new LanguagesRequest { Key = string.Empty, Target = Language.English }; var exception = Assert.Throws <AggregateException>(() => GoogleTranslate.Languages.QueryAsync(request).Wait()); Assert.IsNotNull(exception); var innerException = exception.InnerException; Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException), innerException.GetType()); Assert.AreEqual(innerException.Message, "Key is required"); }
public void LanguagesWhenInvalidKeyTest() { var request = new LanguagesRequest { Key = "test", Target = Language.Danish }; var exception = Assert.Throws <AggregateException>(() => GoogleTranslate.Languages.QueryAsync(request).Wait()); Assert.IsNotNull(exception); var innerException = exception.InnerExceptions.FirstOrDefault(); Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException).ToString(), innerException.GetType().ToString()); Assert.AreEqual("Response status code does not indicate success: 400 (Bad Request).", innerException.Message); }
public LanguagesResponse Languages([FromUri] LanguagesRequest request) { var languages = _brandQueries.GetCulturesByBrand(request.BrandId); if (languages == null) { throw new RegoException("Languages are missing for this brand."); } return(new LanguagesResponse { Languages = languages.Select(c => new Language { Culture = c.Code, NativeName = c.NativeName }).ToList() }); }
public void LanguagesWhenKeyIsNullTest() { var request = new LanguagesRequest { Key = null, Target = Language.English }; var exception = Assert.Throws <AggregateException>(() => GoogleTranslate.Languages.Query(request)); Assert.IsNotNull(exception); Assert.AreEqual("One or more errors occurred.", exception.Message); var innerException = exception.InnerException; Assert.IsNotNull(innerException); Assert.AreEqual(typeof(GoogleApiException), innerException.GetType()); Assert.AreEqual(innerException.Message, "Key is required"); }
public void LanguagesWhenAsyncAndTimeoutTest() { var request = new LanguagesRequest { Key = this.ApiKey, Target = Language.English }; var exception = Assert.Throws <AggregateException>(() => { var result = GoogleTranslate.Languages.QueryAsync(request, TimeSpan.FromMilliseconds(1)).Result; Assert.IsNull(result); }); Assert.IsNotNull(exception); Assert.AreEqual(exception.Message, "One or more errors occurred."); var innerException = exception.InnerException; Assert.IsNotNull(innerException); Assert.AreEqual(innerException.GetType(), typeof(TaskCanceledException)); Assert.AreEqual(innerException.Message, "A task was canceled."); }
public void LanguagesWhenAsyncTest() { var request = new LanguagesRequest { Key = this.ApiKey, Target = Language.English }; var result = GoogleTranslate.Languages.QueryAsync(request).Result; Assert.IsNotNull(result); Assert.AreEqual(Status.Ok, result.Status); var languages = result.Data.Languages; Assert.IsNotNull(languages); Assert.AreEqual(104, languages.Count()); var language = result.Data.Languages.FirstOrDefault(); Assert.IsNotNull(language); Assert.AreEqual("Afrikaans", language.Name); Assert.AreEqual(Language.Afrikaans, language.Language); }
public void GetQueryStringParametersWhenTargetTest() { var request = new LanguagesRequest { Key = "key", Target = Language.Afrikaans }; var queryStringParameters = request.GetQueryStringParameters(); Assert.IsNotNull(queryStringParameters); var key = queryStringParameters.FirstOrDefault(x => x.Key == "key"); var keyExpected = request.Key; Assert.IsNotNull(key); Assert.AreEqual(keyExpected, key.Value); var target = queryStringParameters.FirstOrDefault(x => x.Key == "target"); var targetExpected = request.Target.GetValueOrDefault().ToCode(); Assert.IsNotNull(target); Assert.AreEqual(targetExpected, target.Value); }