public async Task <ActionResult <IntentResult> > Post([FromBody] NluResult nluResult) { JokeResult jokeResult = null; string responseText = ""; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(API_URL); if (response.IsSuccessStatusCode) { jokeResult = await response.Content.ReadAsAsync <JokeResult>(); Console.WriteLine(jokeResult.ToString()); } if (jokeResult != null) { responseText = jokeResult.value.joke; } else { responseText = "Sorry. Due to some error I was unable to think of a joke"; } return(new IntentResult() { responseText = responseText }); }
public async Task <ViewResult> Random(IndexViewModel form) { IndexViewModel model = new IndexViewModel(); HttpClient client = api.Initial(); //Get Categories HttpResponseMessage catResponse = await client.GetAsync("categories"); catResponse.EnsureSuccessStatusCode(); string catJson = await catResponse.Content.ReadAsStringAsync(); CategoryResult catResult = JsonConvert.DeserializeObject <CategoryResult>(catJson); model.Categories = catResult.value; //Get Number of jokes HttpResponseMessage totalResponse = await client.GetAsync("jokes/count"); totalResponse.EnsureSuccessStatusCode(); string totalJson = await totalResponse.Content.ReadAsStringAsync(); TotalResult totalResult = JsonConvert.DeserializeObject <TotalResult>(totalJson); ViewBag.Total = totalResult.value; //Decide whether to pick by ID or get randoms if (form.PickID != 0) { //Pick by ID HttpResponseMessage pickResponse = await client.GetAsync("jokes/" + form.PickID); pickResponse.EnsureSuccessStatusCode(); string pickJson = await pickResponse.Content.ReadAsStringAsync(); JokeIndv pickResult = JsonConvert.DeserializeObject <JokeIndv>(pickJson); JokeValue value = pickResult.value; model.Jokes.Add(value); } else { //Get random Jokes if (form.NumJokes == 0) { form.NumJokes = 1; } HttpResponseMessage jokeResponse = await client.GetAsync("jokes/random/" + form.NumJokes); jokeResponse.EnsureSuccessStatusCode(); string jokeJson = await jokeResponse.Content.ReadAsStringAsync(); JokeResult jokeResult = JsonConvert.DeserializeObject <JokeResult>(jokeJson); model.Jokes = jokeResult.value; } return(View("Index", model)); }
public GetRandomJokeAsyncTests() : base() { _expected = new JokeResult { Setup = "MockSetup", Punchline = "MockPunchline" }; _mockJokeLogic .Setup(x => x.GetRandomJokeAsync()) .ReturnsAsync(_expected); }
public void AddJoke(JokeResult jr) { using (var ctx = new JokesContext(_connectionString)) { ctx.Jokes.Add(new Joke { Number = jr.Number, Setup = jr.Setup, Punchline = jr.Punchline }); ctx.SaveChanges(); } }
private void RestartButton_Click_1(object sender, EventArgs e) { resetSeenJokes(); RestartButton.Hide(); JokeResult.Show(); Notification.Text = ""; JokeResult.Text = "Prepare for LULZ."; JokeButton.Show(); Like.Show(); Dislike.Show(); Settings.Default.CurrentJoke = 0; Settings.Default.Save(); }
public async Task Joke(CommandContext ctx) { JokeResult jokeResult; using (var webClient = new WebClient()) { string url = GenerateAPIURL(Program.config.jokesPrefix); var response = webClient.DownloadString(new Uri(url)); jokeResult = new JokeResult(response); } await ctx.RespondAsync(jokeResult.Joke); }
public string getJoke() { string hereItIs = ""; int numJokes = Settings.Default.JokeList.Count; int indx = rand.Next(0, numJokes); bool allSeen = checkAllSeen(); if (allSeen) { JokeResult.Hide(); RestartButton.Show(); Notification.Text = "You've seen all the jokes!"; JokeResult.BackColor = Color.BlanchedAlmond; JokeButton.Hide(); Like.Hide(); Dislike.Hide(); } else { if (Settings.Default.JokeSeen[indx] == "0") { hereItIs = Settings.Default.JokeList[indx].ToString(); string jokeVal = Settings.Default.LikeOrDislike[indx].ToString(); if (jokeVal == "+") { JokeResult.BackColor = Color.OliveDrab; Notification.Text = "You liked this joke..."; } if (jokeVal == "-") { JokeResult.BackColor = Color.IndianRed; Notification.Text = "You disliked this joke..."; } } else { hereItIs = findNextUnseen(); } Settings.Default.CurrentJoke = indx; Settings.Default.JokeSeen[indx] = "1"; Settings.Default.Save(); } return(hereItIs); }
private void Reset_Click(object sender, EventArgs e) { RestartButton.Hide(); JokeResult.Show(); JokeResult.BackColor = Color.BlanchedAlmond; Notification.Text = ""; JokeResult.Text = "Prepare for LULZ."; JokeButton.Show(); Like.Show(); Dislike.Show(); Settings.Default.CurrentJoke = 0; for (int i = 0; i < Settings.Default.LikeOrDislike.Count; i++) { Settings.Default.LikeOrDislike[i] = "0"; Settings.Default.JokeSeen[i] = "0"; Settings.Default.Save(); } Settings.Default.Save(); }
public GetRandomJokeAsyncTests() : base() { _jokeResponse = new JokeResponse { Id = 1, Type = "TestType", Setup = "TestSetup", Punchline = "TestPunchline" }; _mockRestfulClient .Setup(x => x.GetAsync <JokeResponse>(It.IsAny <string>())) .ReturnsAsync(_jokeResponse); _expected = new JokeResult { Setup = "TestSetup", Punchline = "TestPunchline" }; _mockJokeResultMapper .Setup(x => x.ToJokeResult(It.IsAny <JokeResponse>())) .Returns(_expected); }
public void AssertMappings(JokeResponse jokeResponse, JokeResult expected) { var actual = _objectToTest.ToJokeResult(jokeResponse); actual.Should().BeEquivalentTo(expected); }