示例#1
0
        public void ThrowsIfBoardDoesNotExist()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);

            Assert.Throws<ServiceException>(() => service.GenerateMatch(100, "User1", "User3"));
        }
示例#2
0
 public void ThrowsIfOpponentNotFound()
 {
     var repository = Repository.CreatePopulatedRepository();
     var service = new MatchService(repository, null);
     
     Assert.Throws<ServiceException>(() => service.GenerateMatch(1, "User1", "User3"));
 }
示例#3
0
        public void ThrowsIfPlayingYourself()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);

            // Can't find board
            Assert.Throws<ServiceException>(() => service.GenerateMatch(1, "User1", "User1"));
        }
示例#4
0
        public void GeneratesMatch()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);

            var match = service.GenerateMatch(1, "User1", "User2");

            Assert.NotNull(match);
        }
示例#5
0
        public void ThrowsIfBoardHasEnded()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);

            var board = repository.GetBoardByIdWithCompetitors(1);
            board.End = DateTime.Now.AddDays(-1);

            Assert.Throws<ServiceException>(() => service.GenerateMatch(1, "User1", "User2"));
        }
示例#6
0
        public void CreatesMatch()
        {
            var repository = Repository.CreatePopulatedRepository();
            
            var service = new MatchService(repository, new Mock<IMailService>().Object);

            var matchCount = repository.Matches.Count();

            service.CreateMatch(1, "User1", "User2");

            Assert.That(repository.Matches.Count(), Is.EqualTo(matchCount + 1));
        }
示例#7
0
        public void ThrowsIfBoardNotStarted()
        {
            var repository = Repository.CreatePopulatedRepository();

            var service = new MatchService(repository, new Mock<IMailService>().Object);

            var board = repository.GetBoardById(1);
            board.Started = DateTime.Now.AddDays(5);
            
            Assert.Throws<ServiceException>(() => service.CreateMatch(1, "User1", "User2"));
        }
示例#8
0
        public void DoesNotAutoVerifyIfUnable()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);

            var match = repository.GetUnresolvedMatchesByBoardId(1).OrderByDescending(x => x.VerificationDeadline).First();
            
            service.ConfirmMatch(1, match.MatchId, match.Loser.Name);
            service.ProcessManualVerifications(1);
            
            match = repository.GetMatchById(match.MatchId);

            Assert.That(match.IsResolved, Is.False);
        }
示例#9
0
        public void ThrowsIfResolved()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);

            var match = repository.GetResolvedMatchesByBoardId(1).First();
            Assert.Throws<ServiceException>(() => service.ConfirmMatch(match.Board.BoardId, match.MatchId, match.Loser.Name));
        }
示例#10
0
        public void ThrowsIfMatchNotFound()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);
            var match = repository.GetUnresolvedMatchesByBoardId(1).First();

            Assert.Throws<ServiceException>(() => service.RejectMatch(match.Board.BoardId, 9999, match.Loser.Name));
        }
示例#11
0
        public void LoserCanConfirm()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);
            var match = repository.GetUnresolvedMatchesByBoardId(1).First();

            Assert.DoesNotThrow(() => service.ConfirmMatch(match.Board.BoardId, 1, match.Loser.Profile.UserName));
        }
示例#12
0
        public void ThrowsIfResolved()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);

            var match = repository.Matches.First(x => x.Board.BoardId == 1 && x.Resolved.HasValue);
            Assert.Throws<ServiceException>(() => service.RejectMatch(match.Board.BoardId, match.MatchId, match.Loser.Name));
        }
示例#13
0
        public void ThrowsIfNotSubmitterOrLoserOrAdmin()
        {
            var repository = Repository.CreatePopulatedRepository();
            
            var service = new MatchService(repository, null);
            var match = repository.GetUnresolvedMatchesByBoardId(1).First();

            var profile = new UserProfile {UserName = "******", UserId = 999};
            var nonParticipant = new Competitor { CompetitorId = 999, Name = "Joe Shmoe", Rating = 1500, ProfileUserId = 999};
            
            repository.Add(profile);
            repository.Add(nonParticipant);

            repository.CommitChanges();
            Assert.Throws<ServiceException>(() => service.RejectMatch(match.Board.BoardId, match.MatchId, nonParticipant.Name));
        }
示例#14
0
        public void LoserCanReject()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, new Mock<IMailService>().Object);
            var match = repository.GetUnresolvedMatchesByBoardId(1).First();

            Assert.DoesNotThrow(() => service.RejectMatch(match.Board.BoardId, 1, match.Loser.Profile.UserName));
        }
示例#15
0
        public void VerifiesTiedMatch()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);

            repository.GetMatchById(1).Tied = true;
            
            service.VerifyMatch(1);

            var match = repository.GetMatchById(1);

            Assert.That(match.Verified, Is.True);
            Assert.That(match.Resolved, Is.Not.Null);

            Assert.That(match.Loser.Wins, Is.EqualTo(0));
            Assert.That(match.Loser.Streak, Is.EqualTo(0));
            Assert.That(match.Loser.Loses, Is.EqualTo(0));
            Assert.That(match.Loser.Ties, Is.EqualTo(1));

            Assert.That(match.Winner.Wins, Is.EqualTo(0));
            Assert.That(match.Winner.Streak, Is.EqualTo(0));
            Assert.That(match.Winner.Loses, Is.EqualTo(0));
            Assert.That(match.Winner.Ties, Is.EqualTo(1));
        }
示例#16
0
        public void ThrowsIfMatchNotFound()
        {
            var repository = Repository.CreatePopulatedRepository();
            var service = new MatchService(repository, null);

            Assert.Throws<ServiceException>(() => service.VerifyMatch(100));
        }