/// <summary> /// Asyncronous method that validate the source parameter /// </summary> /// <param name="parameters"></param> /// <returns>Returns a dictionary populated with the source parameter</returns> public static List <KeyValuePair <string, string> > verifySingleSource(WikisearchParameters parameters) { if (String.IsNullOrEmpty(parameters.Text)) { throw new ArgumentException(ErrorMessages.WrongText, ErrorMessages.Text); } var source = new List <KeyValuePair <string, string> >(); source.Add(new KeyValuePair <string, string>("text", $"{parameters.Text}")); return(source); }
public void Should_ThrowException_When_CallWikisearchWithWrongTextSource(string Text) { //Arrange var parameters = new WikisearchParameters { Token = "Token", Text = Text }; //Act & Assert ArgumentException ex = Assert.Throws <ArgumentException>(() => SourceValidationService.verifySingleSource(parameters)); Assert.Equal($"{ErrorMessages.WrongText}{Environment.NewLine}Parameter name: {ErrorMessages.Text}", ex.Message); }
/// <summary> /// Asyncronous method that validate the user parameters and call <c>ApiClient</c> /// </summary> /// <param name="parameters"></param> /// <returns>Returns a <c>WikisearchDto</c> populated with the result of the call </returns> /// <seealso cref="WikisearchDto"/> public Task <WikisearchDto> CallWikisearchAsync(WikisearchParameters parameters) { ServiceUtils.ParameterValidation(parameters); if (parameters.Include != null) { if (parameters.Include.FindAll(x => x == IncludeOption.score_details).ToList().Count > 0) { throw new ArgumentException(ErrorMessages.WrongInclude1, ErrorMessages.Include); } } if (parameters.Lang == LanguageOption.auto) { throw new ArgumentException(ErrorMessages.WrongLang2, ErrorMessages.Lang); } if (parameters.Limit < 1 || parameters.Limit > 50) { throw new ArgumentException(ErrorMessages.WrongLimit, ErrorMessages.Limit); } var source = SourceValidationService.verifySingleSource(parameters); return(_apiClient.CallApiAsync <WikisearchDto>(ApiClient.WikisearchUriBuilder(), ApiClient.WikisearchContentBuilder(source, parameters), parameters.HttpMethod)); }
public async void Should_ThrowException_When_CallWikisearchWithWrongParameters(WikisearchParameters parameters, string message, string wrongParameter) { //Act & Assert ArgumentException ex = await Assert.ThrowsAsync <ArgumentException>(() => _wikisearchtextClassificationService.CallWikisearchAsync(parameters)); if (String.IsNullOrEmpty(wrongParameter)) { Assert.Equal(message, ex.Message); } else { Assert.Equal($"{message}{Environment.NewLine}Parameter name: {wrongParameter}", ex.Message); } }
/// <summary> /// Allocates a dictionary that contains the parameters for the call /// </summary> /// <param name="source"> a dictionary that contains the text source</param> /// <param name="parameters"></param> /// <returns>Returns the dictionary </returns> public static List <KeyValuePair <string, string> > WikisearchContentBuilder(List <KeyValuePair <string, string> > source, WikisearchParameters parameters) { var content = new List <KeyValuePair <string, string> >(); content.Add(new KeyValuePair <string, string>("token", parameters.Token)); content.AddRange(source); if (parameters.Limit != DefaultValues.Limit) { content.Add(new KeyValuePair <string, string>("limit", parameters.Limit.ToString())); } if (parameters.Offset != DefaultValues.Offset) { content.Add(new KeyValuePair <string, string>("offset", parameters.Offset.ToString())); } if (parameters.Query != DefaultValues.Query) { content.Add(new KeyValuePair <string, string>("query", parameters.Query.ToString())); } if (parameters.Include != DefaultValues.Include) { content.Add(new KeyValuePair <string, string>("include", $"{String.Join(" , ", parameters.Include)}")); } return(content); }
/// <summary> /// Asyncronous method that call <see href="https://dandelion.eu/docs/api/datagraph/wikisearch/">Wikisearch end-point</see> on a text source /// </summary> /// <param name="parameters"> Parameters to specify all options for the Wikisearch process </param> /// <returns>Returns a <c>WikisearchDto</c> populated with the result of the Wikisearch process </returns> /// <seealso cref="WikisearchDto"/> public static Task <WikisearchDto> GetWikiSearchAsync(WikisearchParameters parameters) { Init(); return(_wikisearchService.CallWikisearchAsync(parameters)); }