ConsoleApp1/Services/ChuckNorrisService.cs
/// <summary>
/// Get specified number of jokes in specified category and subsitute 'Chuck Norris' with provided name
/// </summary>
/// <param name="names"></param>
/// <param name="numberOfJokes"></param>
/// <param name="categoryOfJokes"></param>
/// <returns></returns>
Get specified number of jokes in specified category and subsitute 'Chuck Norris' with provided name
Get specified number of jokes in specified category and subsitute ' Chuck Norris ' with provided name
public async IAsyncEnumerable<string> GetRandomJokesAsync((string first, string last)? names, int numberOfJokes = 1, string categoryOfJokes = null)
        {
            var newname = names.HasValue ? $"{names.Value.first.Trim()} {names.Value.last.Trim()}" : String.Empty;
            Dictionary<string, string> category = 
                String.IsNullOrEmpty(categoryOfJokes) ? null 
                : new() { { QueryStringParameters.JokeCategory, categoryOfJokes.Trim() } };
            foreach (int n in Enumerable.Range(1, numberOfJokes))
            {
                var joke = await GetRandomJokeAsync(category);
                joke = String.IsNullOrEmpty(newname) ? joke : joke.Replace("Chuck Norris", newname);
                yield return joke;
            }
        }
public async IAsyncEnumerable < string > GetRandomJokesAsync ( ( string first , string last ) ? names , int numberOfJokes = 1 , string categoryOfJokes = null ) { var newname = names . HasValue ? $" { names . Value . first . Trim ( ) } { names . Value . last . Trim ( ) } " : String . Empty ; Dictionary < string , string > category = String . IsNullOrEmpty ( categoryOfJokes ) ? null : new ( ) { { QueryStringParameters . JokeCategory , categoryOfJokes . Trim ( ) } } ; foreach ( int n in Enumerable . Range ( 1 , numberOfJokes ) ) { var joke = await GetRandomJokeAsync ( category ) ; joke = String . IsNullOrEmpty ( newname ) ? joke : joke . Replace ( " " , newname ) ; yield return joke ; } }
Get specified number of jokes in specified category and subsitute 'Chuck Norris' with provided name
Get specified number of jokes in specified category and subsitute ' Chuck Norris ' with provided name
None
names
(string first, string last)?
None
numberOfJokes
int
None
categoryOfJokes
string
None