public void GetAllPeopleShouldWork() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "nmicrosinterviewgetall") .Options; // Insert seed data into the database using one instance of the context using (var context = new AppDbContext(options)) { context.Person.Add(new Person { Id = 1, FName = "Fname1", LName = "Lame1" }); context.Person.Add(new Person { Id = 2, FName = "Fname2", LName = "Lname2" }); context.Person.Add(new Person { Id = 3, FName = "Fname3", LName = "Lname3" }); context.SaveChanges(); } // Use a clean instance of the context to run the test using (var context = new AppDbContext(options)) { PersonController personController = new PersonController(context); IEnumerable <Person> people = personController.GetAllPeople(); Assert.NotNull(people); Assert.Equal(3, people.Count()); } }
public void GetAllPeopleShouldNotWork() { var options = new DbContextOptionsBuilder <AppDbContext>() .UseInMemoryDatabase(databaseName: "nmicrosinterviewgetallnotwork") .Options; // Use a clean instance of the context to run the test using (var context = new AppDbContext(options)) { PersonController personController = new PersonController(context); IEnumerable <Person> people = personController.GetAllPeople(); Assert.NotNull(people); Assert.Empty(people); } }