public async Task CancelAppointmentAsync_WithValidId_ShouldDeleteAppointment() { var options = new DbContextOptionsBuilder <DentHubContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) // Give a Unique name to the DB .Options; var dbContext = new DentHubContext(options); var repository = new DbRepository <Appointment>(dbContext); var ratingRepository = new DbRepository <Rating>(dbContext); var service = new AppointmentService(repository, ratingRepository); var appointment = new Appointment { Id = 41, ClinicId = 1, DentistID = "1", }; dbContext.Appointments.Add(appointment); dbContext.SaveChanges(); await service.CancelAppointmentAsync(41); var result = dbContext.Appointments .CountAsync() .GetAwaiter() .GetResult(); Assert.Equal(0, result); }