public void TestCount() { MusicStoreEntities db = new MusicStoreEntities(); Assert.AreNotEqual(db.Artists.Count(), 0); Artists artists = new Artists(); artists.Name = "Geovane Alves Simões"; if (!db.Artists.Any(a => a.Name.Equals("Geovane Alves Simões"))) { db.Artists.Add(artists); db.SaveChanges(); } }
public void TesteAdd() { IArtistsRepository<Artists> artistsRepository = Artists.GetRepository(); if (artistsRepository.GetByName("Men At Work") == null) { Artists artists = new Artists(); artists.Name = "Men At Work"; artistsRepository.Add(artists); artistsRepository.SaveChanges(); Assert.IsTrue(artistsRepository.Find(w => w.ArtistId == artists.ArtistId).Count() == 1); } }
public void TestBeginTransaction() { string artistsName = "Teste Artist"; IArtistsRepository<Artists> artistsRepository = Artists.GetRepository(); if (artistsRepository.GetByName(artistsName) != null) { artistsRepository.Remove(r => r.Name.Equals(artistsName)); int rowDelete = artistsRepository.SaveChanges(); } using (TransactionScope transaction = new TransactionScope()) { Artists artists = new Artists(); artists.Name = artistsName; artistsRepository.Add(artists); artistsRepository.SaveChanges(); transaction.Complete(); } Assert.IsNotNull(artistsRepository.GetByName(artistsName)); }
public void TesteRemoveAndAddArtists() { IArtistsRepository<Artists> artistsRepository = Artists.GetRepository(); Artists artists = artistsRepository.GetByName("Men At Work"); artistsRepository.Remove(artists); artistsRepository.SaveChanges(); artistsRepository = Artists.GetRepository(); Assert.IsTrue(artistsRepository.Find(w => w.ArtistId == artists.ArtistId).Count() == 0); artists = new Artists() { Name = "Men At Work" }; artistsRepository.Add(artists); artistsRepository.SaveChanges(); artistsRepository = Artists.GetRepository(); Assert.IsTrue(artistsRepository.GetByName("Men At Work") != null); }