示例#1
0
        public void ConstructorDefaultTest()
        {
            var request = new LanguagesRequest();

            Assert.IsTrue(request.IsSsl);
            Assert.IsNull(request.Target);
            Assert.AreEqual(Model.Base, request.Model);
        }
示例#2
0
        public void GetQueryStringParametersTest()
        {
            var request = new LanguagesRequest
            {
                Key    = "abc",
                Target = Language.Afrikaans
            };

            Assert.DoesNotThrow(() => request.GetQueryStringParameters());
        }
示例#3
0
        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");
        }
示例#4
0
        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");
        }
示例#5
0
        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);
        }
示例#6
0
        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);
        }
示例#7
0
        /// <summary>
        /// Gets the languages asynchronous.
        /// </summary>
        /// <param name="search">The search.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>IEnumerable&lt;ILanguage&gt;.</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");
        }
示例#9
0
        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");
        }
示例#10
0
        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);
        }
示例#12
0
        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());
        }
示例#13
0
        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.");
        }
示例#14
0
        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");
        }
示例#15
0
        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");
        }
示例#16
0
        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);
        }
示例#17
0
        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()
            });
        }
示例#18
0
        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");
        }
示例#19
0
        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.");
        }
示例#20
0
        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);
        }