public async Task RemoveAsync_ShouldReturnSuccessfulString() { //Arrange var userId = Guid.NewGuid().ToString(); int carId = 3; string expected = "Successfully removed!"; Models.Domain.Car userHasCar = new Models.Domain.Car() { ID = carId }; _unitOfWorkMock.Setup(x => x.Car.CheckIfUserHasCarAsync(userId, carId)).ReturnsAsync(userHasCar); _unitOfWorkMock.Setup(x => x.Car.RemoveAsync(userHasCar.ID)).ReturnsAsync(true); //Act var actual = await _carService.RemoveAsync(userId, carId); //Assert Assert.Equal(expected, actual); }
public async Task RemoveAsync_ShouldThrowException_WhenUserDoesntHaveCarByID() { //Arrange var userId = Guid.NewGuid().ToString(); int carId = 3; string expected = $"User does not have a car with the provided ID"; Models.Domain.Car userHasCar = new Models.Domain.Car() { ID = carId }; _unitOfWorkMock.Setup(x => x.Car.CheckIfUserHasCarAsync(userId, carId)).ReturnsAsync(() => null); //Act Task actual() => _carService.RemoveAsync(userId, carId); //Assert Exception ex = await Assert.ThrowsAsync <Exception>(actual); Assert.Equal(expected, ex.Message); }
public async Task RemoveAsync_ShouldThrowException_WhenRemovingFromDatabaseFails() { //Arrange var userId = Guid.NewGuid().ToString(); int carId = 3; string expected = $"Couldn't remove from database"; Models.Domain.Car userHasCar = new Models.Domain.Car() { ID = carId }; _unitOfWorkMock.Setup(x => x.Car.CheckIfUserHasCarAsync(userId, carId)).ReturnsAsync(userHasCar); _unitOfWorkMock.Setup(x => x.Car.RemoveAsync(userHasCar.ID)).ReturnsAsync(false); //Act Task actual() => _carService.RemoveAsync(userId, carId); //Assert Exception ex = await Assert.ThrowsAsync <Exception>(actual); Assert.Equal(expected, ex.Message); }
public async Task Update_KilometersAsync_ShouldThrowException_WhenUpdatingKilometersFails() { //Arrange var userId = Guid.NewGuid().ToString(); int carId = 3; string expected = $"Couldn't update the record"; int kilometers = 5000; Models.Domain.Car userHasCar = new Models.Domain.Car() { ID = carId }; _unitOfWorkMock.Setup(x => x.Car.CheckIfUserHasCarAsync(userId, carId)).ReturnsAsync(userHasCar); _unitOfWorkMock.Setup(x => x.Car.UpdateCarKilometersAsync(userHasCar.ID, kilometers)).ReturnsAsync(false); //Act Task actual() => _carService.Update_KilometersAsync(userId, userHasCar.ID, kilometers); //Assert Exception ex = await Assert.ThrowsAsync <Exception>(actual); Assert.Equal(expected, ex.Message); }