Exemplo n.º 1
0
        public void CantExceedTheEventHiFiveLimit()
        {
            //Arrange
            TestHelperMethods.SetupTestEvent(repo);
            var hiFivingUser = repo.Users.Where(u => u.Username == "thatismatt").FirstOrDefault();

            for (int x = 1; x < 6; x++ )
            {
                string userName = "******" + x;
                TestHelperMethods.CreateTestUser(repo, userName);
                var hiFive = new HiFiveTweet(userName);
                processor.ProcessTweet(hiFivingUser, hiFive);
                repo.SubmitChanges();
            }

            //Act
            var oneMoreHiFive = new HiFiveTweet("benadderson");
            processor.ProcessTweet(hiFivingUser, oneMoreHiFive);

            var hiFives = repo.HiFives.Where(hf => hf.HiFiver == "thatismatt").Select(hf => hf.HiFivee).AsEnumerable();

            //Assert
            Assert.Contains("newUser1", hiFives);
            Assert.Contains("newUser2", hiFives);
            Assert.Contains("newUser3", hiFives);
            Assert.Contains("newUser4", hiFives);
            Assert.Contains("newUser5", hiFives);
            Assert.DoesNotContain("benadderson", hiFives);
        }
Exemplo n.º 2
0
        public void CantHiFiveOutsideAnEvent()
        {
            //Arrange
            var hiFive = new HiFiveTweet("benadderson");
            var hiFivingUser = repo.Users.Where(u => u.Username == "thatismatt").FirstOrDefault();

            //Act
            processor.ProcessTweet(hiFivingUser, hiFive);
            repo.SubmitChanges();

            HiFive storedHiFive = repo.HiFives.Where(hf => hf.HiFiver == hiFivingUser.Username &&
                                                                 hf.HiFivee == "benadderson").FirstOrDefault();
            Point pointsAwarded = repo.Points.Where(p => p.Username == "benadderson").FirstOrDefault();

            //Assert
            Assert.Null(storedHiFive);
            Assert.Null(pointsAwarded);
        }
Exemplo n.º 3
0
        public void ProcessTweet(User user, HiFiveTweet tweet)
        {
            // Prevent users from Hi5ing themselves
            if (user.Username == tweet.Friend)
                return;

            Event currentEvent = _repo
                .Events
                .Where(e => e.Start <= DateTime.Now
                         && e.End >= DateTime.Now)
                .SingleOrDefault();

            // Only accept Hi5s for the current event
            if (currentEvent != null)
            {
                // You can only Hi5 each person once per event and there is a total cap of hifives per person per event
                if (_repo.HiFives.Where(h => h.HiFiver == user.Username && h.EventID == currentEvent.EventID).Count() < currentEvent.HiFiveLimit
                    && _repo.HiFives.Where(h => h.HiFiver == user.Username && h.EventID == currentEvent.EventID
                        && h.HiFivee == tweet.Friend).Count() == 0)
                {
                    User hiFivee = EnsureUser(tweet.Friend);

                    _repo
                        .HiFives
                        .InsertOnSubmit(
                            new HiFive
                            {
                                Event = currentEvent,
                                HiFiver = user.Username,
                                HiFivee = tweet.Friend
                            });

                    CreditPoints(hiFivee, Settings.Points.HiFive, "Hi5: " + user.Username);
                }
            }
        }
Exemplo n.º 4
0
        public void CantHiFiveYourself()
        {
            //Arrange
            TestHelperMethods.SetupTestEvent(repo);

            var hiFive = new HiFiveTweet("benadderson");
            var hiFivingUser = repo.Users.Where(u => u.Username == "benadderson").FirstOrDefault();

            //Act
            processor.ProcessTweet(hiFivingUser, hiFive);
            repo.SubmitChanges();

            HiFive storedHiFive = repo.HiFives.Where(hf => hf.HiFiver == hiFivingUser.Username &&
                                                                 hf.HiFivee == "benadderson").FirstOrDefault();
            Point pointsAwarded = repo.Points.Where(p => p.Username == "benadderson").FirstOrDefault();

            //Assert
            Assert.Null(storedHiFive);
            Assert.Null(pointsAwarded);
        }