예제 #1
0
        public static async Task <string> GetMessageResponse(string message)
        {
            var responseMessage = string.Empty;

            var selectedOption = string.Empty;

            foreach (var option in MessageOptions)
            {
                if (message.ToLower().Contains(option.Key))
                {
                    selectedOption = option.Key;
                    break;
                }
            }

            if (!string.IsNullOrEmpty(selectedOption))
            {
                switch (selectedOption.ToLower())
                {
                case "time":
                    responseMessage = string.Format(MessageOptions[selectedOption], DateTime.Now);
                    break;

                case "btc":
                case "bitcoin":
                    var bitcoinResponse = await BitcoinClient.GetBitcoinPrice();

                    responseMessage = string.Format(MessageOptions[selectedOption],
                                                    bitcoinResponse.bpi.EUR.rate_float.ToString("0.00"), bitcoinResponse.bpi.EUR.code,
                                                    bitcoinResponse.bpi.GBP.rate_float.ToString("0.00"), bitcoinResponse.bpi.GBP.code,
                                                    bitcoinResponse.bpi.USD.rate_float.ToString("0.00"), bitcoinResponse.bpi.USD.code);
                    break;

                case "joke":
                    var jokeResponse = await JokeClient.GetRandomJoke();

                    responseMessage = string.Format(MessageOptions[selectedOption], jokeResponse.setup,
                                                    jokeResponse.punchline);
                    break;

                case "advice":
                    var adviceResponse = await AdviceClient.GetRandomAdvice();

                    responseMessage = adviceResponse.slip.advice;
                    break;

                default:
                    responseMessage = MessageOptions[selectedOption];
                    break;
                }
                return(responseMessage);
            }

            return("Option doesn't exist. Write 'help' to see all the options'");
        }
예제 #2
0
 public void TestCleanUp()
 {
     _jokeClient = null;
 }
예제 #3
0
 public void TestInitialize()
 {
     _jokeClient = new JokeClient();
 }