public async Task When_getting_playlists_from_YouTube_api_Then_they_are_saved_to_the_database( [Frozen] IYouTubeCleanupToolDbContext youTubeCleanupToolDbContext, [Frozen] IYouTubeCleanupToolDbContextFactory youTubeCleanupToolDbContextFactory, [Frozen] IYouTubeApi youTubeApi, List <PlaylistData> playlistData, GetAndCacheYouTubeData getAndCacheYouTubeData) { youTubeCleanupToolDbContextFactory.Create().Returns(youTubeCleanupToolDbContext); youTubeApi.GetPlaylists().Returns(TestExtensions.ToAsyncEnumerable(playlistData)); // Act await getAndCacheYouTubeData.GetPlaylists(Callback, CancellationToken.None); // Assert await foreach (var _ in youTubeApi.Received(1).GetPlaylists()) { } await youTubeCleanupToolDbContext.Received(3).UpsertPlaylist(Arg.Any <PlaylistData>()); await youTubeCleanupToolDbContext.Received(1).SaveChangesAsync(); }
public async Task When_getting_playlists_from_YouTube_api_Then_they_are_saved_to_the_database( [Frozen] IYouTubeCleanupToolDbContext youTubeCleanupToolDbContext, [Frozen] IYouTubeCleanupToolDbContextFactory youTubeCleanupToolDbContextFactory, [Frozen] IYouTubeApi youTubeApi, List <PlaylistData> playlistData, GetAndCacheYouTubeData getAndCacheYouTubeData) { youTubeCleanupToolDbContextFactory.Create().Returns(youTubeCleanupToolDbContext); youTubeApi.GetPlaylists().Returns(TestExtensions.ToAsyncEnumerable(playlistData)); var callback = new Action <PlaylistData, InsertStatus>((data, insertStatus) => _testOutputHelper.WriteLine($"{data.Title} - {insertStatus}")); // Act await getAndCacheYouTubeData.GetPlaylists(callback); // Assert await foreach (var _ in youTubeApi.Received(1).GetPlaylists()) { } await youTubeCleanupToolDbContext.Received(3).UpsertPlaylist(Arg.Any <PlaylistData>()); await youTubeCleanupToolDbContext.Received(1).SaveChangesAsync(); }