예제 #1
0
        public void Specification_Listagem_Somente_Restaurantes_Que_Nao_Venceram_Na_Semana()
        {
            List <Mock <User> >       mockedUsers       = TestArtifacts.GetMockedUsers();
            List <Mock <Restaurant> > mockedRestaurants = TestArtifacts.GetMockedRestaurants();

            var restaurant1 = TestArtifacts.GetRestaurant1();
            var restaurant2 = TestArtifacts.GetRestaurant2();
            var poll1       = new RestaurantPoll(new Guid("{D6F9DD48-8F80-4B71-8D34-937526BAC306}"), "Almoço", new DateTime(2020, 9, 19), new List <Restaurant>()
            {
                restaurant1, restaurant2
            });
            var pollResults = new List <RestaurantPollResult>()
            {
                new RestaurantPollResult(Guid.NewGuid(), poll1, new DateTime(2020, 9, 13), restaurant1, 42)
            };

            poll1.SetPollResults(pollResults);

            Assert.Single(poll1.GetValidRestaurantsForPoll());
            Assert.Equal(restaurant2, poll1.GetValidRestaurantsForPoll().First());

            var poll2 = new RestaurantPoll(new Guid("{D6F9DD48-8F80-4B71-8D34-937526BAC306}"), "Almoço", new DateTime(2020, 9, 19), new List <Restaurant>()
            {
                restaurant1, restaurant2
            });
            var pollResults2 = new List <RestaurantPollResult>()
            {
                new RestaurantPollResult(Guid.NewGuid(), poll2, new DateTime(2020, 9, 12), restaurant1, 42)
            };

            poll2.SetPollResults(pollResults2);

            Assert.Equal(2, poll2.GetValidRestaurantsForPoll().Count());
        }
예제 #2
0
        public ActionResult <IEnumerable <RestaurantDTO> > GetRestaurantsValidForPoll()
        {
            try
            {
                RestaurantPoll poll = restaurantPollService.GetTodayRestaurantPoll();

                var validRestaurants = poll.GetValidRestaurantsForPoll()
                                       .Select(restaurant => mapper.Map <RestaurantDTO>(restaurant));

                return(Ok(validRestaurants));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, ex.Message);
                return(BadRequest(ex.Message));
            }
        }