public void GetQuotes_WhenNull_ReturnEmptyList() { //arrange var repository = new FlightRepository(new List <IFlightResponseReader>() { mockKayakServices.Object, mockSkyscannerServices.Object }); //act IEnumerable <IFlightResponse> responses = repository.BrowseQuotes(null); //assert Assert.IsTrue(!responses.Any()); mockILog.Verify(_ => _.Error(It.IsAny <string>()), Times.Once); }
public void GetQuotes_WhenCall_ReturnQuotes() { //arrange IFlightRequest myFlightRequest = new FlightRequest(); IFlightResponse aKayakFlight = new FlightResponse(); var kayakFlights = new List <IFlightResponse>() { aKayakFlight }; mockKayakServices.Setup(_ => _.BrowseQuotesAsync(myFlightRequest)).Returns(Task.FromResult(kayakFlights)); IFlightResponse aSkyscannerFlight = new FlightResponse(); var skyscannerFlights = new List <IFlightResponse>() { aSkyscannerFlight }; mockSkyscannerServices.Setup(_ => _.BrowseQuotesAsync(myFlightRequest)).Returns(Task.FromResult(skyscannerFlights)); //act var repository = new FlightRepository(new List <IFlightResponseReader>() { mockKayakServices.Object, mockSkyscannerServices.Object }); IEnumerable <IFlightResponse> quoteResponses = repository.BrowseQuotes(myFlightRequest); var expectedResponses = new List <IFlightResponse>() { aKayakFlight, aSkyscannerFlight }; var expectedLogInfCount = 6; //assert Assert.IsNotNull(quoteResponses); Assert.AreEqual(quoteResponses.Count(), expectedResponses.Count); Assert.IsTrue(quoteResponses.Contains(expectedResponses[0])); Assert.IsTrue(quoteResponses.Contains(expectedResponses[1])); //assert log information mockILog.Verify(_ => _.Info(It.IsAny <string>()), Times.Exactly(expectedLogInfCount)); //assert no log error mockILog.Verify(_ => _.Error(It.IsAny <string>()), Times.Never); }