public void DeleteDeletesCorrectly() { var methodName = MethodBase.GetCurrentMethod().Name; var options = new DbContextOptionsBuilder <GTLContext>().UseInMemoryDatabase(methodName).Options; // add volumes to db using (var context = new GTLContext(options)) { context.AddRange(volumes); context.SaveChanges(); } // delete volume using (var context = new GTLContext(options)) { var volumeController = ControllerFactory.CreateVolumeController(context); var volumeToDelete = volumes[1]; volumeController.Delete(volumeToDelete); var fetchedVolume = context.Volumes.Find(volumeToDelete.VolumeId); var fetchedVolumes = context.Volumes.ToList(); Assert.Multiple(() => { // assert that the fetched volume is null - deleted from db Assert.That(fetchedVolume, Is.Null); // assert that number of volumes decreased by 1 Assert.AreEqual(fetchedVolumes.Count, volumes.Count - 1); }); } }
public void FindMaterialsFetchesMaterialsWithMultipleAuthors() { // setup var options = new DbContextOptionsBuilder <GTLContext>() .UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name) .UseLazyLoadingProxies() .Options; var authorOne = new Author { FirstName = authorFirstName, LastName = authorLastName }; var authorTwo = new Author { FirstName = "Gergana", LastName = "Petkova" }; // action // add authors to materials materials.ForEach(material => { material.MaterialAuthors = new List <MaterialAuthor> { new MaterialAuthor { Author = authorOne, Material = material }, new MaterialAuthor { Author = authorTwo, Material = material } }; }); using (var context = new GTLContext(options)) { context.AddRange(materials); context.SaveChanges(); } // assertion using (var context = new GTLContext(options)) { var authorController = ControllerFactory.CreateAuthorController(context); var fetchedAuthor = context.Authors.FirstOrDefault(a => a.FirstName == authorOne.FirstName); var fetchedMaterials = authorController.FindMaterials(fetchedAuthor); Assert.That(fetchedMaterials, Has.Exactly(materials.Count).Items); } }