Exemple #1
0
 private async static Task MainAsync()
 {
     var client        = new HttpClient();
     var jokeFeed      = new DefaultJokeService(client);
     var nameGenerator = new RandomNameService(client);
     var prompt        = new ConsolePrompt();
     var printer       = new ConsolePrinter();
     var generator     = new ConsoleJokeGenerator(jokeFeed, nameGenerator, prompt, printer);
     await generator.EventLoop();
 }
Exemple #2
0
        public async void GetCategories_Throws_HttpStatusException()
        {
            // Given
            var messageHandler = new FakeHttpMessageHandler(new HttpRequestException());
            var httpClient     = new HttpClient(messageHandler);
            IJokeService <CategoryQuery> sut = new DefaultJokeService(httpClient);

            // When
            var recorded = await Record.ExceptionAsync(() => sut.GetCategories());

            // Then
            Assert.IsType <HttpRequestException>(recorded);
        }
Exemple #3
0
        public async void GetCategories_Returns_ValidCategories()
        {
            // Given
            var messageHandler = new FakeHttpMessageHandler(JsonConvert.SerializeObject(DefaultCategories));
            var httpClient     = new HttpClient(messageHandler);
            IJokeService <CategoryQuery> sut = new DefaultJokeService(httpClient);

            // When
            var categories = await sut.GetCategories();

            // Then
            Assert.Equal(CategoryUri, messageHandler.RequestMessage.RequestUri);
            Assert.Equal(DefaultCategories, categories);
        }
Exemple #4
0
        public async void GetRandomJoke_Returns_ValidJokeBasedOnCategory()
        {
            // Given
            var messageHandler = new FakeHttpMessageHandler(JsonConvert.SerializeObject(DefaultJoke));
            var httpClient     = new HttpClient(messageHandler);
            IJokeService <CategoryQuery> sut = new DefaultJokeService(httpClient);

            // When
            var joke = await sut.GetRandomJoke(new CategoryQuery("my-category"));

            // Then
            Assert.Equal(new Uri(RandomJokeUri, "?category=my-category"), messageHandler.RequestMessage.RequestUri);
            Assert.Equal(DefaultJoke.Value, joke.Value);
        }