public void LoadValidIdTest() { ICRUDTestDBContextProvider functionalCRUDTestDBContextProvider = new FunctionalCRUDTestDBContextProvider(); AlbumBE albumBE = new AlbumBE(functionalCRUDTestDBContextProvider); albumBE.Load(1); Assert.IsTrue(albumBE.Id == 1); Assert.IsTrue(albumBE.Title == "For Those About To Rock We Salute You"); Assert.IsTrue(albumBE.ArtistId == 1); Assert.IsTrue(albumBE.ArtistName == "AC/DC"); AlbumBE albumBE2 = new AlbumBE(functionalCRUDTestDBContextProvider); albumBE2.Load(2); Assert.IsTrue(albumBE2.Id == 2); Assert.IsTrue(albumBE2.Title == "Balls to the Wall"); Assert.IsTrue(albumBE2.ArtistId == 2); Assert.IsTrue(albumBE2.ArtistName == "Accept"); AlbumBE albumBE3 = new AlbumBE(functionalCRUDTestDBContextProvider); albumBE3.Load(3); Assert.IsTrue(albumBE3.Id == 3); Assert.IsTrue(albumBE3.Title == "Restless and Wild"); Assert.IsTrue(albumBE3.ArtistId == 2); Assert.IsTrue(albumBE3.ArtistName == "Accept"); }
public void Delete(int id) { AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.Load(id); albumBE.Delete(); }
public void SaveValidIdTest() { ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString()); var context = cRUDTestDBContextProvider.GetContext(); var album = new Album { Title = "TestAlbumTitle", AlbumId = 1 }; context.Add(album); context.SaveChanges(); AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.Load(1); albumBE.Title = "TestAlbumTitleChanged"; albumBE.Save(); AlbumBE albumBE2 = new AlbumBE(cRUDTestDBContextProvider); albumBE2.Load(1); Assert.IsTrue(albumBE2.Id == 1); Assert.IsTrue(albumBE2.Title == "TestAlbumTitleChanged"); }
public void TrackCountTest() { ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString()); var context = cRUDTestDBContextProvider.GetContext(); var album = new Album { Title = "TestAlbumTitle", AlbumId = 1 }; var track = new Track { TrackId = 1, AlbumId = 1, Name = "TestTrackName" }; context.Add(album); context.Add(track); context.SaveChanges(); AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.Load(1); Assert.IsTrue(albumBE.TrackCount == 1); TrackBE trackBE = new TrackBE(cRUDTestDBContextProvider); trackBE.New(); trackBE.Name = "TestName"; albumBE.AddToTrack(trackBE); trackBE.Save(); AlbumBE albumBE2 = new AlbumBE(cRUDTestDBContextProvider); albumBE2.Load(1); Assert.IsTrue(albumBE2.TrackCount == 2); }
public void AddToTrackTest() { ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString()); var context = cRUDTestDBContextProvider.GetContext(); var album = new Album { Title = "TestAlbumTitle", AlbumId = 1 }; var track = new Track { TrackId = 1, Name = "TestTrackName" }; context.Add(album); context.Add(track); context.SaveChanges(); TrackBE trackBE = new TrackBE(cRUDTestDBContextProvider); AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.Load(1); trackBE.Load(1); albumBE.AddToTrack(trackBE); trackBE.Save(); albumBE.Load(1); var TrackBECollection = albumBE.GetTracks(); Assert.IsTrue(TrackBECollection.First().Id == 1); Assert.IsTrue(TrackBECollection.First().AlbumId == 1); }
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 AddToAlbumTest() { ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString()); var context = cRUDTestDBContextProvider.GetContext(); var artist = new Artist { ArtistId = 1 }; var album = new Album { AlbumId = 1, Title = "TestAlbumTitle" }; context.Add(artist); context.Add(album); context.SaveChanges(); AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); ArtistBE artistBE = new ArtistBE(cRUDTestDBContextProvider); artistBE.Load(1); albumBE.Load(1); artistBE.AddToAlbum(albumBE); albumBE.Save(); artistBE.Load(1); var AlbumBECollection = artistBE.GetAlbums(); Assert.IsTrue(AlbumBECollection.First().Id == 1); Assert.IsTrue(AlbumBECollection.First().ArtistId == 1); }
public void LoadValidIdTest() { ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString()); var context = cRUDTestDBContextProvider.GetContext(); var album = new Album { Title = "TestAlbumTitle", AlbumId = 1, ArtistId = 1 }; var artist = new Artist { ArtistId = 1, Name = "TestArtistName" }; var album2 = new Album { Title = "TestAlbumTitle", AlbumId = 2 }; var album3 = new Album { Title = "TestAlbumTitle", AlbumId = 3, ArtistId = 2 }; var artist2 = new Artist { ArtistId = 2 }; context.Add(album); context.Add(artist); context.Add(album2); context.Add(album3); context.Add(artist2); context.SaveChanges(); AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.Load(1); Assert.IsTrue(albumBE.Id == 1); Assert.IsTrue(albumBE.Title == "TestAlbumTitle"); Assert.IsTrue(albumBE.ArtistId == 1); Assert.IsTrue(albumBE.ArtistName == "TestArtistName"); AlbumBE albumBE2 = new AlbumBE(cRUDTestDBContextProvider); albumBE2.Load(2); Assert.IsTrue(albumBE2.Id == 2); Assert.IsTrue(albumBE2.Title == "TestAlbumTitle"); AlbumBE albumBE3 = new AlbumBE(cRUDTestDBContextProvider); albumBE3.Load(3); Assert.IsTrue(albumBE3.Id == 3); Assert.IsTrue(albumBE3.Title == "TestAlbumTitle"); Assert.IsTrue(albumBE3.ArtistId == 2); }
public AlbumBEDTO GetAlbum(int id) { AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.Load(id); AlbumBEDTO albumBEDTO = mapper.Map <AlbumBE, AlbumBEDTO>(albumBE); return(albumBEDTO); }
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 Put([FromBody] AlbumBEDTO albumBEDTO) { AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.Load(albumBEDTO.Id); mapper.Map <AlbumBEDTO, AlbumBE>(albumBEDTO, albumBE); if (ModelState.IsValid) { albumBE.Save(); } }
public static List<AlbumBE> GetAlbums() { MusicAppContext Context = GetMusicAppContext(); List<AlbumBE> AllAlbums = new List<AlbumBE>(); foreach (Album item in Context.Albums) { AlbumBE NewAlbum = new AlbumBE(item); AllAlbums.Add(NewAlbum); } return AllAlbums; }
public void ToStringTest() { ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString()); var context = cRUDTestDBContextProvider.GetContext(); var album = new Album { Title = "TestAlbumTitle", AlbumId = 1 }; context.Add(album); context.SaveChanges(); AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.Load(1); Assert.IsTrue(albumBE.ToString().Equals("Album Title: TestAlbumTitle")); }
public void GetTracksTest() { ICRUDTestDBContextProvider cRUDTestDBContextProvider = new CRUDTestDBContextProvider(Guid.NewGuid().ToString()); var context = cRUDTestDBContextProvider.GetContext(); var album = new Album { Title = "TestAlbumTitle", AlbumId = 1 }; var album2 = new Album { Title = "TestAlbumTitle", AlbumId = 2 }; var track = new Track { TrackId = 1, AlbumId = 1, Name = "TestTrackName" }; context.Add(album); context.Add(album2); context.Add(track); context.SaveChanges(); AlbumBE albumBE = new AlbumBE(cRUDTestDBContextProvider); albumBE.Load(1); AlbumBE albumBE2 = new AlbumBE(cRUDTestDBContextProvider); albumBE2.Load(2); var TrackBECollection = albumBE.GetTracks(); Assert.IsTrue(TrackBECollection.First().GetType() == typeof(TrackBE)); Assert.IsTrue(TrackBECollection.First().Name == "TestTrackName"); Assert.IsTrue(TrackBECollection.First().Id == 1); Assert.IsTrue(albumBE2.GetTracks().IsNullOrEmpty()); }
private AlbumBEDTO AsDtos(AlbumBE albumBE) { return(mapper.Map <AlbumBE, AlbumBEDTO>(albumBE)); }