public void GetCategories_CallMethod_ReturnsAtLeastOneCategory() { //Arrange var handlerMock = new Mock <HttpMessageHandler>(); handlerMock.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.OK, Content = new StringContent("[\"animal\",\"career\",\"celebrity\",\"dev\"," + "\"explicit\",\"fashion\",\"food\",\"history\",\"money\",\"movie\",\"music\"," + "\"political\",\"religion\",\"science\",\"sport\",\"travel\"]") }); var client = new HttpClient(handlerMock.Object); _sut = new JokeGenerator.JokeGenerator(client); //Act var actual = _sut.GetCategories(); //Assert Assert.Greater(actual.Count, 0); }
/// <summary> /// Calls API for the list of categories, and sets the information into the results variable. /// </summary> private static List <string> GetCategories() { var jokeGen = new JokeGenerator(new HttpClient()); catList = jokeGen.GetCategories(); return(catList); }
public void GetCategories_BadRequest_ReturnsEmptyList() { //Arrange var handlerMock = new Mock <HttpMessageHandler>(); handlerMock.Protected() .Setup <Task <HttpResponseMessage> >("SendAsync", ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()) .ReturnsAsync(new HttpResponseMessage { StatusCode = HttpStatusCode.NotFound, }); var client = new HttpClient(handlerMock.Object); _sut = new JokeGenerator.JokeGenerator(client); //Act var actual = _sut.GetCategories(); //Assert Assert.AreEqual(0, actual.Count); }