예제 #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
        private RestaurantPoll LoadPoll(RestaurantPoll poll)
        {
            // busca os ultimos 100 resultados das votações passadas.
            var pollResults = dbContext.PollResults
                              .Where(pr => pr.Date.Date <= poll.Date.Date)
                              .OrderByDescending(pr => pr.Date)
                              .Include(v => v.WinnerRestaurant)
                              .Include(v => v.RestaurantPoll)
                              .Take(100).ToList();

            poll.SetPollResults(pollResults);

            // busca todos os votos (máximo = 5000).
            var votes = dbContext.Votes
                        .Where(v => v.RestaurantPoll.Id == poll.Id)
                        .Include(v => v.Restaurant)
                        .Include(v => v.Voter)
                        .Include(v => v.RestaurantPoll)
                        .Take(5000).ToList();

            poll.SetVotes(votes);

            poll.SetRestaurants(dbContext.Restaurants.ToList());

            return(poll);
        }
예제 #3
0
        public void Specification_Somente_Um_Restaurante_Vencedor_Por_Semana()
        {
            List <Mock <User> >       mockedUsers       = TestArtifacts.GetMockedUsers();
            List <Mock <Restaurant> > mockedRestaurants = TestArtifacts.GetMockedRestaurants();

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

            poll.SetPollResults(pollResults);

            var user1 = mockedUsers[0].Object;
            var user2 = mockedUsers[1].Object;

            poll.AddVote(restaurant1, user1);
            Assert.Single(poll.Votes);

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

            poll2.SetPollResults(pollResults);

            Assert.ThrowsAny <Exception>(() => poll2.AddVote(restaurant1, user2));
            Assert.Empty(poll2.Votes);
        }