예제 #1
0
        public async Task <IActionResult> Index()
        {
            string     quoteString = "";
            string     quoteAuthor = "";
            HttpClient client      = new HttpClient();

            // using external API to generate quotes
            try
            {
                var response = await client.GetStringAsync("https://api.quotable.io/random");

                if (string.IsNullOrEmpty(response))
                {
                    Debug.WriteLine("Failed to receive response from the Quote API.");
                }

                QuoteApiModel quote = Newtonsoft.Json.JsonConvert.DeserializeObject <QuoteApiModel>(response);

                if (quote != null)
                {
                    quoteString = quote.Content;
                    quoteAuthor = quote.Author;
                }
            }
            catch (HttpRequestException ex)
            {
                throw ex;
            }

            ViewData["QuoteString"] = quoteString;
            ViewData["QuoteAuthor"] = quoteAuthor;

            return(View());
        }
예제 #2
0
        public void correctQuoteApiModelInfo(string author, string content, string expected)
        {
            QuoteApiModel quoteApiModel = new QuoteApiModel();

            quoteApiModel.Author  = author;
            quoteApiModel.Content = content;
            Assert.True(quoteApiModel.QuoteApiModelInfo() == expected);
        }
예제 #3
0
        public void AuthorName()
        {
            QuoteApiModel quoteApiModel = new QuoteApiModel();

            Assert.True(quoteApiModel.Author == null);
        }