public void AddingNewTaskShouldBeSuccessful() { var task = _service.NewTask(TrackModel1); var result = _service.AddTask(task); Assert.IsTrue(result); var readTask = _service.GetNextTask(); try { Assert.IsNotNull(readTask); Assert.AreEqual(Artist1, readTask.Artist); Assert.AreEqual(Album1, readTask.Album); Assert.AreEqual(Track1, readTask.Track); } finally { _service.TaskDone(readTask); } }
public AlbumModel GetByIdWithTracks(long albumId) { var album = _albumRepository.GetByIdWithTracks(albumId); if (album == null) { throw new Exception($"Artist did not found by id: {albumId}"); } if (!album.Tracks.Any()) { var sourceId = int.Parse(album.SourceId); var discogsClient = CreateDiscogsClient(); var tracksForSave = new List <TrackModel>(); var sourceTracks = discogsClient.GetMasterRelease(sourceId); foreach (var sourceTrack in sourceTracks.Tracklist) { tracksForSave.Add(new TrackModel { AlbumId = album.Id, Title = sourceTrack.Title, Duration = DurationToSec(sourceTrack.Duration), Position = sourceTrack.Position } ); } _trackRepository.SaveMany(tracksForSave); } var result = _albumRepository.GetByIdWithTracks(album.Id); // create find-tasks for tracks with empty data foreach (var trackModel in result.Tracks) { if (!trackModel.TrackDatas.Any()) { var task = _findTrackService.NewTask(trackModel); _findTrackService.AddTask(task); } } return(result); }