Esempio n. 1
0
        public async void GetRandomJoke_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.GetRandomJoke(CategoryQuery.None));

            // Then
            Assert.IsType <HttpRequestException>(recorded);
        }
Esempio n. 2
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);
        }