/// <summary>
        /// Creates the ViewModels.
        /// </summary>
        /// <param name="windowManager">WindowManager used to display dialogs.</param>
        /// <param name="localFileFactory">Factory used to create <see cref="Data.ILocalFile"/>s.</param>
        /// <param name="fileOperator">FileOperator used to interface with files.</param>
        /// <param name="lastFMClient">Last.fm client.</param>
        /// <param name="discogsClient">Client used to interact with Discogs.com</param>
        /// <param name="fileParserFactory">Factory for creating <see cref="IFileParser"/></param>
        private void CreateViewModels(IExtendedWindowManager windowManager, ILocalFileFactory localFileFactory, IFileOperator fileOperator, ILastFMClient lastFMClient,
                                      IDiscogsDataBaseClient discogsClient, IFileParserFactory fileParserFactory)
        {
            var manualScrobbleViewModel = new ManualScrobbleViewModel(windowManager);

            manualScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var friendScrobbleViewModel = new FriendScrobbleViewModel(windowManager, lastFMClient.User);

            friendScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var databaseScrobbleViewModel = new DatabaseScrobbleViewModel(windowManager, lastFMClient.Artist, lastFMClient.Album, discogsClient);

            databaseScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var csvScrobbleViewModel = new FileParseScrobbleViewModel(windowManager, fileParserFactory, fileOperator);

            csvScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var fileScrobbleViewModel = new FileScrobbleViewModel(windowManager, localFileFactory, fileOperator);

            fileScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var mediaPlayerDatabaseScrobbleViewModel = new MediaPlayerDatabaseScrobbleViewModel(windowManager);

            mediaPlayerDatabaseScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var iTunesScrobbleVM = new ITunesScrobbleViewModel(windowManager, lastFMClient.Track, lastFMClient.Album, lastFMClient.Artist);

            iTunesScrobbleVM.StatusUpdated += Scrobbler_StatusUpdated;
            // todo: put back in once local api is working again
            //var spotifyScrobbleVM = new SpotifyScrobbleViewModel(windowManager, lastFMClient.Track, lastFMClient.Album, lastFMClient.Auth);
            //spotifyScrobbleVM.StatusUpdated += Scrobbler_StatusUpdated;
            var setlistFMScrobbleVM = new SetlistFMScrobbleViewModel(windowManager, lastFMClient.Artist);

            setlistFMScrobbleVM.StatusUpdated += Scrobbler_StatusUpdated;
            var cacheScrobblerVM = new CacheScrobblerViewModel(windowManager);

            cacheScrobblerVM.StatusUpdated += Scrobbler_StatusUpdated;

            ActivateItem(manualScrobbleViewModel);
            ActivateItem(friendScrobbleViewModel);
            ActivateItem(databaseScrobbleViewModel);
            ActivateItem(csvScrobbleViewModel);
            ActivateItem(fileScrobbleViewModel);
            ActivateItem(mediaPlayerDatabaseScrobbleViewModel);
            ActivateItem(iTunesScrobbleVM);
            //ActivateItem(spotifyScrobbleVM);
            ActivateItem(setlistFMScrobbleVM);
            ActivateItem(cacheScrobblerVM);

            // this one should be selected
            ActivateItem(manualScrobbleViewModel);
        }
