public void UpdateCache_Exception_DoesNotRethrow() { var mockTmdbCacheUpdater = new Mock <ITmdbCacheUpdater>(); mockTmdbCacheUpdater .Setup(tcu => tcu.UpdateCache()) .Throws <ApplicationException>(); var mockServiceProvider = new Mock <IServiceProvider>(); mockServiceProvider .Setup(sp => sp.GetService(typeof(ITmdbCacheUpdater))) .Returns(mockTmdbCacheUpdater.Object); var mockServiceScope = new Mock <IServiceScope>(); mockServiceScope.Setup(x => x.ServiceProvider).Returns(mockServiceProvider.Object); var mockServiceScopeFactory = new Mock <IServiceScopeFactory>(); mockServiceScopeFactory .Setup(x => x.CreateScope()) .Returns(mockServiceScope.Object); mockServiceProvider .Setup(x => x.GetService(typeof(IServiceScopeFactory))) .Returns(mockServiceScopeFactory.Object); // Act var service = new TmdbDataRefresherService(FakeOptions, FakeLogger, mockServiceProvider.Object); service.StartAsync(CancellationToken.None); mockTmdbCacheUpdater.Verify(tcu => tcu.UpdateCache(), Times.Once); }
public async Task StartingAndStoppingService_CallsUpdateCache() { var services = new ServiceCollection(); services.AddTransient <ITmdbCacheUpdater, FakeTmdbCacheUpdater>(); var service = new TmdbDataRefresherService(FakeOptions, FakeLogger, services.BuildServiceProvider()); Assert.False(FakeTmdbCacheUpdater.IsUpdateCacheCalled); await service.StartAsync(CancellationToken.None); Assert.True(FakeTmdbCacheUpdater.IsUpdateCacheCalled); }