public void Should_Return_No_Restaurant_When_All_Elected_At_Week()
            {
                // Preparação
                var poll = new Poll() { Id = 3, Date = DateTime.Now, Status = EPollStatus.Active };

                var restaurants = new List<Restaurant>
                {
                    new Restaurant { Id = 1, Name = "Restaurante 1" },
                    new Restaurant { Id = 2, Name = "Restaurante 2" },
                    new Restaurant { Id = 3, Name = "Restaurante 3" }
                };

                _mockPollDAL
                    .Setup(d => d.GetElectedRestaurantsAtPollWeek(It.Is<Poll>(p => p == poll)))
                    .Returns(restaurants);

                _mockRestaurantBLL
                    .Setup(r => r.GetAllRestaurants())
                    .Returns(restaurants);

                // Teste
                var result = _pollBLL.GetAvailableRestaurantsToVote(poll);

                // Verificação
                Assert.IsNotNull(result);
                Assert.AreEqual(0, result.Count);
            }
Beispiel #2
0
        public List<Restaurant> GetAvailableRestaurantsToVote(Poll poll)
        {
            var electedRestaurants = DAL.GetElectedRestaurantsAtPollWeek(poll);

            var availableRestaurants = electedRestaurants == null ?
                RestaurantBLL.GetAllRestaurants().ToList() :
                RestaurantBLL.GetAllRestaurants()
                .Where(r => !electedRestaurants.Contains(r))
                .ToList();

            return availableRestaurants;
        }
Beispiel #3
0
        public virtual IEnumerable<Restaurant> GetElectedRestaurantsAtPollWeek(Poll poll)
        {
            var delta = DayOfWeek.Monday - poll.Date.DayOfWeek;
            if (delta > 0)
                delta = -6;
            var firstDayOfWeek = poll.Date.AddDays(delta);

            var electedRestaurants = from p in LPContext.Poll
                                     where p.Date >= firstDayOfWeek
                                     select p.ElectedRestaurant;

            return electedRestaurants;
        }
            public void Get_Existing_And_Already_Closed_Poll()
            {
                // Preparação
                var accessDatetime = new DateTime(2015, 08, 17, 15, 00, 00);

                var existingPoll = new Poll { Id = 3, Date = accessDatetime.Date, Status = EPollStatus.Closed };

                _mockPollDAL
                    .Setup(d => d.GetPoll(It.Is<DateTime>(ad => ad == accessDatetime)))
                    .Returns(existingPoll);

                // Teste
                var result = _pollBLL.GetPoll(accessDatetime);

                // Verificações
                Assert.IsNotNull(result);
                Assert.AreEqual(typeof(Poll), result.GetType());
                Assert.AreEqual(existingPoll.Id, result.Id);
                Assert.AreEqual(existingPoll.Date, result.Date);
                Assert.AreEqual(existingPoll.Status, result.Status);
            }
Beispiel #5
0
        private void ClosePoll(Poll poll)
        {
            var pollToClose = DAL.GetPollById(poll.Id);

            if (pollToClose == null)
                throw new Exception("Cannot close poll. Poll does not exist.");

            var mostVoted = VoteBLL.GetMostVotedRestaurant(pollToClose.Id);

            DAL.ModifyPollAndSave(pollToClose.Id, EPollStatus.Closed, mostVoted);
        }
Beispiel #6
0
        private Poll CreatePoll(DateTime datetime)
        {
            Poll poll = new Poll()
            {
                Date = datetime.Date,
                Status = EPollStatus.Active
            };

            if (datetime >= GetDatePollLimitTime(datetime))
                poll.Status = EPollStatus.Closed;

            DAL.CreatePoll(poll);

            return poll;
        }
            public void Get_Poll_And_Close_It_After_Expiration()
            {
                // Preparação
                var accessDatetime = new DateTime(2015, 08, 17, 13, 00, 00);

                var existingPoll = new Poll { Id = 3, Date = new DateTime(2015, 08, 17, 00, 00, 00), Status = EPollStatus.Active };

                var electedRestaurant = new Restaurant() { Id = 4, Name = "Restaurante teste" };

                _mockPollDAL
                    .Setup(d => d.GetPoll(It.Is<DateTime>(ad => ad == accessDatetime)))
                    .Returns(existingPoll);

                _mockPollDAL
                    .Setup(d => d.GetPollById(It.Is<int>(i => i == existingPoll.Id)))
                    .Returns(existingPoll);

                _mockVoteBLL
                    .Setup(v => v.GetMostVotedRestaurant(It.Is<int>(i => i == existingPoll.Id)))
                    .Returns(electedRestaurant);

                _mockPollDAL
                    .Setup(d => d.ModifyPollAndSave(
                        It.Is<int>(i => i == existingPoll.Id),
                        It.Is<EPollStatus>(s => s == EPollStatus.Closed),
                        It.Is<Restaurant>(r => r == electedRestaurant)))
                    .Callback<int, EPollStatus, Restaurant>((i, s, r) =>
                        {
                            existingPoll.Id = i;
                            existingPoll.Status = s;
                            existingPoll.ElectedRestaurant = r;
                            existingPoll.ElectedRestaurantId = r?.Id;
                        });

                // Teste
                var result = _pollBLL.GetPoll(accessDatetime);

                // Verificações
                Assert.IsNotNull(result);
                Assert.AreEqual(typeof(Poll), result.GetType());
                Assert.AreEqual(3, result.Id);
                Assert.AreEqual(existingPoll.Date, result.Date);
                Assert.AreEqual(EPollStatus.Closed, result.Status);
                Assert.AreEqual<Restaurant>(electedRestaurant, result.ElectedRestaurant);
            }
Beispiel #8
0
        public virtual void CreatePoll(Poll poll)
        {
            LPContext.Poll.Add(poll);

            LPContext.SaveChanges();
        }