public async Task Offer_adjacent_3_seats_nearer_the_middle_of_a_row_when_it_is_possible() { var showId = new ShowId("3"); var partyRequested = new PartyRequested(3); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.First)) .ContainsExactly("A6-A7-A8"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Second)) .ContainsExactly("C4-C5-C6", "C1-C2-C3", "C7-C8-C9"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Third)); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Third)) .ContainsExactly("E4-E5-E6", "E1-E2-E3", "E7-E8-E9"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Mixed)) .ContainsExactly("A6-A7-A8", "B2-B3-B4", "C4-C5-C6"); }
public override int GetHashCode() { unchecked { return((ShowId.GetHashCode() * Places.GetHashCode()) ^ 1337); } }
public async Task <AuditoriumSeating> GetAuditoriumSeating(ShowId showId) { var auditoriumDto = await _auditoriumSeatingRepository.GetAuditoriumSeatingFor(showId.Id); var reservedSeatsDto = await _reservationsProvider.GetReservedSeats(showId.Id); return(AdaptAuditoriumSeatingDto(auditoriumDto, reservedSeatsDto)); }
public async Task Be_a_Value_Type() { var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter(new AuditoriumLayoutRepository(), new ReservationsProvider()); var showIdWithoutReservationYet = new ShowId("18"); var auditoriumSeatingFirstInstance = await auditoriumLayoutAdapter.GetAuditoriumSeating(showIdWithoutReservationYet); var auditoriumSeatingSecondInstance = await auditoriumLayoutAdapter.GetAuditoriumSeating(showIdWithoutReservationYet); // Two different instances with same values should be equals Check.That(auditoriumSeatingSecondInstance).IsEqualTo(auditoriumSeatingFirstInstance); // Should not mutate existing instance auditoriumSeatingSecondInstance.Rows.Values.First().Seats.First().Allocate(); Check.That(auditoriumSeatingSecondInstance).IsEqualTo(auditoriumSeatingFirstInstance); }
public async Task <IActionResult> GetSuggestionsFor([FromQuery(Name = "showId")] string showId, [FromQuery(Name = "party")] int party) { // Imperative shell for this use case ------------------------------- // Infra => Domain var id = new ShowId(showId); var partyRequested = new PartyRequested(party); // Call curried imperative shell // Balance restored : Adapter no longer needs to know other adapters, only uses the domain core var suggestions = await _suggestionsDelegate(id, partyRequested); // Domain => Infra return(new OkObjectResult(suggestions /*JsonConvert.SerializeObject(suggestions, Formatting.Indented)*/)); }
public async Task Offer_adjacent_seats_nearer_the_middle_of_a_row() { var showId = new ShowId("9"); var partyRequested = new PartyRequested(1); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.First)).ContainsExactly("A4", "A3", "B5"); }
public async Task Suggest_one_seat_when_Auditorium_contains_one_available_seat_only() { var showId = new ShowId("1"); var partyRequested = new PartyRequested(1); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.First)).ContainsExactly("A3"); }
public async Task <AuditoriumSeating> GetAuditoriumSeating(ShowId showId) { // Call the AuditoriumLayout Bounded Context in order to get an empty AuditoriumSeating var auditoriumDtoTask = _auditoriumLayoutProviderWebClient.GetAuditoriumSeatingFor(showId.Id); // Call the SeatReservation Bounded Context to get the list of already reserved seats var reservedSeatsDtoTask = _seatsReservationsProviderWebClient.GetReservedSeats(showId.Id); await Task.WhenAll(auditoriumDtoTask, reservedSeatsDtoTask); var auditoriumDto = auditoriumDtoTask.Result; var reservedSeatsDto = reservedSeatsDtoTask.Result; // Adapt all these information into a type belonging to our SeatSuggestion Bounded Context (External Domains/BCs INFRA => Our Domain) var auditoriumSeating = AdaptAuditoriumSeatingDto(auditoriumDto, reservedSeatsDto); return(auditoriumSeating); }
public async Task <IActionResult> GetSuggestionsFor([FromQuery(Name = "showId")] string showId, [FromQuery(Name = "party")] int party) { // Imperative shell for this use case ------------------------------- // Infra => Domain var id = new ShowId(showId); var partyRequested = new PartyRequested(party); // non-pure function var auditoriumSeating = await _auditoriumSeatingProvider.GetAuditoriumSeating(id); // pure function (the core) var suggestions = SeatAllocator .TryMakeSuggestions(id, partyRequested, auditoriumSeating) .GetValueOrFallback(new SuggestionNotAvailable(id, partyRequested)); // Domain => Infra return(new OkObjectResult(suggestions /*JsonConvert.SerializeObject(suggestions, Formatting.Indented)*/)); }
public async Task Return_SeatsNotAvailable_when_Auditorium_has_all_its_seats_already_reserved() { var showId = new ShowId("5"); var partyRequested = new PartyRequested(1); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.PartyRequested).IsEqualTo(partyRequested); Check.That(suggestionsMade.ShowId).IsEqualTo(showId); Check.That(suggestionsMade).IsInstanceOf <SuggestionNotAvailable>(); }
public async Task Offer_several_suggestions_ie_1_per_PricingCategory_and_other_one_without_category_affinity() { var showId = new ShowId("18"); var partyRequested = new PartyRequested(1); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.First)).ContainsExactly("A5", "A6", "A4"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Second)).ContainsExactly("A2", "A9", "A1"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Third)).ContainsExactly("E5", "E6", "E4"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Mixed)).ContainsExactly("A5", "A6", "A4"); }
public async Task Offer_4_adjacent_seats_nearer_the_middle_of_a_row_when_it_is_possible() { var showId = new ShowId("3"); var partyRequested = new PartyRequested(4); var auditoriumLayoutAdapter = new AuditoriumSeatingAdapter( new AuditoriumLayoutRepositoryFromSuggestion(new AuditoriumLayoutRepository()), new ReservationsProvider()); var seatAllocator = new SeatAllocator(auditoriumLayoutAdapter); var suggestionsMade = await seatAllocator.MakeSuggestions(showId, partyRequested); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.First)).IsEmpty(); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Second)) .ContainsExactly("C4-C5-C6-C7", "D4-D5-D6-D7"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Third)) .ContainsExactly("E4-E5-E6-E7", "F4-F5-F6-F7"); Check.That(suggestionsMade.SeatNames(PricingCategoryRequested.Mixed)) .ContainsExactly("A6-A7-A8-A9", "B1-B2-B3-B4", "C4-C5-C6-C7"); }
public SuggestionNotAvailable(ShowId showId, PartyRequested partyRequested) : base(showId, partyRequested) { }