Beispiel #2
0
        /// <summary>
        /// Creates the ViewModels.
        /// </summary>
        /// <param name="windowManager">WindowManager used to display dialogs.</param>
        /// <param name="localFileFactory">Factory used to create <see cref="ILocalFile"/>s.</param>
        private void CreateViewModels(IExtendedWindowManager windowManager, ILocalFileFactory localFileFactory)
        {
            var manualScrobbleViewModel = new ManualScrobbleViewModel(windowManager);

            manualScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var friendScrobbleViewModel = new FriendScrobbleViewModel(windowManager, MainViewModel.Client.User);

            friendScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var databaseScrobbleViewModel = new DatabaseScrobbleViewModel(windowManager, MainViewModel.Client.Artist, MainViewModel.Client.Album);

            databaseScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var csvScrobbleViewModel = new CSVScrobbleViewModel(windowManager, new CSVTextFieldParserFactory());

            csvScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var fileScrobbleViewModel = new FileScrobbleViewModel(windowManager, localFileFactory);

            fileScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var mediaPlayerDatabaseScrobbleViewModel = new MediaPlayerDatabaseScrobbleViewModel(windowManager);

            mediaPlayerDatabaseScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var iTunesScrobbleVM = new ITunesScrobbleViewModel(windowManager);

            iTunesScrobbleVM.StatusUpdated += Scrobbler_StatusUpdated;
            var spotifyScrobbleVM = new SpotifyScrobbleViewModel(windowManager);

            spotifyScrobbleVM.StatusUpdated += Scrobbler_StatusUpdated;
            var setlistFMScrobbleVM = new SetlistFMScrobbleViewModel(windowManager);

            setlistFMScrobbleVM.StatusUpdated += Scrobbler_StatusUpdated;
            var cacheScrobblerVM = new CacheScrobblerViewModel(windowManager);

            cacheScrobblerVM.StatusUpdated += Scrobbler_StatusUpdated;

            ActivateItem(manualScrobbleViewModel);
            ActivateItem(friendScrobbleViewModel);
            ActivateItem(databaseScrobbleViewModel);
            ActivateItem(csvScrobbleViewModel);
            ActivateItem(fileScrobbleViewModel);
            ActivateItem(mediaPlayerDatabaseScrobbleViewModel);
            ActivateItem(iTunesScrobbleVM);
            ActivateItem(spotifyScrobbleVM);
            ActivateItem(setlistFMScrobbleVM);
            ActivateItem(cacheScrobblerVM);

            // this one should be selected
            ActivateItem(manualScrobbleViewModel);
        }
