public void SelectsValidReleasesWithTracks() { string fileWithValues = "data/releases-artist-2pac.json"; var values = TestHelper.GetFileData(fileWithValues); var deserializeJson = new DeserializeJson <ReleaseResults>(); var releaseResults = deserializeJson.Deserialize(values); MusicStatService sut = new MusicStatService(); MusicInterpretor sut2 = new MusicInterpretor(sut); List <Release> Releases = new List <Release>(); for (int i = 0; i < releaseResults.Releases.Count; i++) { CommandFactory commandFactory = new GetTracksByReleaseIDFactory(releaseResults.Releases[i], sut); Command command = commandFactory.GetCommand(); Task t = command.ExecuteAsync(); t.ContinueWith(task => { if (task.Status == TaskStatus.RanToCompletion) { GetTracksByReleaseID getTracksByReleaseID = (GetTracksByReleaseID)command;//doesn't filter non-unique tracks Releases.Add(getTracksByReleaseID.Release); } else { Assert.False(true); } }); } var totalTracks = Releases.Where(x => (x != null && x.Media != null)).SelectMany(x => x.Media).SelectMany(x => x.Tracks).ToList(); Assert.Equal(13, Releases.Count); Assert.True(totalTracks.Count > 0);//why are we gettin random tracks back? }
public void SelectsValidReleasesWithTracksWithMultiThread() { MusicStatService sut = new MusicStatService(); MusicInterpretor sut2 = new MusicInterpretor(sut); List <Release> Releases = new List <Release>(); /* * CommandFactory commandFactory = new GetReleasesByArtistsIDFactory("382f1005-e9ab-4684-afd4-0bdae4ee37f2", sut); * Command command = commandFactory.GetCommand(); * command.ExecuteAsync().Wait(); * GetReleasesByArtistsID getTracksByReleaseID = (GetReleasesByArtistsID)command;//doesn't filter non-unique tracks * Releases = getTracksByReleaseID.ReleaseResults.Releases; * * var totalTracks = Releases.Where(x => (x != null && x.Media != null)).SelectMany(x => x.Media).SelectMany(x => x.Tracks).ToList(); * * Assert.Equal(14, Releases.Count); * Assert.True(totalTracks.Count > 0);//why are we gettin random tracks back? */ }
public static IEnumerable <object[]> GetTracksAsyncTestParams() { string artistName = "Tupac shakur"; var mockService = new Mock <IMusicStatService>(); var realService = new MusicStatService(); Func <object, string> getReleasesFileData = (object path) => { return(TestHelper.GetFileData((string)path)); }; Func <object, string> getTracksData = (object releaseID) => { Task <string> tracksTask = realService.getTracks((string)releaseID); tracksTask.Wait(); return(tracksTask.Result); }; Func <object, object, Task <string> > getTracksLyrics = (object artistName, object trackTitle) => { return(realService.getLyrics((string)artistName, (string)trackTitle)); }; mockService.Setup(mss => mss.getArtists(artistName)) .Returns(Task <string> .Factory.StartNew(getReleasesFileData, "data/artists-query-2pac.json")); mockService.Setup(mss => mss.getReleases("92a4d187-168d-4422-8d04-d194bea5da47")) .Returns(Task <string> .Factory.StartNew(getReleasesFileData, "data/releases-artist-tupac-shakur.json")); mockService.Setup(mss => mss.getReleases("382f1005-e9ab-4684-afd4-0bdae4ee37f2")) .Returns(Task <string> .Factory.StartNew(getReleasesFileData, "data/releases-artist-2pac.json")); mockService.Setup((mss) => mss.getTracks(It.IsAny <string>())) .Returns <string>((s) => Task <string> .Factory.StartNew(getTracksData, s)); mockService.Setup((mss) => mss.getLyrics(It.IsAny <string>(), It.IsAny <string>())) .Returns <string, string>(async(artistName, trackTitle) => await await Task.Factory.StartNew(() => getTracksLyrics(artistName, trackTitle))); var mock = mockService.Object; Task <string> artistsResultsTask = mock.getArtists(artistName); artistsResultsTask.Wait(); string artistsResultsJson = artistsResultsTask.Result; DeserializeJson <ArtistResults> deserializeJson = new DeserializeJson <ArtistResults>(); ArtistResults artistResults = deserializeJson.Deserialize(artistsResultsJson); var real = new MusicStatService(); yield return(new object[] { mock, artistResults.Artists[1] }); }