public void GetAllRates_With_Service_Unavailable() { // Arrenge const string ratesUrl = "http://quiet-stone-2094.herokuapp.com/rates.json"; var options = new DbContextOptionsBuilder <GNBContext>() .UseInMemoryDatabase(databaseName: "GNBTestDB") .Options; var mockLogger = new Mock <ILogger <RateService> >(); var logger = mockLogger.Object; var context = new GNBContext(options); var rateRepository = new RateRepository(context); var rateService = new RateService(rateRepository, logger); // Act var rates = rateService.GetAllAsync(ratesUrl).Result; var ratesFromDB = rateService.GetAllAsync("").Result; // Assertion Assert.True(rates.Any()); // Checks if all rates were fetched from server. Assert.True(ratesFromDB.Any()); // Checks if all rates were fetched from database. }
public void CheckIfLoggerWasExecuted_Getting_Rates() { // Arrenge. var mockLogger = new Mock <ILogger <RateService> >(); var rateService = new RateService(null, mockLogger.Object); // Act var rates = rateService.GetAllAsync(null); // Assert mockLogger.Verify(l => l.Log( LogLevel.Error, It.IsAny <EventId>(), It.Is <It.IsAnyType>((v, t) => true), It.IsAny <Exception>(), It.Is <Func <It.IsAnyType, Exception, string> >((v, t) => true)), Times.AtLeastOnce); }