예제 #1
0
        public void RestaurantPollResult_Fails_Invalid_Date()
        {
            var validGuid      = Guid.NewGuid();
            var restaurant     = TestArtifacts.GetRestaurant1();
            var restaurantPoll = TestArtifacts.GetRestaurantPoll();

            Assert.ThrowsAny <ArgumentException>(new Action(() => new RestaurantPollResult(validGuid, restaurantPoll, default, restaurant, 42)));
        public void Finaliza_As_Votacoes_Anteriores_Caso_Nao_Tiverem_Sido_Finalizadas()
        {
            List <Mock <User> >       mockedUsers       = TestArtifacts.GetMockedUsers();
            List <Mock <Restaurant> > mockedRestaurants = TestArtifacts.GetMockedRestaurants();

            var restaurant1 = TestArtifacts.GetRestaurant1();
            var restaurant2 = TestArtifacts.GetRestaurant2();

            var dia1 = new DateTime(2020, 1, 10);
            var dia2 = new DateTime(2020, 1, 11);

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

            poll_Dia1.AddVote(restaurant1, mockedUsers[0].Object);
            poll_Dia1.AddVote(restaurant1, mockedUsers[1].Object);
            poll_Dia1.AddVote(restaurant1, mockedUsers[2].Object);
            poll_Dia1.AddVote(restaurant2, mockedUsers[3].Object);

            var mockRepo = new Mock <IRestaurantPollRepository>();
            var service  = new RestaurantPollService(mockRepo.Object);

            mockRepo.Setup(r => r.GetUnfinishedPolls(It.IsAny <DateTime>())).Returns(new RestaurantPoll[] { poll_Dia1 });

            service.GetPollByDate(dia2);

            // ao buscar a votação do dia 11/1/2020 deverá chamar o método AddPollResult
            mockRepo.Verify(r => r.AddPollResult(It.IsAny <RestaurantPollResult>()), Times.Once());
            mockRepo.Verify(r => r.GetPollByDate(It.Is <DateTime>(c => c == dia2)), Times.Once());
        }
예제 #3
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());
        }
예제 #4
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);
        }
예제 #5
0
        public void RestaurantPollResult_Pass_Valid_Date(int dia, int mes, int ano)
        {
            var validGuid      = Guid.NewGuid();
            var restaurant     = TestArtifacts.GetRestaurant1();
            var restaurantPoll = TestArtifacts.GetRestaurantPoll();

            new RestaurantPollResult(validGuid, restaurantPoll, new DateTime(ano, mes, dia), restaurant, 42);
        }
예제 #6
0
        public void RestaurantPollResult_Has_Valid_Winner()
        {
            var validGuid      = Guid.NewGuid();
            var restaurant     = TestArtifacts.GetRestaurant1();
            var restaurantPoll = TestArtifacts.GetRestaurantPoll();

            // must fail
            Assert.ThrowsAny <ArgumentException>(new Action(() => new RestaurantPollResult(validGuid, restaurantPoll, DateTime.Now, null, 42)));

            // pass
            new RestaurantPollResult(validGuid, restaurantPoll, DateTime.Now, restaurant, 42);
        }
        public void Verifica_Ranking()
        {
            List <Mock <User> >       mockedUsers       = TestArtifacts.GetMockedUsers();
            List <Mock <Restaurant> > mockedRestaurants = TestArtifacts.GetMockedRestaurants();

            var restaurant1 = TestArtifacts.GetRestaurant1();
            var restaurant2 = TestArtifacts.GetRestaurant2();
            var poll_Dia1   = new RestaurantPoll(new Guid("{D6F9DD48-8F80-4B71-8D34-937526BAC306}"), "Almoço", new DateTime(2020, 1, 10), new List <Restaurant>()
            {
                restaurant1, restaurant2
            });

            poll_Dia1.AddVote(restaurant1, mockedUsers[0].Object);
            poll_Dia1.AddVote(restaurant1, mockedUsers[1].Object);
            poll_Dia1.AddVote(restaurant2, mockedUsers[2].Object);

            var ranking = poll_Dia1.GetRanking();

            Assert.Equal(2, ranking.ElementAt(0).Votes);
            Assert.Equal(1, ranking.ElementAt(1).Votes);
            Assert.Equal(restaurant1, ranking.ElementAt(0).Restaurant);
            Assert.Equal(restaurant2, ranking.ElementAt(1).Restaurant);
        }
        public void Verifica_Resultado_Da_Votacao()
        {
            List <Mock <User> >       mockedUsers       = TestArtifacts.GetMockedUsers();
            List <Mock <Restaurant> > mockedRestaurants = TestArtifacts.GetMockedRestaurants();

            var restaurant1 = TestArtifacts.GetRestaurant1();
            var restaurant2 = TestArtifacts.GetRestaurant2();
            var poll_Dia1   = new RestaurantPoll(new Guid("{D6F9DD48-8F80-4B71-8D34-937526BAC306}"), "Almoço", new DateTime(2020, 1, 10), new List <Restaurant>()
            {
                restaurant1, restaurant2
            });

            poll_Dia1.AddVote(restaurant1, mockedUsers[0].Object);
            poll_Dia1.AddVote(restaurant1, mockedUsers[1].Object);
            poll_Dia1.AddVote(restaurant1, mockedUsers[2].Object);
            poll_Dia1.AddVote(restaurant2, mockedUsers[3].Object);

            var result = poll_Dia1.GetResult();

            Assert.Equal(3, result.TotalVotes);
            Assert.Equal(restaurant1, result.WinnerRestaurant);
            Assert.Equal(restaurant1, poll_Dia1.WinnerRestaurant);
        }
예제 #9
0
 public void RestaurantPollResult_Pass_Valid_Votes(int votes)
 {
     new RestaurantPollResult(Guid.NewGuid(), TestArtifacts.GetRestaurantPoll(), DateTime.Now, TestArtifacts.GetRestaurant1(), votes);
 }
예제 #10
0
 public void RestaurantPollResult_Fails_Invalid_Votes(int votes)
 {
     Assert.ThrowsAny <ArgumentException>(new Action(() => new RestaurantPollResult(Guid.NewGuid(), TestArtifacts.GetRestaurantPoll(), DateTime.Now, TestArtifacts.GetRestaurant1(), votes)));
 }
예제 #11
0
 public void RestaurantPollResult_Fails_Invalid_Id(string guidStr)
 {
     Assert.ThrowsAny <ArgumentException>(new Action(() => new RestaurantPollResult(new Guid(guidStr), TestArtifacts.GetRestaurantPoll(), DateTime.Now, TestArtifacts.GetRestaurant1(), 42)));
 }
예제 #12
0
        public void RestaurantPollResult_Pass_Valid_Id(string guidStr)
        {
            var validGuid = new Guid(guidStr);

            new RestaurantPollResult(validGuid, TestArtifacts.GetRestaurantPoll(), DateTime.Now, TestArtifacts.GetRestaurant1(), 42);
        }