Пример #1
0
        public void TakeSomebodyElsesSeat()
        {
            //Arrange
            int eventId;
            TestHelperMethods.SetupTestEvent(repo, out eventId);
            TestHelperMethods.SetupTestSession(repo, eventId);
            TestHelperMethods.SetupTestSeat(repo, eventId, 1, 1, "ABCDE");

            var sat = new SatTweet { SeatCode = "ABCDE" };
            var satUser = repo.Users.Where(u => u.Username == "thatismatt").FirstOrDefault();
            processor.ProcessTweet(satUser, sat);
            repo.SubmitChanges();

            //Act
            var sat2 = new SatTweet { SeatCode = "ABCDE" };
            var satUser2 = repo.Users.Where(u => u.Username == "benadderson").FirstOrDefault();
            processor.ProcessTweet(satUser2, sat2);
            repo.SubmitChanges();

            var storedSats = repo.Sats.Where(s => s.Seat.Code == "ABCDE").Select(s => s.Username).AsEnumerable();

            //Assert
            Assert.NotNull(storedSats);
            Assert.Contains("benadderson", storedSats);
            Assert.DoesNotContain("thatismatt", storedSats);
        }
Пример #2
0
        public void ProcessSatTweet()
        {
            //Arrange
            int eventId;
            TestHelperMethods.SetupTestEvent(repo, out eventId);
            TestHelperMethods.SetupTestSession(repo, eventId);
            TestHelperMethods.SetupTestSeat(repo, eventId, 1, 1, "ABCDE");

            var sat = new SatTweet { SeatCode = "ABCDE" };
            var satUser = repo.Users.Where(u => u.Username == "thatismatt").FirstOrDefault();

            //Act
            processor.ProcessTweet(satUser, sat);
            repo.SubmitChanges();

            var storedSat = repo.Sats.Where(s => s.Username == "thatismatt").FirstOrDefault();
            var pointsAwarded = repo.Points.Where(p => p.Username == "thatismatt").FirstOrDefault();

            //Assert
            Assert.NotNull(storedSat);
            Assert.True(storedSat.Seat.Code == "ABCDE");
            Assert.NotNull(pointsAwarded);
            Assert.True(pointsAwarded.Details.StartsWith("Sat in seat: "));
            Assert.True(pointsAwarded.Amount == 10);
        }
Пример #3
0
        public void CantSitOutsideASession()
        {
            //Arrange

            //Act
            var sat = new SatTweet { SeatCode = "ABCDE" };
            var satUser = repo.Users.Where(u => u.Username == "thatismatt").FirstOrDefault();
            processor.ProcessTweet(satUser, sat);
            repo.SubmitChanges();

            var storedSat = repo.Sats.Where(s => s.Username == "thatismatt").FirstOrDefault();

            //Assert
            Assert.Null(storedSat);
        }
Пример #4
0
        public void MoveToSitSomewhereElse()
        {
            //Arrange
            int eventId;
            TestHelperMethods.SetupTestEvent(repo, out eventId);
            TestHelperMethods.SetupTestSession(repo, eventId);
            TestHelperMethods.SetupTestSeat(repo, eventId, 1, 1, "ABCDE");
            TestHelperMethods.SetupTestSeat(repo, eventId, 1, 2, "FGHIJ");

            var sat = new SatTweet { SeatCode = "ABCDE" };
            var satUser = repo.Users.Where(u => u.Username == "thatismatt").FirstOrDefault();
            processor.ProcessTweet(satUser, sat);
            repo.SubmitChanges();

            //Act
            var sat2 = new SatTweet { SeatCode = "FGHIJ" };
            var satUser2 = repo.Users.Where(u => u.Username == "thatismatt").FirstOrDefault();
            processor.ProcessTweet(satUser2, sat2);
            repo.SubmitChanges();

            var storedSats = repo.Sats.Where(s => s.Username == "thatismatt").Select(s => s.Seat.Code).AsEnumerable();
            var pointsAwarded =
                repo.Points.Where(p => p.Username == "thatismatt" && p.Details.StartsWith("Sat in seat: ")).AsEnumerable
                    ();

            //Assert
            Assert.NotNull(storedSats);
            Assert.Contains("FGHIJ", storedSats);
            Assert.DoesNotContain("ABCDE", storedSats);
            Assert.NotNull(pointsAwarded);
            Assert.True(pointsAwarded.Count() == 1);
        }
Пример #5
0
        public void ProcessTweet(User user, SatTweet tweet)
        {
            // The logic for this isn't great - need to make sure we're really dealing with the current session
            Session session = _repo
                .Sessions
                .Where(s => s.Finish > DateTime.Now) // hasn't finished
                .OrderBy(s => s.Start)
                .FirstOrDefault();

            Seat seat = _repo
                .Seats
                .SingleOrDefault(s => s.Code == tweet.SeatCode);

            if (session != null && seat != null)
            {
                // If there's someone already in the seat then remove them from that seat.
                // There really should only be one of these, but this isn't enforced in DB so
                // clean all up just to be sure.
                var previousSitters = _repo
                    .Sats
                    .Where(s => s.SessionID == session.SessionID
                             && s.SeatID == seat.SeatID);
                _repo
                    .Sats
                    .DeleteAllOnSubmit(previousSitters);

                Sat currentSat = _repo
                    .Sats
                    .Where(s => s.SessionID == session.SessionID
                             && s.Username == user.Username)
                    .SingleOrDefault();

                // If they've already got a seat for the session, move them, rather than creating a new record
                // Also, only grant points the first time they sit down!
                if (currentSat == null)
                {
                    _repo
                        .Sats
                        .InsertOnSubmit(new Sat
                                            {
                                                Username = user.Username,
                                                SessionID = session.SessionID,
                                                SeatID = seat.SeatID
                                            });
                    CreditPoints(user, Settings.Points.Sat, "Sat in seat: " + session.SessionID);
                }
                else
                {
                    currentSat.SeatID = seat.SeatID;
                }
            }
        }