public async Task TestDeleteActivity() { var user = new ApplicationUser { Id = Guid.NewGuid().ToString(), UserName = "******" }; var activity = new UserAction { Id = 1, ApplicationUser = user }; var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options; using (var db = new ApplicationDbContext(options)) { IProfileService profileService = new ProfileService(db); db.Users.Add(user); db.UserActions.Add(activity); await db.SaveChangesAsync(); await profileService.DeleteActivity(user); Assert.Equal(0, db.UserActions.Count()); } }