public async ValueTask <MuzlanResponse <IList <AlbumRecord> > > FindAlbums(string artist, CancellationToken token = default) { var pageUri = new Uri($"https://{_baseUri.DnsSafeHost}/artist/{Uri.EscapeDataString(artist)}/all-albums"); try { var content = await _client.TryGetStringAsync(pageUri, token).ConfigureAwait(false); using var document = await _parser.ParseDocumentAsync(content, token).ConfigureAwait(false); var albums = new List <AlbumRecord>(); foreach (var item in document.QuerySelectorAll <IHtmlDivElement>("div.page-content div.row div.item")) { var mediaImage = item.QuerySelector <IHtmlImageElement>("div.item-media a.item-media-content img"); var mediaTitle = item.QuerySelector <IHtmlAnchorElement>("div.item-info div.item-title a"); var imageUri = new Uri($"https://{_baseUri.DnsSafeHost}{mediaImage.Dataset["original"]}"); var albumName = mediaTitle.Text.Trim(); var albumUri = new Uri($"https://{_baseUri.DnsSafeHost}{mediaTitle.PathName}"); var album = new AlbumRecord(artist, albumName, albumUri, imageUri); albums.Add(album); } return(MuzlanResponse <IList <AlbumRecord> > .FromResult(albums, pageUri)); } catch (Exception ex) { return(MuzlanResponse <IList <AlbumRecord> > .FromException(ex, pageUri)); } }
private async Task InitializeRecords() { var testAlbum = new AlbumRecord { IsShowcased = true, UserId = _testQuery.UserId.GetValueOrDefault() }; var testBook = new BookRecord { IsShowcased = true, UserId = _testQuery.UserId.GetValueOrDefault() }; var testGame = new GameRecord { IsShowcased = true, UserId = _testQuery.UserId.GetValueOrDefault() }; var testMovie = new MovieRecord { IsShowcased = true, UserId = _testQuery.UserId.GetValueOrDefault() }; await _context.AlbumRecords.AddAsync(testAlbum); await _context.BookRecords.AddAsync(testBook); await _context.GameRecords.AddAsync(testGame); await _context.MovieRecords.AddAsync(testMovie); await _context.SaveChangesAsync(); }
internal Album(AlbumRecord record, PhotoDatabase db) { this.record = record; photos = new List<Photo> (); foreach (AlbumItemRecord item in record.Items) { Photo photo = db.LookupPhotoById (item.Id); photos.Add (photo); } }
public AlbumIncrementPlayCountCommandHandlerTests() { _fixture = new Fixture(); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _context = InitializeDatabase(); _testCommand = _fixture.Create <AlbumIncrementPlayCountCommand>(); _testRecord = _fixture .Build <AlbumRecord>() .With(a => a.Id, _testCommand.AlbumId) .With(a => a.UpdatedOn, DateTimeOffset.UtcNow) .With(a => a.User, _testCommand.User) .With(a => a.UserId, _testCommand.User.Id) .Create(); _handler = new AlbumIncrementPlayCountCommandHandler(_context); }
public AlbumUpdateCommandHandlerTests() { _fixture = new Fixture(); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _context = InitializeDatabase(); _testCommand = CreateTestCommand( Guid.NewGuid(), CompletionStatusReference.Completed, false, false, 1, Guid.NewGuid()); var checkout = _fixture .Build <CheckoutRecord>() .With(c => c.ModifiedOn, DateTimeOffset.UtcNow) .Create(); var itemStorage = _fixture .Build <ItemStorageRecord>() .With(a => a.ModifiedOn, DateTimeOffset.UtcNow) .Create(); _testAlbum = _fixture .Build <AlbumRecord>() .With(a => a.Id, _testCommand.AlbumId) .With(a => a.Artist, _testCommand.Artist) .With(a => a.Checkout, checkout) .With(a => a.UpdatedOn, DateTimeOffset.UtcNow) .With(a => a.ItemStorage, itemStorage) .With(a => a.MediaType, _testCommand.MediaType) .With(a => a.TimesCompleted, 1) .With(a => a.Title, _testCommand.Title) .With(a => a.User, _testCommand.User) .With(a => a.UserId, _testCommand.User.Id) .Create(); _handler = new AlbumUpdateCommandHandler(_context); }
public async Task Handler_Does_Not_Add_Record_With_Same_Artist_Media_Type_And_Title_For_User() { var existingAlbum = new AlbumRecord { Artist = _testCommand.Artist, MediaType = _testCommand.MediaType, Title = _testCommand.Title, UserId = _testCommand.User.Id }; await _context.Albums.AddAsync(existingAlbum); await _context.SaveChangesAsync(); await _handler.Handle(_testCommand); var album = await _context.Albums.CountAsync(a => a.Artist == _testCommand.Artist && a.MediaType == _testCommand.MediaType && a.Title == _testCommand.Title && a.UserId == _testCommand.User.Id); album.Should().Be(1); }
public AlbumListGetQueryHandlerTests() { _fixture = new Fixture(); _fixture.Behaviors.Add(new OmitOnRecursionBehavior()); _context = InitializeDatabase(); _testQuery = new AlbumListGetQuery(13, 0, string.Empty, _fixture.Create <ApplicationUser>()); _albumRecords = _fixture .Build <AlbumRecord>() .With(album => album.User, _testQuery.User) .With(album => album.UserId, _testQuery.User.Id) .CreateMany(); _testRecord = _fixture .Build <AlbumRecord>() .With(album => album.User, _testQuery.User) .With(album => album.UserId, _testQuery.User.Id) .Create(); _handler = new AlbumListGetQueryHandler(_context); }