public async Task CreateAsync_Creates_And_Returns_Created_Workout() { // Arrange var expectedWorkout = new Workout { Name = "Test workout 01" }; WorkoutRepositoryMock .Setup(x => x.CreateAsync(expectedWorkout)) .ReturnsAsync(expectedWorkout) .Verifiable(); // Act var result = await ServiceUnderTest.CreateAsync(expectedWorkout); // Assert Assert.Same(expectedWorkout, result); WorkoutRepositoryMock.Verify(x => x.CreateAsync(expectedWorkout), Times.Once); }
public async Task DeleteAsync_Throws_EntityNotFoundException_When_WorkoutDoesNotExist() { // Arrange const int id = 1; WorkoutRepositoryMock .Setup(x => x.ReadOneAsync(id)) .ReturnsAsync(default(Workout)) .Verifiable(); WorkoutRepositoryMock .Setup(x => x.DeleteAsync(id)) .Verifiable(); // Act, Assert await Assert.ThrowsAsync <EntityNotFoundException>(() => ServiceUnderTest.DeleteAsync(id)); WorkoutRepositoryMock.Verify(x => x.ReadOneAsync(id), Times.Once); WorkoutRepositoryMock.Verify(x => x.DeleteAsync(id), Times.Never); }
UpdateAsync_Throws_EntityIncorrectlyIdentifiedException_When_Workout_Id_DoesNotMatchWorkoutId() { const int id = 1; var expectedWorkout = new Workout { Name = "Test workout 01", Id = id }; WorkoutRepositoryMock .Setup(x => x.ReadOneAsync(id)) .ReturnsAsync(default(Workout)) .Verifiable(); WorkoutRepositoryMock .Setup(x => x.UpdateAsync(expectedWorkout)) .Verifiable(); // Act, Assert await Assert.ThrowsAsync <EntityIncorrectlyIdentifiedException>(() => ServiceUnderTest.UpdateAsync(id + 1, expectedWorkout)); WorkoutRepositoryMock.Verify(x => x.ReadOneAsync(id), Times.Never); WorkoutRepositoryMock.Verify(x => x.UpdateAsync(expectedWorkout), Times.Never); }
public async Task DeleteAsync_Enforces_Workout_Existence_And_Deletes() { // Arrange const int id = 1; var expectedWorkout = new Workout { Name = "Test workout 01", Id = id }; WorkoutRepositoryMock .Setup(x => x.ReadOneAsync(id)) .ReturnsAsync(expectedWorkout) .Verifiable(); WorkoutRepositoryMock .Setup(x => x.DeleteAsync(id)) .ReturnsAsync(expectedWorkout) .Verifiable(); // Act, Assert await ServiceUnderTest.DeleteAsync(id); WorkoutRepositoryMock.Verify(x => x.ReadOneAsync(id), Times.Once); WorkoutRepositoryMock.Verify(x => x.DeleteAsync(id), Times.Once); }
public async Task UpdateAsync_Throws_EntityNotFoundException_When_WorkoutDoesNotExist() { // Arrange const int id = 1; var expectedWorkout = new Workout { Name = "Test workout 01", Id = id }; WorkoutRepositoryMock .Setup(x => x.ReadOneAsync(id)) .ReturnsAsync(default(Workout)) .Verifiable(); WorkoutRepositoryMock .Setup(x => x.UpdateAsync(expectedWorkout)) .Verifiable(); // Act, Assert await Assert.ThrowsAsync <EntityNotFoundException>(() => ServiceUnderTest.UpdateAsync(id, expectedWorkout)); WorkoutRepositoryMock.Verify(x => x.ReadOneAsync(id), Times.Once); WorkoutRepositoryMock.Verify(x => x.UpdateAsync(expectedWorkout), Times.Never); }