public void WillUpdateScoreForOneOnOne()
        {
            // Arrange
            var ladder = new Ladder("Default", 2, 1);
            var scoringService = new ScoringService();

            var game = TestUtils.CreateStartedGameWithMapAndPlayersUnitsPlaced();
            game.Teams.First().Players.First().Surrender();

            game.LadderId = ladder.Id;
            game.Ladder = ladder;

            // Act
            scoringService.Score(ladder, game);

            // Assert
            Assert.AreEqual(2, ladder.Standings.Count, "Player standings have not been created");

            var player1Standing = ladder.Standings.First(x => x.UserId == game.Teams.First().Players.First().User.Id);
            var player2Standing = ladder.Standings.First(x => x.UserId == game.Teams.Last().Players.First().User.Id);

            Assert.IsTrue(player1Standing.Rating < player2Standing.Rating);
            Assert.AreEqual(1, player1Standing.GamesLost);
            Assert.AreEqual(1, player1Standing.GamesPlayed);
        }
Exemplo n.º 2
0
            public void GamesAreCreated()
            {
                // Arrange
                var mockUnitOfWork = TestUtils.GetUnitOfWorkMock();
                mockUnitOfWork.SetupGet(x => x.Games).Returns(new MockGamesRepository());
                mockUnitOfWork.SetupGet(x => x.Ladders).Returns(new MockLadderRepository());
                var unitOfWork = mockUnitOfWork.Object;

                var gameServiceMock = new Mock<IGameService>();
                gameServiceMock.Setup(x => x.Create(
                    Enums.GameType.Ranking,
                    It.IsAny<User>(),
                    It.IsAny<string>(),
                    It.IsAny<string>(),
                    It.IsAny<Domain.Games.GameOptions>()))
                    .Returns(TestUtils.CreateGame(2, 1, Enums.GameType.Ranking));

                var ladderService = new LadderService(unitOfWork, gameServiceMock.Object, TestUtils.MockMapTemplateProvider(), new Mock<IEventAggregator>().Object);

                var mapTemplate = TestUtils.GetMapTemplate();

                var ladder = new Ladder("Default", 2, 1);

                ladder.MapTemplates.Add(mapTemplate.Name);

                ladder.Options.MapDistribution = Enums.MapDistribution.Default;
                ladder.Options.VisibilityModifier.Add(Enums.VisibilityModifierType.None);

                ladder.ToggleActive(true);

                unitOfWork.Ladders.Add(ladder);

                var user1 = TestUtils.CreateUser("1");
                var user2 = TestUtils.CreateUser("2");
                ladder.QueueUser(user1);
                ladder.QueueUser(user2);

                // Act
                ladderService.CheckAndCreateMatches();

                // Assert
                Assert.IsTrue(ladder.Games.Any());
                var game = ladder.Games.First();
                Assert.AreEqual(Enums.GameState.Active, game.State);
                Assert.AreEqual(Enums.GameType.Ranking, game.Type);
                Assert.AreEqual(ladder, game.Ladder);
                Assert.IsFalse(ladder.Queue.Any());
            }
Exemplo n.º 3
0
        public void ActiveOnlyWithTemplates()
        {
            // Arrange
            var ladder = new Ladder("1vs1", 2, 1);

            // Act
            ladder.ToggleActive(true);
        }
Exemplo n.º 4
0
            public void UserCannotQueueTwice()
            {
                // Arrange
                var user1 = TestUtils.CreateUser("1");
                var ladder = new Ladder("Default", 2, 1);

                // Act
                ladder.QueueUser(user1);
                ladder.QueueUser(user1);
            }
Exemplo n.º 5
0
            public void QueueForUserSuccess()
            {
                // Arrange
                var user1 = TestUtils.CreateUser("1");
                var ladder = new Ladder("Default", 2, 1);

                // Act
                ladder.QueueUser(user1);

                // Assert
                Assert.IsTrue(ladder.Queue.Any());
            }
Exemplo n.º 6
0
        public void GameNameIsGenerated()
        {
            // Arrange
            var ladder = new Ladder("1vs1", 2, 1);

            // Act
            var gameName = ladder.GetGameName();
            Thread.Sleep(1);
            var gameName2 = ladder.GetGameName();

            // Assert
            Assert.IsTrue(gameName.Contains(ladder.Name));
            Assert.AreNotEqual(gameName, gameName2);
        }
Exemplo n.º 7
0
        public void ActiveWithTemplates()
        {
            // Arrange
            var ladder = new Ladder("1vs1", 2, 1);
            ladder.MapTemplates.Add("MapTemplate");

            // Act
            ladder.ToggleActive(true);

            // Assert
            Assert.IsTrue(ladder.IsActive);
        }
Exemplo n.º 8
0
 public LadderStanding(Ladder ladder, User user)
 {
     this.LadderId = ladder.Id;
     this.UserId = user.Id;
 }
Exemplo n.º 9
0
        public LadderQueueEntry(Ladder ladder, User user)
        {
            this.ladder = ladder;

            this.User = user;
            this.UserId = user.Id;
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create new ladeder
        /// </summary>
        public Ladder Create(string name, int numberOfTeams, int numberOfPlayers)
        {
            var ladder = new Ladder(name, numberOfTeams, numberOfPlayers);

            this.unitOfWork.Ladders.Add(ladder);

            return ladder;
        }
Exemplo n.º 11
0
        /// <summary>
        /// Create a game for the given ladder
        /// </summary>        
        protected virtual Games.Game CreateGame(Ladder ladder)
        {
            var systemUser = this.unitOfWork.Users.FindByName("System");

            var mapTemplate = ladder.GetMapTemplateForGame();

            var game = gameService.Create(
                Enums.GameType.Ranking,
                systemUser,
                ladder.GetGameName(),
                mapTemplate,
                ladder.Options);

            game.Ladder = ladder;
            game.LadderId = ladder.Id;

            return game;
        }
Exemplo n.º 12
0
        private void InitLadder(ImperaContext context, User systemUser)
        {
            if (context.Ladders.FirstOrDefault(l => l.Name == "Default") == null)
            {
                var ladder = new Ladder("Default", 2, 2);

                ladder.MapTemplates.Add("WorldDeluxe");

                ladder.Options.MapDistribution = MapDistribution.Default;
                ladder.Options.VisibilityModifier.Add(VisibilityModifierType.None);
                ladder.Options.VictoryConditions.Add(VictoryConditionType.Survival);

                ladder.Options.AttacksPerTurn = 3;
                ladder.Options.InitialCountryUnits = 3;
                ladder.Options.MapDistribution = MapDistribution.Default;
                ladder.Options.MaximumNumberOfCards = 5;
                ladder.Options.MaximumTimeoutsPerPlayer = 1;
                ladder.Options.MinUnitsPerCountry = 1;
                ladder.Options.MovesPerTurn = 3;
                ladder.Options.NewUnitsPerTurn = 3;
                ladder.Options.TimeoutInSeconds = (int)TimeSpan.FromDays(1).TotalSeconds;

                ladder.ToggleActive(true);

                context.Ladders.Add(ladder);

                context.SaveChanges();
            }
        }