public async Task GivenExistingBooking_WhenCruiseIsLocked_ShouldFailToUpdate() { var repository = GetBookingRepositoryForTest(); var cruise = await CruiseRepositoryTest.GetCruiseForTestAsync(); var booking = await GetNewlyCreatedBookingForTestAsync(cruise, repository); Assert.IsFalse(booking.IsLocked); var cruiseRepository = new CruiseRepository(); Assert.IsFalse(cruise.IsLocked); cruise.IsLocked = true; await cruiseRepository.UpdateMetadataAsync(cruise); var updateSource = GetBookingForTest(GetCabinForTest(SjoslagetDbExtensions.CabinTypeId, GetPaxForTest(firstName: "Förnamn1", lastName: "Efternamn1"))); updateSource.Reference = booking.Reference; try { await repository.UpdateAsync(cruise, updateSource); Assert.Fail("Update booking did not throw."); } catch (BookingException) { } }
public async Task GivenBookingSource_WhenCruiseIsLocked_ShouldFailToCreate() { var cruiseRepository = new CruiseRepository(); var cruise = await cruiseRepository.GetActiveAsync(); Assert.IsFalse(cruise.IsLocked); cruise.IsLocked = true; await cruiseRepository.UpdateMetadataAsync(cruise); try { await GetNewlyCreatedBookingForTestAsync(cruise, GetBookingRepositoryForTest()); Assert.Fail("Create booking did not throw"); } catch (BookingException) { } }
public async Task <IHttpActionResult> Lock() { Cruise cruise = await _cruiseRepository.GetActiveAsync(); if (null == cruise) { return(NotFound()); } try { cruise.IsLocked = !cruise.IsLocked; await _cruiseRepository.UpdateMetadataAsync(cruise); return(Ok(IsLockedResult.FromCruise(cruise))); } catch (Exception ex) { _log.Error(ex, "An unexpected exception occurred while locking/unlocking the active cruise."); throw; } }