public async Task VerifyGetJokesWithTermHydratesVMAndPutsJokeIntoCorrectJokeSizeGrouping() { var foundJokes = new List <DadJoke> { new DadJoke { Id = "123", Joke = "Knock, Knock, whose there" }, new DadJoke { Id = "456", Joke = "The wheels on the bus go knock and knock, I mean round and round" }, new DadJoke { Id = "987", Joke = "This is a very long joke that takes a lot of time to develop and by the time you get to the punchline you would have been better off with knock going with something else" } }; // Arrange string jokeTerm = "Knock"; _jokeService.Setup(s => s.GetJokesWithTerm(It.IsAny <string>())).Returns(Task.FromResult <IEnumerable <DadJoke> >(foundJokes)); var handler = new DadJokeHandler(_jokeService.Object); // Act var vm = await handler.GetJokesWithTerm(jokeTerm); // Assert Assert.AreEqual(jokeTerm, vm.Term); Assert.IsTrue(vm.JokesFound); Assert.IsTrue(vm.ShortJokes.Count == 1 && vm.MediumJokes.Count == 1 && vm.LargeJokes.Count == 1); }
public async Task <ActionResult> GetJokesWithTerm(string jokeTerm) { var handler = new DadJokeHandler(new DadJokeService()); var vm = await handler.GetJokesWithTerm(jokeTerm); return(PartialView("_FilteredJokesList", vm)); }
public async Task <ActionResult> GetRandomJoke() { var handler = new DadJokeHandler(new DadJokeService()); var vm = await handler.GetRandomJoke(); return(Json(new { Result = vm.Joke }, JsonRequestBehavior.AllowGet)); }
public async Task VerifyGetJokesWithTermThrowsApplicationErrorWhenASearchIsPerformedWithNoTerm() { // Arrange var handler = new DadJokeHandler(_jokeService.Object); // Act var vm = await handler.GetJokesWithTerm(string.Empty); }
public void VerifyGetWordCountWorksWithNoWords() { // Arrange var handler = new DadJokeHandler(_jokeService.Object); // Act int count = handler.GetWordCount(string.Empty); // Assert Assert.IsTrue(count == 0); }
public void VerifyGetWordCountWorks() { // Arrange var handler = new DadJokeHandler(_jokeService.Object); // Act int count = handler.GetWordCount("How now brown cow"); // Assert Assert.IsTrue(count == 4); }
public void VerifyFormatJokeForDisplayWrapsTermWithSpanTags() { // Arrange string joke = "Why did the chicken cross the road? To get to the other side."; string expectedValue = "Why did the <span class='look-at-me'>chicken</span> cross the road? To get to the other side."; string jokeTerm = "chicken"; var handler = new DadJokeHandler(_jokeService.Object); // Act var vm = handler.FormatJokeForDisplay(joke, jokeTerm); // Assert Assert.AreEqual(vm.Joke, expectedValue); }
public async Task VerifyGetJokesWithTermHydratesVMWhenNoMatchingJokesWithTermFound() { // Arrange var jokes = new List <DadJoke>(); string jokeTerm = "Knock"; _jokeService.Setup(s => s.GetJokesWithTerm(It.IsAny <string>())).Returns(Task.FromResult <IEnumerable <DadJoke> >(jokes)); var handler = new DadJokeHandler(_jokeService.Object); // Act var vm = await handler.GetJokesWithTerm(jokeTerm); // Assert Assert.AreEqual(jokeTerm, vm.Term); Assert.IsFalse(vm.JokesFound); }
public async Task VerifyGetRandomJokeHydratesModel() { // Arrange _jokeService.Setup(s => s.GetRandomJoke()).Returns(Task.FromResult(new DadJoke { Id = "1235", Joke = "Knock knock...whos there..." }) ); var handler = new DadJokeHandler(_jokeService.Object); // Act var vm = await handler.GetRandomJoke(); // Assert Assert.IsTrue(!string.IsNullOrWhiteSpace(vm.Joke)); }