public async Task RemoveFavouriteAsync_should_not_crash_if_not_exists() { const string repoToDelete = "path to delete"; var history = new List <Repository> { new Repository("path1"), new Repository("path2"), new Repository("path3"), new Repository("path4"), new Repository("path5"), }; _repositoryStorage.Load(KeyFavouriteHistory).Returns(x => history); _repositoryHistoryMigrator.MigrateAsync(Arg.Any <List <Repository> >()).Returns(x => (history, false)); var newHistory = await _manager.RemoveFavouriteAsync(repoToDelete); newHistory.Count.Should().Be(5); newHistory.Should().NotContain(repoToDelete); _repositoryStorage.Received(1).Load(KeyFavouriteHistory); _repositoryStorage.DidNotReceive().Save(KeyFavouriteHistory, Arg.Any <IEnumerable <Repository> >()); #pragma warning disable 4014 _repositoryHistoryMigrator.Received(1).MigrateAsync(history); #pragma warning restore 4014 }
/// <summary> /// Loads the list of favourite local git repositories from a persistent storage. /// </summary> /// <returns>The list of favourite local git repositories.</returns> public async Task <IList <Repository> > LoadFavouriteHistoryAsync() { await TaskScheduler.Default; var history = _repositoryStorage.Load(KeyFavouriteHistory) ?? Array.Empty <Repository>(); // backwards compatibility - port the existing user's categorised repositories var(migrated, changed) = await _repositoryHistoryMigrator.MigrateAsync(history); if (changed) { _repositoryStorage.Save(KeyFavouriteHistory, migrated); } return(migrated ?? new List <Repository>()); }