public async Task GetWeatherInCity_Exception_TestAsync() { await Assert.ThrowsAsync <InvalidOperationException>(() => _api.GetWeatherInCityAsync("hjghjg")); }
internal async Task <string> AnswerQuestionAsync(string userQuestion) { AIConfiguration config = new AIConfiguration("dialogflow.com", SupportedLanguage.Russian); var apiAi = new ApiAi(config); List <string> answers = new List <string>(); userQuestion = userQuestion.ToLowerInvariant(); if (userQuestion == "/start" || userQuestion == "начать") { try { await GetStartMessageAsync(answers); } catch (Exception e) { Console.WriteLine(e); } } if (userQuestion.Contains("сколько времени")) { var time = DateTime.Now.ToString("HH:mm"); string timeString = $"Точное время: {time}"; if (!answers.Contains(timeString)) { answers.Add(timeString); } } if (userQuestion.Contains("какой сегодня день")) { var date = DateTime.Now.ToString("dd.MM.yyyy"); string dateString = $"Сегодня: {date}"; if (!answers.Contains(dateString)) { answers.Add(dateString); } } if (userQuestion.StartsWith("какая погода в городе")) { var words = userQuestion.Split(' '); var city = words[words.Length - 1]; var weatherApi = new WeatherApi(); var forecast = await weatherApi.GetWeatherInCityAsync(city); if (!answers.Contains(forecast)) { answers.Add(forecast); } } if (userQuestion == "цитата") { var quoteApi = new QuoteApi(); string quote = await quoteApi.GetQuote(); if (!answers.Contains(quote)) { answers.Add(quote); } } if (answers.Count == 0) { var response = apiAi.TextRequest(userQuestion); string answer = response.Result.Fulfillment.Speech; if (String.IsNullOrEmpty(answer)) { answer = "Прости, я тебя не понимаю"; } answers.Add(answer); } return(String.Join(", ", answers)); }