/// <summary> /// Initializes new instance of <see cref="CommonViewItemModel"/> from artist entity. /// </summary> /// <param name="artist">Instance of <see cref="DbArtist"/>.</param> public CommonViewItemModel(DbArtist artist) { if (artist == null) { throw new ArgumentNullException(nameof(artist)); } Type = CommonItemType.Artist; Title = artist.Name ?? "Artist"; InternalDbEntityId = artist.Id; ExtendedArtistName = artist.Name; var songsCount = artist.FileCount; var albumCount = artist.AlbumCount; if (songsCount > 0 && albumCount > 0) { Content = string.Format(CommonSharedStrings.ArtistSubtitleFormat, albumCount, songsCount); } else if (songsCount > 0) { Content = string.Format(CommonSharedStrings.ArtistSubtitleFallbackFormat2, songsCount); } else { Content = CommonSharedStrings.ArtistSubtitleFallbackFormat; } Genre = ReleaseDate = string.Empty; ImagePath = ImageHash = artist.ImagePath; ExtendedFilePath = string.Empty; DatabaseItemAddedDate = artist.DatabaseItemAddedDate; }
/// <summary> /// Load artist online data. /// </summary> /// <param name="elem"></param> /// <returns></returns> private async Task LoadArtistOnlineContentAsync(DbArtist elem) { // Check internet connection if (InternetConnectivityDetector.HasInternetConnection) { // Load Online content try { var modifyFlag = false; if (string.IsNullOrEmpty(elem.Intro)) { elem = await elem.LoadOnlineArtistInfoAsync(); modifyFlag = !string.IsNullOrEmpty(elem.Intro); } if (!modifyFlag) { return; } ArtistBio = elem.Intro; await CommitOnlineData(elem); } catch (Exception ex) { TelemetryHelper.TrackExceptionAsync(ex); } } }
/// <summary> /// Load online information for a specific artist. /// </summary> /// <param name="artist"></param> /// <returns></returns> public static async Task <DbArtist> LoadOnlineArtistInfoAsync(this DbArtist artist) { if (artist == null) { throw new ArgumentNullException(nameof(artist)); } if (InternetConnectivityDetector.HasInternetConnection) { try { if (string.IsNullOrEmpty(artist.Intro)) { artist = await artist.LoadArtistIntroAsync(); } return(artist); } catch (Exception ex) { TelemetryHelper.TrackExceptionAsync(ex); return(artist); } } return(artist); }
async Task <List <DbArtist> > IndexArtistsAsync( IEnumerable <string> artists, Dictionary <string, DbArtist> artistsCache) { var artistsDelta = new List <DbArtist>(); foreach (var a in artists) { // Empty Artist: Ignore artist relationship if (string.IsNullOrEmpty(a) || artistsCache.ContainsKey(a)) { continue; } var dbA = new DbArtist { Name = a }; m_dbContext.Artists.Add(dbA); artistsCache.Add(a, dbA); artistsDelta.Add(dbA); } await m_dbContext.SaveChangesAsync(); return(artistsDelta); }
public Album Insert(CreateAlbum value) { using (var tran = db.Database.BeginTransaction(System.Data.IsolationLevel.RepeatableRead)) { if (db.Albums.Any(t => EF.Functions.Like(t.Title, value.Title))) { throw new ArgumentException("name must be unique"); } DbGenre genre; if (db.Genres.Any(s => EF.Functions.Like(s.Name, value.Genre))) { genre = db.Genres.FirstOrDefault(s => EF.Functions.Like(s.Name, value.Genre)); } else { var toInsert2 = new DbGenre() { Name = value.Genre }; db.Genres.Add(toInsert2); db.SaveChanges(); genre = toInsert2; } DbArtist artist; if (db.Artists.Any(s => EF.Functions.Like(s.Name, value.Artist))) { artist = db.Artists.FirstOrDefault(s => EF.Functions.Like(s.Name, value.Artist)); } else { var toInsert2 = new DbArtist() { Name = value.Artist }; db.Artists.Add(toInsert2); db.SaveChanges(); artist = toInsert2; } var toInsert = new DbAlbum() { Title = value.Title, ArtistId = artist.Id, GenreId = genre.Id }; db.Albums.Add(toInsert); db.SaveChanges(); tran.Commit(); return(FindById(toInsert.Id)); } }
public void MapToDetailRep_HasExpectedBioImageUrl_WithValidInput() { DbArtist sourceObj = _validDbArtist; sourceObj.BioImageId = 1515; ArtistMapper mapper = new ArtistMapper(); ArtistDetail result = mapper.MapToDetailRep(_validDbArtist); Assert.Equal("/api/image/1515", result.BioImageUrl); }
public void MapToDetailRep_HasNullBioImageId_WithNullInput() { DbArtist sourceObj = _validDbArtist; sourceObj.BioImageId = null; ArtistMapper mapper = new ArtistMapper(); ArtistDetail result = mapper.MapToDetailRep(_validDbArtist); Assert.Null(result.BioImageId); }
/// <summary> /// Share an artist. /// </summary> /// <param name="artist">The artist to be shared.</param> public static void Share(this DbArtist artist) { if (artist != null) { var shareService = ShareServices.GetForCurrentView(); shareService.PrecleanForSession(); shareService.SetArtistContent(artist); shareService.ShowShareUI(); } }
/// <summary> /// Helper that verifies and creates new instance of <see cref="CommonViewItemModel"/> from artist entity. /// </summary> /// <param name="artist">Instance of <see cref="DbArtist"/>.</param> /// <returns>Instance of <see cref="CommonViewItemModel"/>. Will return null if given artist has null or empty name.</returns> public static CommonViewItemModel CreateFromDbArtistAndCheck(DbArtist artist) { if (string.IsNullOrEmpty(artist?.Name)) { return(null); } else { return(new CommonViewItemModel(artist)); } }
private async Task <DbArtist> CreateArtist(string name, string bioText, string[] genres, string bioImagePath) { foreach (string genre in genres) { await this.CreateGenre(genre); } var existing = await this._context.Artists.FirstOrDefaultAsync(a => a.Name == name); if (existing != null) { return(existing); } var artist = new DbArtist() { Name = name, BioText = bioText, CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow, PublishStatus = DbPublishedStatus.PUBLISHED }; foreach (string genre in genres) { var dbGenre = await _context.Genres.FirstAsync(x => x.Name == genre); if (dbGenre != null) { artist.ArtistGenres.Add(new DbArtistGenre() { Genre = dbGenre, CreatedUtc = DateTime.UtcNow }); } } if (!string.IsNullOrWhiteSpace(bioImagePath)) { string fullPath = Path.Combine(Directory.GetCurrentDirectory(), bioImagePath); if (File.Exists(fullPath)) { artist.BioImage = new DbImageResource() { Data = File.ReadAllBytes(fullPath), MimeType = "image/png" }; } } _context.Artists.Add(artist); await _context.SaveChangesAsync(); return(artist); }
public static async void Shuffle(this DbArtist artist) { if (artist?.MediaFiles != null) { var random = new Random(); var shuffledFiles = artist.MediaFiles .OrderBy(file => random.Next()) .Select(file => MusicPlaybackItem.CreateFromMediaFile(file)); PlaybackControl.Instance.Clear(); await PlaybackControl.Instance.AddFile(shuffledFiles.ToList(), -1); } }
public void MapToDetailRep_HasPublishedStatus_WithValidInput(DbPublishedStatus publishedStatusTestCase) { DbArtist sourceObj = _validDbArtist; sourceObj.PublishStatus = publishedStatusTestCase; PublishedStatusEnumMapper statusMapper = new PublishedStatusEnumMapper(); ArtistMapper mapper = new ArtistMapper(); PublishStatus expetedStatus = statusMapper.Map(publishedStatusTestCase); ArtistDetail result = mapper.MapToDetailRep(sourceObj); ICollection <string> dbGenres = _validDbArtist.ArtistGenres.Select(x => x.Genre.Name).ToList(); Assert.Equal(expetedStatus, result.PublishedStatus); }
public SearchResultModel(DbArtist artist) { Entity = artist; Title = artist.Name; Artist = artist.Name; Subtitle = CommonSharedStrings.ArtistText; ItemType = CommonItemType.Artist; HasThumbnail = true; Thumbnail = new ThumbnailTag { ArtistName = artist.Name, Fallback = "Artist,ArtistPlaceholder" }; }
/// <summary> /// Play all songs by a specific artist. /// </summary> /// <param name="artist"></param> /// <param name="requireClear"></param> /// <param name="isInsert"></param> public static async void Play(this DbArtist artist, bool requireClear = false, bool isInsert = false) { if (artist?.MediaFiles != null) { var sortedFiles = artist.MediaFiles .OrderBy(file => file.Title, new AlphabetAscendComparer()) .Select(file => MusicPlaybackItem.CreateFromMediaFile(file)); if (requireClear) { PlaybackControl.Instance.Clear(); } await PlaybackControl.Instance.AddFile(sortedFiles.ToList(), isInsert? -2 : -1); } }
public async Task LoadTitleAsync(bool artistFallbackLarge = false) { _backendArtist = await _itemId.GetArtistByIdAsync(); if (_backendArtist == null) { return; } ArtistBio = !string.IsNullOrEmpty(_backendArtist.Intro) ? _backendArtist.Intro : string.Empty; ArtistName = _backendArtist.Name; BackgroundImageTag = new ThumbnailTag { Fallback = artistFallbackLarge ? "Artist,DefaultArtistLarge" : "Artist,ArtistPlaceholder", ArtistName = _backendArtist.Name, }; }
public async Task <ArtistDetail> AddAsync(Artist artist) { PublishedStatusEnumMapper statusMapper = new PublishedStatusEnumMapper(); var newArtistEntity = new DbArtist() { CreatedUtc = DateTime.Now, UpdatedUtc = DateTime.Now, Name = artist.Name, BioText = artist.BioText, PublishStatus = statusMapper.Map(artist.PublishedStatus) }; foreach (string genre in artist.Genres) { var dbGenre = await _context.Genres.SingleOrDefaultAsync(x => x.Name == genre); if (dbGenre != null) { newArtistEntity.ArtistGenres.Add((new DbArtistGenre() { Genre = dbGenre })); } else { throw new RepositoryException($"The supplied genre '{genre}' does not exist."); } } if (artist.BioImageId.HasValue) { var img = await this._context.ImageResources.SingleOrDefaultAsync(x => x.Id == artist.BioImageId.Value); if (img != null) { newArtistEntity.BioImage = img; } else { throw new RepositoryException($"Invalid {nameof(artist.BioImageId)}, no image for ID"); } } this._context.Artists.Add(newArtistEntity); await this._context.SaveChangesAsync(); return(_mapper.MapToDetailRep(newArtistEntity)); }
/// <summary> /// Load artist intro for a specific artist. /// </summary> /// <param name="elem"></param> /// <returns></returns> public static async Task <DbArtist> LoadArtistIntroAsync(this DbArtist elem) { if (InternetConnectivityDetector.HasInternetConnection) { try { var bio = await GrooveMusicMetadata.GetArtistBio(elem.Name); elem.Intro = bio; } catch (Exception ex) { TelemetryHelper.TrackExceptionAsync(ex); } } return(elem); }
/// <summary> /// Load online content for a specific artist. /// </summary> /// <param name="elem"></param> /// <returns></returns> public static async Task <string> LoadArtistOnlineContentAsync(this DbArtist elem) { // Check internet connection if (InternetConnectivityDetector.HasInternetConnection) { // Return Online content try { var modifyFlag = false; if (string.IsNullOrEmpty(elem.Intro)) { var bio = await GrooveMusicMetadata.GetArtistBio(elem.Name); if (!string.IsNullOrEmpty(bio)) { modifyFlag = true; } } if (modifyFlag) { using (var scope = ApplicationServiceBase.App.GetScope()) using (var context = scope.ServiceProvider.GetRequiredService <MedialibraryDbContext>()) { context.Entry(elem).Entity.ImagePath = elem.ImagePath; context.Entry(elem).Entity.Intro = elem.Intro; context.Entry(elem).State = EntityState.Modified; await context.SaveChangesAsync(); } return(elem.ImagePath); } } catch (Exception ex) { TelemetryHelper.TrackExceptionAsync(ex); } } return(string.Empty); }
public Artist Insert(CreateArtist value) { using (var tran = db.Database.BeginTransaction(System.Data.IsolationLevel.RepeatableRead)) { if (db.Artists.Any(t => EF.Functions.Like(t.Name, value.Name))) { throw new ArgumentException("name must be unique"); } var toInsert = new DbArtist() { Name = value.Name }; db.Artists.Add(toInsert); db.SaveChanges(); tran.Commit(); return(ToModel(toInsert)); } }
public ArtistDetail MapToDetailRep(DbArtist a) { PublishedStatusEnumMapper statusMapper = new PublishedStatusEnumMapper(); if (a == null) { throw new NullReferenceException($"A null value was passed to the mapper. Expected an object of type {nameof(DbArtist)}"); } return(new ArtistDetail { Id = a.Id, Name = a.Name, BioText = a.BioText, BioImageId = a.BioImageId, BioImageUrl = (a.BioImageId.HasValue ? $"/api/image/{a.BioImageId.Value}" : null), Genres = a.ArtistGenres.Select(g => g.Genre.Name).ToList(), CreatedUtc = new DateTime(a.CreatedUtc.Ticks, DateTimeKind.Utc), UpdatedUtc = new DateTime(a.UpdatedUtc.Ticks, DateTimeKind.Utc), PublishedStatus = statusMapper.Map(a.PublishStatus) }); }
public AlbumRepositoryTests() { // set up test data var options = new DbContextOptionsBuilder <MusicStoreDbContext>() .UseInMemoryDatabase(databaseName: "test_db" + Guid.NewGuid().ToString()) .Options; this.db = new MusicStoreDbContext(options); foreach (string g in _validGenres) { this.db.Genres.Add(new DbGenre { Name = g, CreatedUtc = DateTime.UtcNow }); } var imageResource = new DbImageResource() { MimeType = "img/png", Data = new byte[10] }; var artist = new DbArtist { BioText = "", CreatedUtc = DateTime.UtcNow, Name = "test artist", PublishStatus = DbPublishedStatus.PUBLISHED, UpdatedUtc = DateTime.UtcNow }; db.ImageResources.Add(imageResource); db.Artists.Add(artist); db.SaveChanges(); _validImageId = imageResource.Id; _validArtistId = artist.Id; var loggerMock = new Mock <ILogger <ArtistController> >(); this.repo = new AlbumRepository(this.db, new AlbumMapper()); }
public ArtistMapperTests() { ICollection <DbArtistGenre> artistGenres = (new List <string> { "genre1", "genre2", "genre3" }).Select(x => new DbArtistGenre { Genre = new DbGenre() { Name = x, CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow } }).ToList(); DbArtist artist = new DbArtist() { Id = 44, Name = "SampleName", BioText = "SampleText", CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow, PublishStatus = DbPublishedStatus.PUBLISHED, }; // artist genres is a virtual readonly property mock this property // and manualy set the rest of the values on the resulting object var stub = new Mock <DbArtist>(); stub.SetupGet(x => x.ArtistGenres).Returns(artistGenres); stub.Object.Id = 44; stub.Object.Name = "SampleName"; stub.Object.BioText = "SampleText"; stub.Object.CreatedUtc = DateTime.UtcNow; stub.Object.UpdatedUtc = DateTime.UtcNow; stub.Object.PublishStatus = DbPublishedStatus.PUBLISHED; _validDbArtist = stub.Object; }
/// <summary> /// Write online data into database. /// </summary> /// <param name="elem"></param> /// <returns></returns> private async Task CommitOnlineData(DbArtist elem) { using (var scope = ApplicationServiceBase.App.GetScope()) using (var context = scope.ServiceProvider.GetRequiredService <MedialibraryDbContext>()) { try { var query = context.Artists.Where(i => i.Id == elem.Id); if (query.Any()) { var item = query.FirstOrDefault(); context.Entry(item).Entity.Intro = elem.Intro; // ArtistImagePath is the absoulte path on disk. context.Entry(item).Entity.ImagePath = elem.ImagePath; context.Entry(item).State = EntityState.Modified; await context.SaveChangesAsync(); } } catch (Exception ex) { TelemetryHelper.TrackExceptionAsync(ex); } } }
public async Task CreateSeedContent() { DbArtist tempArtistResult = null; tempArtistResult = await CreateArtist("Beck", "Bio text...", new string[] { "Indie", "Electronic" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Modern Guilt", description : "", genres : new string[] { "Alternative" }, producer : "Danger Mouse, Beck", label : "DGC Records", releaseDate : new DateTime(2008, 7, 8), price : 13.99, coverImagePath : "Images/Covers/Beck_ModernGuilt.jpg", tracks : new TrackStruct[] { new TrackStruct("Orphans", "3:15"), new TrackStruct("Gamma Ray", "2:57"), new TrackStruct("Chemtrails", "4:40"), new TrackStruct("Modern Guilt", "3:14"), new TrackStruct("Youthless", "3:00"), new TrackStruct("Walls", "2:22"), new TrackStruct("Replica", "3:25"), new TrackStruct("Soul of a Man", "2:36"), new TrackStruct("Profanity Prayers", "3:43"), new TrackStruct("Volcano", "4:26") }); await CreateAlbum( artistId : tempArtistResult.Id, title : "Guero", description : "", genres : new string[] { "Electronic", "Hip Hop", "Rock" }, producer : "Beck Hansen, Dust Brothers, Tony Hoffer", label : "Interscope Records", releaseDate : new DateTime(2005, 3, 21), price : 13.99, coverImagePath : "Images/Covers/beckguero.jpg", tracks : new TrackStruct[] { new TrackStruct("E-Pro", "3:22"), new TrackStruct("Qué Onda Guero", "3:29"), new TrackStruct("Girl", "3:30"), new TrackStruct("Missing", "4:44"), new TrackStruct("lack Tambourine", "2:46"), new TrackStruct("Earthquake Weather", "4:26"), new TrackStruct("Hell Yes", "3:18"), new TrackStruct("Broken Drum", "4:30"), new TrackStruct("Scarecrow", "4:16"), new TrackStruct("Go It Alone", "4:09"), new TrackStruct("Farewell Ride", "4:19"), new TrackStruct("Rental Car", "3:05"), new TrackStruct("Emergency Exit", "4:01"), new TrackStruct("Send A Message To Her", "4:28"), new TrackStruct("Chain Reaction", "3:27"), new TrackStruct("Clap Hands", "3:19") }); tempArtistResult = await CreateArtist("Fleetwood Mac", "Bio text...", new string[] { "Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Rumours", description : "", genres : new string[] { "Rock" }, producer : "Fleetwood Mac, Ken Caillat, Richard Dashut", label : "Warner Bros", releaseDate : new DateTime(1977, 2, 4), price : 13.99, coverImagePath : "Images/Covers/FMacRumours.png", tracks : new TrackStruct[] { new TrackStruct("Second Hand News", "2:56"), new TrackStruct("Dreams", "4:14"), new TrackStruct("Never Going Back Again", "2:14"), new TrackStruct("Dont Stop", "3:13"), new TrackStruct("Go Your Own Way", "3:13"), new TrackStruct("Songbird", "3:30"), new TrackStruct("The Chain", "4:30"), new TrackStruct("You Make Loving Fun", "3:31"), new TrackStruct("I Don't Want to Know", "3:15"), new TrackStruct("Oh Daddy", "3:56"), new TrackStruct("Gold Dust Woman", "4:56") }); tempArtistResult = await CreateArtist("LCD Soundsystem", "", new string[] { "Dance-Punk", "Electronica", "Electronic Rock", "Alt-Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Sound of Silver", description : "", genres : new string[] { "Dance-Punk", "Electronica", "Electronic Rock" }, producer : "DFA, Capitol, EMI", label : "The DFA", releaseDate : new DateTime(2007, 3, 12), price : 13.99, coverImagePath : "Images/Covers/SoundOfSilver.jpg", tracks : new TrackStruct[] { new TrackStruct("Get Innocuous!", "7:11"), new TrackStruct("Time to Get Away", "4:11"), new TrackStruct("North American scum", "5:25"), new TrackStruct("Someone Great", "6:25"), new TrackStruct("All My Friends", "7:37"), new TrackStruct("Us v Them", "8:29"), new TrackStruct("Watch the Tapes", "3:55"), new TrackStruct("Sound of Silver", "7:07"), new TrackStruct("New York, I Love You but You're Bringing Me Down", "5:35") }); tempArtistResult = await CreateArtist("Arcade Fire", "", new string[] { "Rock", "Indie-Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Funeral", description : "", genres : new string[] { "Indie-Rock", "Rock" }, producer : "Arcade Fire", label : "Merge", releaseDate : new DateTime(2004, 9, 14), price : 13.99, coverImagePath : "Images/Covers/afFuneral.jpg", tracks : new TrackStruct[] { new TrackStruct("Neighborhood #1 (Tunnels)", "4:48"), new TrackStruct("Neighborhood #2 (Laïka)", "3:32"), new TrackStruct("Une Année Sans Lumière", "3:41"), new TrackStruct("Neighborhood #3 (Power Out)", "5:12"), new TrackStruct("Neighborhood #4 (7 Kettles)", "4:49"), new TrackStruct("Crown Of Love", "4:42"), new TrackStruct("Wake Up", "5:35"), new TrackStruct("Haïti", "4:07"), new TrackStruct("Rebellion(Lies)", "5:12"), new TrackStruct("In The Backseat", "6:20") }); tempArtistResult = await CreateArtist("Pixies", "", new string[] { "Noise-Pop", "Alt-Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Doolittle", description : "", genres : new string[] { "Noise-Pop", "Alt-Rock" }, producer : "Gil Norton", label : "4AD, Elektra", releaseDate : new DateTime(1998, 10, 23), price : 13.99, coverImagePath : "Images/Covers/Pixies-Doolittle.jpg", tracks : new TrackStruct[] { new TrackStruct("Debaser", "2:52"), new TrackStruct("Tame", "1:55"), new TrackStruct("Wave Of Mutilation", "2:04"), new TrackStruct("I Bleed", "2:34"), new TrackStruct("Here Comes Your Man", "3:21"), new TrackStruct("Dead", "2:21"), new TrackStruct("Monkey Gone To Heaven", "2:57"), new TrackStruct("Mr.Grieves", "2:05"), new TrackStruct("Crackity Jones", "1:24"), new TrackStruct("La La Love You", "2:43"), new TrackStruct("No. 13 Baby", "3:51"), new TrackStruct("There Goes My Gun", "1:49"), new TrackStruct("Hey", "3:31"), new TrackStruct("Silver", "2:25"), new TrackStruct("Gouge Away", "2:45") }); tempArtistResult = await CreateArtist("Wilco", "", new string[] { "Alt-rock", "Indie-Rock", "Alternative country" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Yankee Hotel Foxtrot", description : "", genres : new string[] { "Alt-rock", "Indie-Rock" }, producer : "Wilco", label : "Nonesuch", releaseDate : new DateTime(1998, 10, 23), price : 13.99, coverImagePath : "Images/Covers/yankeehotelfoxtrot.jpg", tracks : new TrackStruct[] { new TrackStruct("I Am Trying To Break Your Heart", "6:57"), new TrackStruct("Kamera", "3:29"), new TrackStruct("Radio Cure ", "5:08"), new TrackStruct("War On War", "3:47"), new TrackStruct("Jesus, Etc.", "3:50"), new TrackStruct("Ashes Of American Flags", "4:43"), new TrackStruct("Heavy Metal Drummer", "3:08"), new TrackStruct("I'm The Man Who Loves You", "3:55"), new TrackStruct("Pot Kettle Black", "4:00"), new TrackStruct("Poor Places", "5:15"), new TrackStruct("Reservations", "7:22") }); await CreateAlbum( artistId : tempArtistResult.Id, title : "Sky Blue Sky", description : "", genres : new string[] { "Alt-rock", "Indie-Rock" }, producer : "Wilco", label : "Nonesuch", releaseDate : new DateTime(2007, 5, 15), price : 13.99, coverImagePath : "Images/Covers/skybluesky.jpg", tracks : new TrackStruct[] { new TrackStruct("Either Way", "3:01"), new TrackStruct("You Are My Face", "4:39"), new TrackStruct("Impossible Germany", "5:58"), new TrackStruct("Sky Blue Sky", "3:24"), new TrackStruct("Side With The Seeds", "4:16"), new TrackStruct("Shake It Off", "5:43"), new TrackStruct("Please Be Patient With Me", "3:20"), new TrackStruct("Hate It Here", "4:34"), new TrackStruct("Leave Me(Like You Found Me)", "4:11"), new TrackStruct("Walken", "4:28"), new TrackStruct("What Light ", "3:36"), new TrackStruct("On And On And On", "4:02"), }); tempArtistResult = await CreateArtist("Pearl Jam", "Bio text...", new string[] { "Grunge", "Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Ten", description : "", genres : new string[] { "Alt-rock", "Grunge" }, producer : "Rick Parashar, Pearl Jam", label : "Epic", releaseDate : new DateTime(1991, 8, 27), price : 9.99, coverImagePath : "Images/Covers/pjTen.jpg", tracks : new TrackStruct[] { new TrackStruct("Once", "3:51"), new TrackStruct("Even Flow", "4:53"), new TrackStruct("Alive", "5:40"), new TrackStruct("Why Go", "3:19"), new TrackStruct("Black", "5:43"), new TrackStruct("Jeremy", "5:18"), new TrackStruct("Oceans", "2:41"), new TrackStruct("Porch", "3:30"), new TrackStruct("Garden", "4:58"), new TrackStruct("Deep", "4:13"), new TrackStruct("Release", "5:05"), new TrackStruct("Master / Slave", "3:43"), }); tempArtistResult = await CreateArtist("Graham Coxon", "Bio text...", new string[] { "Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Love Travels At Illegal Speeds", description : "", genres : new string[] { "Rock", "Alternative Rock", "Brit Pop" }, producer : "Stephen Street", label : "Parlophone", releaseDate : new DateTime(2006, 3, 8), price : 9.99, coverImagePath : "Images/Covers/gc-ltais.jpeg", tracks : new TrackStruct[] { new TrackStruct("Standing On My Own Again", "4:29"), new TrackStruct("I Can't Look At Your Skin", "3:35"), new TrackStruct("Don't Let Your Man Know", "2:54"), new TrackStruct("Just A State Of Mind", "4:36"), new TrackStruct("You & I", "3:42"), new TrackStruct("Gimme Some Love", "2:32"), new TrackStruct("I Don't Wanna Go Out", "4:17"), new TrackStruct("Don't Believe Anything I Say", "5:26"), new TrackStruct("Tell It Like It Is", "4:02"), new TrackStruct("Flights To The Sea (Lovely Rain)", "3:25"), new TrackStruct("What's He Got?", "3:42"), new TrackStruct("You Always Let Me Down", "2:49"), new TrackStruct("See A Better Day", "5:10"), new TrackStruct("Click Click Click", "2:54"), new TrackStruct("Livin'", "3:42"), }); tempArtistResult = await CreateArtist("Yeah Yeah Yeahs", "Bio text...", new string[] { "Rock", "Electronic", "Alternative Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "It's Blitz!", description : "", genres : new string[] { "Rock", "Alternative Rock", "Electronic" }, producer : "Nick Launay, David Sitek", label : "Dress Up, DGC, Interscope", releaseDate : new DateTime(2009, 3, 6), price : 9.99, coverImagePath : "Images/Covers/itsblitz.jpeg", tracks : new TrackStruct[] { new TrackStruct("Zero", "4:26"), new TrackStruct("Heads Will Roll", "3:42"), new TrackStruct("Soft Shock", "3:53"), new TrackStruct("Skeletons", "5:02"), new TrackStruct("Dull Life", "4:08"), new TrackStruct("Shame And Fortune", "3:31"), new TrackStruct("Runaway", "5:13"), new TrackStruct("Dragon Queen", "4:02"), new TrackStruct("Hysteric", "3:52"), new TrackStruct("Little Shadow", "3:57"), }); tempArtistResult = await CreateArtist("The Flaming Lips", "Bio text...", new string[] { "Experimental", "Indie Rock", "Psychedelic Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "The Soft Bulletin", description : "", genres : new string[] { "Experimental", "Indie Rock", "Psychedelic Rock" }, producer : "Dave Fridmann", label : "Warner Bros", releaseDate : new DateTime(1999, 5, 17), price : 9.99, coverImagePath : "Images/Covers/flaminglipstsb.jpeg", tracks : new TrackStruct[] { new TrackStruct("Race For The Prize", "4:18"), new TrackStruct("A Spoonful Weighs A Ton", "3:32"), new TrackStruct("The Spark That Bled", "5:55"), new TrackStruct("Slow Motion", "3:53"), new TrackStruct("What Is The Light?", "4:05"), new TrackStruct("The Observer", "4:10"), new TrackStruct("Waitin' For A Superman", "4:17"), new TrackStruct("Suddenly Everything Has Changed", "3:54"), new TrackStruct("The Gash", "4:02"), new TrackStruct("Feeling Yourself Disintegrate", "5:17"), new TrackStruct("Sleeping On The Roof", "3:10"), new TrackStruct("Race For The Prize", "4:09"), new TrackStruct("Waitin' For A Superman", "4:19"), new TrackStruct("Buggin'", "3:16") }); tempArtistResult = await CreateArtist("Pavement", "Bio text...", new string[] { "Indie Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Crooked Rain, Crooked Rain", description : "", genres : new string[] { "Indie Rock" }, producer : "Pavement", label : "Big Cat", releaseDate : new DateTime(1999, 5, 17), price : 9.99, coverImagePath : "Images/Covers/crookedrain.jpeg", tracks : new TrackStruct[] { new TrackStruct("Silence Kit", "3:00"), new TrackStruct("Elevate Me Later", "2:51"), new TrackStruct("Stop Breathin", "4:27"), new TrackStruct("Cut Your Hair", "3:06"), new TrackStruct("Newark Wilder", "3:53"), new TrackStruct("Unfair", "2:33"), new TrackStruct("Gold Soundz", "2:39"), new TrackStruct("5-4 = Unity", "2:09"), new TrackStruct("Range Life", "4:54"), new TrackStruct("Heaven Is A Truck", "2:30"), new TrackStruct("Hit The Plane Down", "3:36"), new TrackStruct("Fillmore Jive", "6:38") }); tempArtistResult = await CreateArtist("Doves", "Bio text...", new string[] { "Indie Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Lost Souls", description : "", genres : new string[] { "Brit Pop", "Indie Rock" }, producer : "Doves; Steve Osborne", label : "Heavenly Records", releaseDate : new DateTime(2000, 5, 3), price : 9.99, coverImagePath : "Images/Covers/lostsouls.jpeg", tracks : new TrackStruct[] { new TrackStruct("Firesuite", "4:36"), new TrackStruct("Here It Comes", "4:50"), new TrackStruct("Break Me Gently", "4:38"), new TrackStruct("Sea Song", "6:12"), new TrackStruct("Rise", "5:38"), new TrackStruct("Lost Souls", "6:09"), new TrackStruct("Melody Calls", "3:27"), new TrackStruct("Catch The Sun", "4:49"), new TrackStruct("The Man Who Told Everything", "5:47"), new TrackStruct("The Cedar Room", "7:38"), new TrackStruct("Reprise", "1:45"), new TrackStruct("A House", "3:40") }); tempArtistResult = await CreateArtist("Queens of the Stone Age", "Bio text...", new string[] { "Rock", "Indie Rock" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Rated R", description : "", genres : new string[] { "Rock" }, producer : "Chris Goss, Joshua Homme", label : "Heavenly Records", releaseDate : new DateTime(2000, 6, 5), price : 9.99, coverImagePath : "Images/Covers/qotsar.jpeg", tracks : new TrackStruct[] { new TrackStruct("Feel Good Hit Of The Summer", "2:43"), new TrackStruct("The Lost Art Of Keeping A Secret", "3:36"), new TrackStruct("Leg Of Lamb", "2:48"), new TrackStruct("Auto Pilot", "4:01"), new TrackStruct("Better Living Through Chemistry", "5:49"), new TrackStruct("Monsters In The Parasol", "3:27"), new TrackStruct("Quick And To The Pointless", "1:42"), new TrackStruct("In The Fade", "3:51"), new TrackStruct("Untitled", "0:34"), new TrackStruct("Tension Head", "2:52"), new TrackStruct("Lightning Song", "2:07"), new TrackStruct("I Think I Lost My Headache", "8:40") }); tempArtistResult = await CreateArtist("The Go! Team", "Bio text...", new string[] { "Leftfield", "Abstract", "Electro", "Future Jazz" }, null); await CreateAlbum( artistId : tempArtistResult.Id, title : "Thunder, Lightning, Strike", description : "", genres : new string[] { "Leftfield", "Abstract", "Electro", "Future Jazz" }, producer : "The Go! Team, Gareth Parton", label : "Memphis Industries", releaseDate : new DateTime(2004, 9, 13), price : 9.99, coverImagePath : "Images/Covers/thunderlightningstrike.jpeg", tracks : new TrackStruct[] { new TrackStruct("Panther Dash", "2:42"), new TrackStruct("Ladyflash", "4:07"), new TrackStruct("Feelgood By Numbers", "1:56"), new TrackStruct("The Power Is On", "3:11"), new TrackStruct("Get It Together", "3:24"), new TrackStruct("Junior Kickstart", "3:30"), new TrackStruct("Air Raid Gtr", "0:41"), new TrackStruct("Bottle Rocket", "3:40"), new TrackStruct("Friendship Update", "3:58"), new TrackStruct("Huddle Formation", "3:09"), new TrackStruct("Everyone's A V.I.P. To Someone", "4:55") }); List <int> groupIds = _context.AlbumGroups.Select(x => x.Id).ToList(); // randomize the item order in each group foreach (var groupId in groupIds) { var items = _context.AlbumGroupListPositions.Where(x => x.GroupId == groupId) .AsEnumerable() .OrderBy(x => Guid.NewGuid()); int i = 1; foreach (var itm in items) { itm.PositionIndex = i; i++; } await _context.SaveChangesAsync(); } }
private Artist ToModel(DbArtist value) { return(new Artist(value.Id, value.Name)); }
public AlbumRepository_ListByAlbumGroupKeyTests() { // set up test data var options = new DbContextOptionsBuilder <MusicStoreDbContext>() .UseInMemoryDatabase(databaseName: "test_db" + Guid.NewGuid().ToString()) .Options; this.db = new MusicStoreDbContext(options); foreach (string g in _validGenres) { this.db.Genres.Add(new DbGenre { Name = g, CreatedUtc = DateTime.UtcNow }); } var imageResource = new DbImageResource() { MimeType = "img/png", Data = new byte[10] }; var artist = new DbArtist { BioText = "", CreatedUtc = DateTime.UtcNow, Name = "test artist", PublishStatus = DbPublishedStatus.PUBLISHED, UpdatedUtc = DateTime.UtcNow }; db.ImageResources.Add(imageResource); db.Artists.Add(artist); List <DbAlbum> testAlbums = new List <DbAlbum>(); for (int i = 0; i < 10; i++) { testAlbums.Add(new DbAlbum { Title = "test_album_" + i, CreatedUtc = DateTime.UtcNow, PublishStatus = DbPublishedStatus.PUBLISHED, ReleaseDate = DateTime.Now, UpdatedUtc = DateTime.UtcNow, Artist = new DbArtist { Name = "test artist " + i, PublishStatus = DbPublishedStatus.PUBLISHED, CreatedUtc = DateTime.UtcNow, UpdatedUtc = DateTime.UtcNow } }); } this.db.Albums.AddRange(testAlbums); var group = new DbAlbumGroup { CreatedUtc = DateTime.UtcNow, Key = VALID_GROUP_KEY, Name = "test group", UpdatedUtc = DateTime.UtcNow }; db.AlbumGroups.Add(group); db.SaveChanges(); _validImageId = imageResource.Id; _validArtistId = artist.Id; _validGroupId = group.Id; _validAlbumIds = testAlbums.Select(x => x.Id).ToArray(); for (int i = 0; i < _validAlbumIds.Length; i++) { // insert all albums into the test group db.AlbumGroupListPositions.Add(new DbAlbumGroupAlbumPosition { AlbumId = _validAlbumIds[i], GroupId = _validGroupId, CreatedUtc = DateTime.UtcNow, PositionIndex = i }); } db.SaveChanges(); var loggerMock = new Mock <ILogger <ArtistController> >(); this.repo = new AlbumRepository(this.db, new AlbumMapper()); }
/// <summary> /// Set content for artist. /// </summary> /// <param name="item">The artist information to be shared.</param> public void SetArtistContent(DbArtist artist) { Title = artist.Name; Description = artist.Intro ?? string.Empty; }