public void Delete_Pier_By_Pier() { string pierName = "Test Pier to Delete"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { PierRepository pierRepository = new PierRepository(ctx); pierRepository.Add(new Pier { Name = pierName }); pierRepository.SaveChanges(); } // Find and delete it using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Pier> piers = ctx.Piers.Where(pier => pier.Name == pierName).ToList(); Assert.AreEqual(1, piers.Count()); PierRepository pierRepository = new PierRepository(ctx); pierRepository.Delete(piers[0]); pierRepository.SaveChanges(); } // Check that nothing is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Pier> piers = ctx.Piers.Where(pier => pier.Name == pierName).ToList(); Assert.AreEqual(0, piers.Count()); } }
public void Add_Pier() { string pierName = "Test Pier to Add"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { PierRepository pierRepository = new PierRepository(ctx); pierRepository.Add(new Pier { Name = pierName }); pierRepository.SaveChanges(); } // Check that it is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Pier> piers = ctx.Piers.Where(pier => pier.Name == pierName).ToList(); Assert.AreEqual(1, piers.Count()); } }
public void Update_Pier() { string pierName = "Test Pier to Update"; string pierNameUpdated = "Test Pier Updated"; // Add to database using (ThamesClipperContext ctx = new ThamesClipperContext()) { PierRepository pierRepository = new PierRepository(ctx); pierRepository.Add(new Pier { Name = pierName }); pierRepository.SaveChanges(); } // Find and update it using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Pier> piers = ctx.Piers.Where(pier => pier.Name == pierName).ToList(); Assert.AreEqual(1, piers.Count()); PierRepository pierRepository = new PierRepository(ctx); piers[0].Name = pierNameUpdated; pierRepository.Update(piers[0]); pierRepository.SaveChanges(); } // Check that the new name is there using (ThamesClipperContext ctx = new ThamesClipperContext()) { List<Pier> piers = ctx.Piers.Where(pier => pier.Name == pierNameUpdated).ToList(); Assert.AreEqual(1, piers.Count()); } }