public ArtistRepositoryTests() { // 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] }; db.ImageResources.Add(imageResource); db.SaveChanges(); _validImageId = imageResource.Id; var loggerMock = new Mock <ILogger <ArtistController> >(); this.repo = new ArtistRepository(this.db, new ArtistMapper()); }
public async Task <ImageReferenceDetail> AddAsync(ImageReferenceDetail image) { var dbImage = new DbImageResource() { CreatedUtc = DateTime.Now, UpdatedUtc = DateTime.Now, Filename = image.FileName, MimeType = image.MimeType, Data = image.Data }; this._context.ImageResources.Add(dbImage); await this._context.SaveChangesAsync(); image.Id = dbImage.Id; return(image); }
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()); }