public void AlbumCountTest() { ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString()); var context = cRUDTestDBContextProvider.GetContext(); var artist = new Artist { ArtistId = 1 }; var album = new Album { AlbumId = 1, ArtistId = 1, Title = "TestAlbumTitle" }; context.Add(artist); context.Add(album); context.SaveChanges(); ArtistBE artistBE = new ArtistBE(cRUDTestDBContextProvider); artistBE.Load(1); Assert.IsTrue(artistBE.AlbumCount == 1); AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.New(); albumBE.Title = "TestAlbumTitle"; artistBE.AddToAlbum(albumBE); albumBE.Save(); ArtistBE artistBE2 = new ArtistBE(cRUDTestDBContextProvider); artistBE2.Load(1); Assert.IsTrue(artistBE2.AlbumCount == 2); }
public void SaveWithoutIdTest() { ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString()); AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.New(); albumBE.Title = "TestAlbumTitle"; albumBE.Save(); Assert.IsTrue(albumBE.Id != default); }
public void Post([FromBody] AlbumBEDTO albumBEDTO) { AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.New(); mapper.Map <AlbumBEDTO, AlbumBE>(albumBEDTO, albumBE); if (ModelState.IsValid) { albumBE.Save(); } }