Esempio n. 1
0
        public async Task Call_suggestion_api_when_asking_for_seats_suggestions()
        {
            var showId = "666";
            var party  = 2;

            var seatSuggestionsProvider     = Substitute.For <ISuggestSeats>();
            var suggestionsForFirstCategory =
                SeatFactory.BuildSuggestions(party, PricingCategoryRequested.First, "A7-A8", "A10-A11", "B6-B7");

            var suggestionsForSecondCategory =
                SeatFactory.BuildSuggestions(party, PricingCategoryRequested.Second, "A12-A13", "C6-C7", "D8-D9");

            var suggestionsForThirdCategory =
                SeatFactory.BuildSuggestions(party, PricingCategoryRequested.Third, "E8-E9", "E10-E11", "E6-E7");

            var suggestionsForMixedCategory =
                SeatFactory.BuildSuggestions(party,
                                             PricingCategoryRequested.Mixed); // to be refactor since mixed here makes no sense

            seatSuggestionsProvider.MakeSuggestions(showId, party).Returns(new SuggestionsMade(new ShowId(showId),
                                                                                               new PartyRequested(party),
                                                                                               suggestionsForFirstCategory, suggestionsForSecondCategory, suggestionsForThirdCategory,
                                                                                               suggestionsForMixedCategory));

            var pricingProvider = Substitute.For <IProvidePrices>();

            pricingProvider.GetPrices(showId).Returns(new PricingMapping(110, 90, 70));

            var controller = new ShowsController(Substitute.For <IProvideAuditoriumSeating>(),
                                                 Substitute.For <IProvideReservedSeats>(), seatSuggestionsProvider, pricingProvider, null, null, null);

            var suggestions = await controller.MakeSuggestions(showId, party);

            Check.That(suggestions.ShowId).IsEqualTo(showId);
            Check.That(suggestions.PartyRequested).IsEqualTo(party);
            Check.That(suggestions.SuggestionsForFirstCategory)
            .ContainsExactly(
                new ShowSuggestion(showId, party, PricingCategoryRequested.First,
                                   SeatFactory.BuildSeats(PricingCategory.First, "A7", "A8"), 2 * 110),
                new ShowSuggestion(showId, party, PricingCategoryRequested.First,
                                   SeatFactory.BuildSeats(PricingCategory.First, "A10", "A11"), 2 * 110),
                new ShowSuggestion(showId, party, PricingCategoryRequested.First,
                                   SeatFactory.BuildSeats(PricingCategory.First, "B6", "B7"), 2 * 110));

            Check.That(suggestions.SuggestionsForFirstCategory.Select(s => s.TotalPrice))
            .ContainsExactly(2 * 110, 2 * 110, 2 * 110);
            Check.That(suggestions.SuggestionsForSecondCategory.Select(s => s.TotalPrice))
            .ContainsExactly(2 * 90, 2 * 90, 2 * 90);
            Check.That(suggestions.SuggestionsForThirdCategory.Select(s => s.TotalPrice))
            .ContainsExactly(2 * 70, 2 * 70, 2 * 70);
            Check.That(suggestions.SuggestionsForMixedCategory.Select(s => s.TotalPrice)).IsEmpty();
        }