Beispiel #3
0
        /// <summary>
        /// Creates the ViewModels.
        /// </summary>
        /// <param name="windowManager">WindowManager used to display dialogs.</param>
        /// <param name="localFileFactory">Factory used to create <see cref="Data.ILocalFile"/>s.</param>
        /// <param name="fileOperator">FileOperator used to interface with files.</param>
        /// <param name="lastFMClient">Last.fm client.</param>
        /// <param name="discogsClient">Client used to interact with Discogs.com</param>
        /// <param name="fileParserFactory">Factory for creating <see cref="IFileParser"/></param>
        private ScrobbleViewModelBase[] CreateViewModels(IExtendedWindowManager windowManager, ILocalFileFactory localFileFactory, IFileOperator fileOperator, ILastFMClient lastFMClient,
                                                         IDiscogsDataBaseClient discogsClient, IFileParserFactory fileParserFactory)
        {
            var manualScrobbleViewModel = new ManualScrobbleViewModel(windowManager);

            manualScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var friendScrobbleViewModel = new FriendScrobbleViewModel(windowManager, lastFMClient.User);

            friendScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var databaseScrobbleViewModel = new DatabaseScrobbleViewModel(windowManager, lastFMClient.Artist, lastFMClient.Album, discogsClient);

            databaseScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var csvScrobbleViewModel = new FileParseScrobbleViewModel(windowManager, fileParserFactory, fileOperator);

            csvScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var fileScrobbleViewModel = new FileScrobbleViewModel(windowManager, localFileFactory, fileOperator);

            fileScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var mediaPlayerDatabaseScrobbleViewModel = new MediaPlayerDatabaseScrobbleViewModel(windowManager);

            mediaPlayerDatabaseScrobbleViewModel.StatusUpdated += Scrobbler_StatusUpdated;
            var iTunesScrobbleVM = new ITunesScrobbleViewModel(windowManager, lastFMClient.Track, lastFMClient.Album, lastFMClient.Artist);

            iTunesScrobbleVM.StatusUpdated += Scrobbler_StatusUpdated;
            // todo: put back in once local api is working again
            //var spotifyScrobbleVM = new SpotifyScrobbleViewModel(windowManager, lastFMClient.Track, lastFMClient.Album, lastFMClient.Auth);
            //spotifyScrobbleVM.StatusUpdated += Scrobbler_StatusUpdated;
            var setlistFMScrobbleVM = new SetlistFMScrobbleViewModel(windowManager, lastFMClient.Artist);

            setlistFMScrobbleVM.StatusUpdated += Scrobbler_StatusUpdated;
            var cacheScrobblerVM = new CacheScrobblerViewModel(windowManager);

            cacheScrobblerVM.StatusUpdated += Scrobbler_StatusUpdated;

            return(new ScrobbleViewModelBase[] { manualScrobbleViewModel, friendScrobbleViewModel, databaseScrobbleViewModel, csvScrobbleViewModel,
                                                 fileScrobbleViewModel, mediaPlayerDatabaseScrobbleViewModel, iTunesScrobbleVM, setlistFMScrobbleVM, cacheScrobblerVM });
        }
        public async Task ScrobbleTest()
        {
            // given: mocks
            string artistSearchText = "TestArtist";

            Mock <IExtendedWindowManager> windowManagerMock = new Mock <IExtendedWindowManager>(MockBehavior.Strict);

            IEnumerable <LastArtist> artists = TestHelper.CreateGenericArtists(3);
            IEnumerable <LastAlbum>  albums  = TestHelper.CreateGenericAlbums(3);

            Mock <IArtistApi> artistAPIMock = new Mock <IArtistApi>(MockBehavior.Strict);

            artistAPIMock.Setup(a => a.SearchAsync(artistSearchText, It.IsAny <int>(), It.IsAny <int>()))
            .Returns(Task.Run(() => PageResponse <LastArtist> .CreateSuccessResponse(artists)));
            artistAPIMock.Setup(a => a.GetTopAlbumsAsync(artists.First().Name, It.IsAny <bool>(), It.IsAny <int>(), It.IsAny <int>()))
            .Returns(Task.Run(() => PageResponse <LastAlbum> .CreateSuccessResponse(albums)));

            DateTime        scrobbleTime      = DateTime.Now;
            List <Scrobble> expectedScrobbles = new List <Scrobble>();

            for (int i = 0; i < 3; i++)
            {
                // -3 minutes because that is the default if the song has no duration
                expectedScrobbles.Add(new Scrobble("TestArtist", "TestAlbum", "TestTrack", scrobbleTime.Subtract(TimeSpan.FromMinutes(i * 3))));
            }

            LastAlbum albumToScrobble = albums.First();

            albumToScrobble.Tracks = expectedScrobbles.ToLastTracks();

            Mock <IAlbumApi> albumAPIMock = new Mock <IAlbumApi>(MockBehavior.Strict);

            albumAPIMock.Setup(a => a.GetInfoAsync(albums.First().ArtistName, albums.First().Name, It.IsAny <bool>(), It.IsAny <string>()))
            .Returns(Task.Run(() => LastResponse <LastAlbum> .CreateSuccessResponse(albumToScrobble)));

            IEnumerable <Scrobble> actual        = null;
            Mock <IUserScrobbler>  scrobblerMock = new Mock <IUserScrobbler>(MockBehavior.Strict);

            scrobblerMock.Setup(u => u.ScrobbleAsync(It.IsAny <IEnumerable <Scrobble> >(), false)).Callback <IEnumerable <Scrobble>, bool>((s, c) => actual = s)
            .Returns(Task.Run(() => new ScrobbleResponse()));
            scrobblerMock.Setup(u => u.IsAuthenticated).Returns(true);

            var discocsClientMock = new Mock <IDiscogsDataBaseClient>(MockBehavior.Strict);

            var vm = new DatabaseScrobbleViewModel(windowManagerMock.Object, artistAPIMock.Object, albumAPIMock.Object, discocsClientMock.Object)
            {
                DatabaseToSearch = Database.LastFm,
                Scrobbler        = scrobblerMock.Object,
                SearchType       = SearchType.Artist,
                SearchText       = artistSearchText,
            };

            vm.ScrobbleTimeVM.UseCurrentTime = false;
            vm.ScrobbleTimeVM.Time           = scrobbleTime;

            // when searching and scrobbling
            await vm.Search();

            // now we should have artists
            // we "click" the first one, this should trigger the album search
            (vm.ActiveItem as ArtistResultViewModel).Items.First().Clicked();

            // now we should have albums
            // we "click" the first one, this should trigger the tracklist fetching
            (vm.ActiveItem as ReleaseResultViewModel).Items.First().Clicked();

            vm.CheckAll();
            await vm.Scrobble();

            // then: correct items where scrobbles
            Assert.That(actual.IsEqualScrobble(expectedScrobbles), Is.True);
        }