public async Task TripController_Reset_WhenTripDoesNotExist_ShouldReturnNotFound() { // Arrange var tripReference = StringHelper.RandomString(8); var bookingReference = StringHelper.RandomString(6); _mockTripRepository .Setup(m => m.GetByTripReferenceAsync(It.IsAny <string>())) .ReturnsAsync(default(Trip)) .Verifiable(); _mockTripRepository .Setup(m => m.ResetAsync(It.IsAny <Trip>())) .Returns(Task.FromResult <object>(null)) .Verifiable(); _mockBookingRepository .Setup(m => m.GetByTripReferenceAsync(It.IsAny <string>())) .ReturnsAsync(default(IEnumerable <Booking>)) .Verifiable(); _mockBookingRepository .Setup(m => m.CancelAsync(It.IsAny <Booking>())) .Returns(Task.FromResult <object>(null)) .Verifiable(); // Act var tripController = new TripController(_mockTripRepository.Object, _mockVehicleRepository.Object, _mockBookingRepository.Object, _mockLogger.Object); var result = await tripController.Reset(tripReference); // Assert Assert.IsNotNull(result as NotFoundObjectResult); _mockTripRepository.Verify(m => m.GetByTripReferenceAsync(It.IsAny <string>()), Times.Once); _mockTripRepository.Verify(m => m.ResetAsync(It.IsAny <Trip>()), Times.Never); _mockBookingRepository.Verify(m => m.GetByTripReferenceAsync(It.IsAny <string>()), Times.Never); _mockBookingRepository.Verify(m => m.CancelAsync(It.IsAny <Booking>()), Times.Never); }
public async Task TripController_Reset_WhenBookingExists_ShouldReturnOk() { // Arrange var tripReference = StringHelper.RandomString(8); var bookingReference = StringHelper.RandomString(6); _mockTripRepository .Setup(m => m.GetByTripReferenceAsync(It.IsAny <string>())) .ReturnsAsync(TestDataHelper.GetTripCollection(tripReference).FirstOrDefault()) .Verifiable(); _mockTripRepository .Setup(m => m.ResetAsync(It.IsAny <Trip>())) .Returns(Task.FromResult <object>(null)) .Verifiable(); _mockBookingRepository .Setup(m => m.GetByTripReferenceAsync(It.IsAny <string>())) .ReturnsAsync(TestDataHelper.GetBookingCollection(bookingReference, tripReference)) .Verifiable(); _mockBookingRepository .Setup(m => m.CancelAsync(It.IsAny <Booking>())) .Returns(Task.FromResult <object>(null)) .Verifiable(); // Act var tripController = new TripController(_mockTripRepository.Object, _mockVehicleRepository.Object, _mockBookingRepository.Object, _mockLogger.Object); var result = await tripController.Reset(tripReference); // Assert Assert.IsNotNull(result as OkResult); _mockTripRepository.Verify(m => m.GetByTripReferenceAsync(It.IsAny <string>()), Times.Once); _mockTripRepository.Verify(m => m.ResetAsync(It.IsAny <Trip>()), Times.Once); _mockBookingRepository.Verify(m => m.GetByTripReferenceAsync(It.IsAny <string>()), Times.Once); _mockBookingRepository.Verify(m => m.CancelAsync(It.IsAny <Booking>()), Times.Once); }