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");
        }
示例#2
0
        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");
        }
示例#5
0
        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)
 {
 }