public void DeleteConfirmed_WhenDeleting_ThenTheWorkoutIsRemovedFromTheDatabase() { // Arrange var dbContext = new FakeShoeTrackerDbContext(); dbContext .WithWorkout("foo", _currentUserId) .WithWorkout("other", _currentUserId); var controller = new WorkoutController(dbContext) .WithAuthenticatedUser("some user", _currentUserId) .WithValidModelState(); var workoutId = dbContext.Workouts.Select(s => s.WorkoutId).First(); // Act controller.DeleteConfirmed(workoutId); // Assert Assert.That(dbContext.Workouts.Count(), Is.EqualTo(1)); Assert.That(dbContext.Workouts.First().Name, Is.EqualTo("other")); Assert.That(dbContext.NumerOfTimesSaveChangesCalled, Is.EqualTo(1)); }
public void DeleteConfirmed_WhenDeletingInValidWorkout_ThenNothingHappes() { // Arrange var dbContext = new FakeShoeTrackerDbContext(); var controller = new WorkoutController(dbContext) .WithAuthenticatedUser("some user", _currentUserId) .WithValidModelState(); const int workoutId = -1; // Act controller.DeleteConfirmed(workoutId); // Assert Assert.That(dbContext.Workouts.Count(), Is.EqualTo(0)); Assert.That(dbContext.NumerOfTimesSaveChangesCalled, Is.EqualTo(1)); }