public async Task NormalScrobbleTest()
        {
            // given: CSVScrobbleViewModel with needed mocks to scrobble
            IEnumerable <Scrobble> actual = null;
            var 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 expected = new List <Scrobble>()
            {
                new Scrobble("TestArtist", "TestAlbum", "TestTrack", DateTime.Now)
                {
                    AlbumArtist = "TestAlbumArtist", Duration = TimeSpan.FromSeconds(30)
                },
                new Scrobble("TestArtist2", "TestAlbum2", "TestTrack2", DateTime.Now.AddSeconds(1))
                {
                    AlbumArtist = "TestAlbumArtist2", Duration = TimeSpan.FromSeconds(31)
                },
                new Scrobble("TestArtist3", "TestAlbum3", "TestTrack3", DateTime.Now.AddSeconds(2))
                {
                    AlbumArtist = "TestAlbumArtist2", Duration = TimeSpan.FromSeconds(0)
                }
            };

            var parserFactoryMock = new Mock <IFileParserFactory>(MockBehavior.Strict);

            var csvParserMock = new Mock <IFileParser>(MockBehavior.Strict);

            csvParserMock.Setup(p => p.Parse(It.IsAny <string>(), It.IsAny <TimeSpan>(), It.IsAny <ScrobbleMode>())).Returns(
                new FileParseResult(expected.Select(i => new DatedScrobble(i)), Enumerable.Empty <string>()));

            parserFactoryMock.Setup(p => p.CreateCSVFileParser()).Returns(csvParserMock.Object);

            var jsonParserMock = new Mock <IFileParser>(MockBehavior.Strict);

            parserFactoryMock.Setup(p => p.CreateJSONFileParser()).Returns(jsonParserMock.Object);

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

            FileParseScrobbleViewModel vm = new FileParseScrobbleViewModel(windowManagerMock.Object, parserFactoryMock.Object, fileOperatorMock.Object)
            {
                Scrobbler    = scrobblerMock.Object,
                FilePath     = "C:\\TestFile.csv",
                ScrobbleMode = ScrobbleMode.Normal
            };

            await vm.ParseFile();

            vm.CheckAll();

            // when: scrobbling
            await vm.Scrobble();

            // then: expected tracks scrobbled
            Assert.That(actual.IsEqualScrobble(expected));
        }
        /// <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);
        }
Example #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 });
        }