private void Tester(int IndexCompare, Func<IMusicSession, IList<Track>> Trackers, Func<AlbumInfoEditor, IMusicSession, IProgress<ImportExportError>> Initializer) //, Action<IList<Track>,IMusicSession> F) { TesterBasic(IndexCompare, (ms) => { using (AlbumInfoEditor aie = new AlbumInfoEditor(Trackers(ms), ms)) { IProgress<ImportExportError> res = Initializer(aie, ms); aie.Commit(res); //aie.CommitChanges(true); } } ); }
public void Test() { Console.WriteLine("AlbumInfoEditor tester #1"); using (IMusicSession ms = MusicSessionImpl.GetSession(_SK.Builder)) { Assert.That(ms.AllAlbums.Count, Is.EqualTo(0)); Assert.That(ms.AllGenres.Count, Is.EqualTo(0)); Assert.That(ms.AllArtists.Count, Is.EqualTo(0)); IMusicImporter imi = ms.GetDBImporter(); Assert.That(imi, Is.Not.Null); imi.Load(); Assert.That(ms.AllAlbums.Count, Is.EqualTo(0)); Assert.That(ms.AllGenres.Count, Is.EqualTo(25)); Assert.That(ms.AllArtists.Count, Is.EqualTo(0)); Console.WriteLine("Importing Music Folder"); IDirectoryImporterBuilder imib = ms.GetImporterBuilder(MusicImportType.Directory) as IDirectoryImporterBuilder; Assert.That(imib, Is.Not.Null); imib.Directory = DirectoryIn; imib.DefaultAlbumMaturity = AlbumMaturity.Discover; Assert.That(imib.IsValid, Is.True); imi = imib.BuildImporter(); Assert.That(imi, Is.Not.Null); imi.Load(); Assert.That(ms.AllAlbums.Count, Is.EqualTo(7)); Assert.That(ms.AllGenres.Count, Is.EqualTo(25)); Assert.That(ms.AllArtists.Count, Is.EqualTo(13)); AssertEnumerable(from a in ms.AllAlbums select a.Name, from a in OldAlbums[0] select a.Name, n => n); AssertEnumerable(from a in ms.AllAlbums select (a.MainGenre == null ? null : a.MainGenre.FullName), from a in OldAlbums[0] select a.Genre, n => n); AssertEnumerable(from a in ms.AllAlbums select a.Year, from a in OldAlbums[0] select a.Year, n => n); AssertAlbums(ms, OldAlbums[0], AlbumDescriptorCompareMode.AlbumMD); AssertAlbums(ms, OldAlbums[0], AlbumDescriptorCompareMode.AlbumandTrackMD); Console.WriteLine("Import Successful 7 Albums(8 Tracks)"); IList<Artist> ar = Artist.GetArtistFromName("Toto", ms as MusicSessionImpl).ToList(); IList<AlbumTarget> AlbumTargets = AlbumTarget.FromListAndTargets(ms.AllTracks.Cast<Track>().ToList(), ar, "Africa"); Assert.That(AlbumTargets.Count, Is.EqualTo(1)); Assert.That(AlbumTargets[0].AlbumName, Is.EqualTo("Africa")); Assert.That(AlbumTargets[0].Artists.SequenceEqual(ar), Is.True); Assert.That(AlbumTargets[0].OrderedTrack.Count, Is.EqualTo(ms.AllAlbums.Count)); Assert.That(AlbumTargets[0].OrderedTrack.Select(ot => ot.OriginAlbum).OrderBy(a => a.Name).SequenceEqual(ms.AllAlbums.OrderBy(a => a.Name))); Assert.That(AlbumTargets[0].OrderedTrack.SelectMany(ot => ot.Tracks).Count(), Is.EqualTo(ms.AllTracks.Count())); Assert.That(AlbumTargets.All(e => e.OrderedTrack.All(at => at.Complete)), Is.True); IList<ITrack> atrs = ms.AllTracks; List<Track> trs = new List<Track>(); trs.Add(atrs[0] as Track); trs.Add(atrs[1] as Track); AlbumTargets = AlbumTarget.FromListAndTargets(trs, ar, null); Assert.That(AlbumTargets.Count, Is.EqualTo(2)); Assert.That(AlbumTargets.All(at => at.Artists.SequenceEqual(ar)), Is.True); Assert.That(AlbumTargets.SelectMany(at => at.OrderedTrack.SelectMany(ot => ot.Tracks)).Count(), Is.EqualTo(2)); AlbumTargets = AlbumTarget.FromListAndTargets(trs, null, "Afreica"); Assert.That(AlbumTargets.Count, Is.EqualTo(2)); Assert.That(AlbumTargets.All(at => at.AlbumName == "Afreica"), Is.True); Assert.That(AlbumTargets.SelectMany(at => at.OrderedTrack.SelectMany(ot => ot.Tracks)).Count(), Is.EqualTo(2)); Assert.That(AlbumTargets.All(e => e.OrderedTrack.All(at => at.Complete)), Is.True); var arc = Artist.GetArtistFromName("Los Hombres Calientes", ms as MusicSessionImpl).ToList(); var resartcalien = ms.AllAlbums.Where(a => a.Artists.Any(art => art.Name == "Los Hombres Calientes")).Select(a => a); var resnamecalien = ms.AllAlbums.Where(a => a.Name == "LOS HOMBRES CALIENTES VOL. IV").Select(a => a); AlbumTargets = AlbumTarget.FromListAndTargets(resartcalien.SelectMany(a => (a as Album).RawTracks).ToList(), null, "la mano nell luco"); Assert.That(AlbumTargets.Count, Is.EqualTo(1)); Assert.That(AlbumTargets[0].AlbumName, Is.EqualTo("la mano nell luco")); Assert.That(AlbumTargets[0].Artists.SequenceEqual(arc), Is.True); Assert.That(AlbumTargets[0].OrderedTrack.Count, Is.EqualTo(2)); Assert.That(AlbumTargets.SelectMany(at => at.OrderedTrack.SelectMany(ot => ot.Tracks)).Count(), Is.EqualTo(3)); Assert.That(AlbumTargets.All(e => e.OrderedTrack.All(at => at.Complete)), Is.True); var arf = Artist.GetArtistFromName("Des Menches Gefriezert", ms as MusicSessionImpl).ToList(); AlbumTargets = AlbumTarget.FromListAndTargets(resnamecalien.SelectMany(a => (a as Album).RawTracks).ToList(), arf, null); Assert.That(AlbumTargets.Count, Is.EqualTo(1)); Assert.That(AlbumTargets[0].AlbumName, Is.EqualTo("LOS HOMBRES CALIENTES VOL. IV")); Assert.That(AlbumTargets[0].Artists.SequenceEqual(arf), Is.True); Assert.That(AlbumTargets[0].OrderedTrack.Count, Is.EqualTo(2)); Assert.That(AlbumTargets.SelectMany(at => at.OrderedTrack.SelectMany(ot => ot.Tracks)).Count(), Is.EqualTo(3)); Assert.That(AlbumTargets.All(e => e.OrderedTrack.All(at => at.Complete)), Is.True); var unic = ms.AllAlbums.Where(a => a.Artists.Any(art => art.Name == "Los Hombres Calientes") && a.Name == "LOS HOMBRES CALIENTES VOL. IV").Select(a => a); Assert.That(unic.Count(), Is.EqualTo(1)); Album all = unic.First() as Album; Assert.That(all, Is.Not.Null); Assert.That(all.RawTracks.Count(), Is.EqualTo(2)); AlbumTargets = AlbumTarget.FromListAndTargets(all.RawTracks.ToList()[0].SingleItemCollection().ToList(), arf, "toto"); Assert.That(AlbumTargets.Count, Is.EqualTo(1)); Assert.That(AlbumTargets[0].AlbumName, Is.EqualTo("toto")); Assert.That(AlbumTargets[0].Artists.SequenceEqual(arf), Is.True); Assert.That(AlbumTargets[0].OrderedTrack.Count, Is.EqualTo(1)); Assert.That(AlbumTargets.SelectMany(at => at.OrderedTrack.SelectMany(ot => ot.Tracks)).Count(), Is.EqualTo(1)); Assert.That(AlbumTargets[0].OrderedTrack[0].Complete, Is.False); using (AlbumInfoEditor aie = new AlbumInfoEditor(all.RawTracks.ToList()[0].SingleItemCollection().ToList(), ms)) { aie.AlbumName = "toto"; aie.Author = Artist.AuthorName( arf); aie.Commit(); //aie.CommitChanges(true); } AssertAlbums(ms, OldAlbums[1], AlbumDescriptorCompareMode.AlbumMD); AssertAlbums(ms, OldAlbums[1], AlbumDescriptorCompareMode.AlbumandTrackMD, true); //<Artist>Los Hombres Calientes</Artist> //<Name>LOS HOMBRES CALIENTES VOL. IV</Name> } using (IMusicSession ms = MusicSessionImpl.GetSession(_SK.Builder)) { Assert.That(ms.AllAlbums.Count, Is.EqualTo(0)); Assert.That(ms.AllGenres.Count, Is.EqualTo(0)); Assert.That(ms.AllArtists.Count, Is.EqualTo(0)); IMusicImporter imi = ms.GetDBImporter(); Assert.That(imi, Is.Not.Null); imi.Load(); AssertAlbums(ms, OldAlbums[1], AlbumDescriptorCompareMode.AlbumMD); AssertAlbums(ms, OldAlbums[1], AlbumDescriptorCompareMode.AlbumandTrackMD); IMusicRemover imr = ms.GetMusicRemover(); imr.IncludePhysicalRemove = false; imr.AlbumtoRemove.AddCollection(ms.AllAlbums); imr.Comit(); Assert.That(ms.AllAlbums.Count, Is.EqualTo(0)); } using (IMusicSession ms = MusicSessionImpl.GetSession(_SK.Builder)) { Assert.That(ms.AllAlbums.Count, Is.EqualTo(0)); Assert.That(ms.AllGenres.Count, Is.EqualTo(0)); Assert.That(ms.AllArtists.Count, Is.EqualTo(0)); IMusicImporter imi = ms.GetDBImporter(); Assert.That(imi, Is.Not.Null); imi.Load(); Assert.That(ms.AllAlbums.Count, Is.EqualTo(0)); Assert.That(ms.AllGenres.Count, Is.EqualTo(25)); Assert.That(ms.AllArtists.Count, Is.EqualTo(0)); Console.WriteLine("Importing Music Folder"); IDirectoryImporterBuilder imib = ms.GetImporterBuilder(MusicImportType.Directory) as IDirectoryImporterBuilder; Assert.That(imib, Is.Not.Null); imib.Directory = DirectoryIn; imib.DefaultAlbumMaturity = AlbumMaturity.Discover; Assert.That(imib.IsValid, Is.True); imi = imib.BuildImporter(); Assert.That(imi, Is.Not.Null); imi.Load(); AssertAlbums(ms, OldAlbums[1], AlbumDescriptorCompareMode.AlbumMD); AssertAlbums(ms, OldAlbums[1], AlbumDescriptorCompareMode.AlbumandTrackMD, true); } }