Inheritance: IChampionRecalculator
        public void SetUp()
        {
            dataContextMock = MockRepository.GenerateMock<IDataContext>();
            championRepositoryMock = MockRepository.GenerateMock<IChampionRepository>();
            championRecalculatorPartialMock = MockRepository.GeneratePartialMock<ChampionRecalculator>(dataContextMock,
                championRepositoryMock);

            List<GameDefinition> allGameDefinitions = new List<GameDefinition>
            {
                new GameDefinition { Active = true, Id = 1 },
                new GameDefinition { Active = true, Id = 2 },
                new GameDefinition { Active = false, Id = 3 }
            };

            allGameDefinitionsQueryable = allGameDefinitions.AsQueryable();

            dataContextMock.Expect(mock => mock.GetQueryable<GameDefinition>()).Return(allGameDefinitionsQueryable);
        }
        public void RecalculateForSingleGame()
        {
            using (NemeStatsDbContext dbContext = new NemeStatsDbContext())
            {
                SecuredEntityValidatorFactory factory = new SecuredEntityValidatorFactory();

                using (NemeStatsDataContext dataContext = new NemeStatsDataContext(dbContext, factory))
                {
                    IChampionRepository championRepository = new ChampionRepository(dataContext);

                    IChampionRecalculator championRecalculator = new ChampionRecalculator(dataContext, championRepository);
                    ApplicationUser user = new ApplicationUser
                    {
                        Id = "80629c07-b8df-4deb-a9e3-5b503ce7d7df",
                        CurrentGamingGroupId = 1
                    };
                    championRecalculator.RecalculateChampion(2005, user);
                }
            }
        }
Esempio n. 3
0
        private void CreatePlayedGames(NemeStatsDataContext dataContext)
        {
            var playerRepository = new EntityFrameworkPlayerRepository(dataContext);
            var nemesisRecalculator = new NemesisRecalculator(dataContext, playerRepository);
            var championRepository = new ChampionRepository(dataContext);
            var championRecalculator = new ChampionRecalculator(dataContext, championRepository);
            var securedEntityValidator = new SecuredEntityValidator(dataContext);
            var weightBonusCalculator = new WeightBonusCalculator(new WeightTierCalculator());
            var pointsCalculator = new PointsCalculator(weightBonusCalculator, new GameDurationBonusCalculator());
            var linkedPlayedGameValidator = new LinkedPlayedGameValidator(dataContext);
            var applicationLinker = new ApplicationLinker(dataContext);

            IPlayedGameSaver playedGameSaver = new PlayedGameSaver(
                dataContext, 
                playedGameTracker, 
                nemesisRecalculator, 
                championRecalculator, 
                securedEntityValidator,
                pointsCalculator,
                new FakeEventBus(),
                linkedPlayedGameValidator,
                applicationLinker);
            
            List<Player> players = new List<Player> { testPlayer1, testPlayer2 };
            List<int> playerRanks = new List<int> { 1, 1 };
            PlayedGame playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer1, testPlayer2, testPlayer3 };
            playerRanks = new List<int> { 1, 2, 3 };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer1, testPlayer3, testPlayer2 };
            playerRanks = new List<int> { 1, 2, 3 };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer3, testPlayer1 };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            //make player4 beat player 1 three times
            players = new List<Player> { testPlayer4, testPlayer1, testPlayer2, testPlayer3 };
            playerRanks = new List<int> { 1, 2, 3, 4 };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer4, testPlayer1 };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer4, testPlayer1 };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            //--make the inactive player5 beat player1 3 times
            players = new List<Player> { testPlayer5, testPlayer1 };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer5, testPlayer1 };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer5, testPlayer1 };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            //make player 2 be the only one who beat player 5
            players = new List<Player> { testPlayer2, testPlayer5 };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinition.Id, players, playerRanks, testUserWithDefaultGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            //--create games that have a different GamingGroupId and testPlayer7 being the champion
            players = new List<Player> { testPlayer7WithOtherGamingGroupId };
            playerRanks = new List<int> { 1 };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer7WithOtherGamingGroupId, testPlayer8WithOtherGamingGroupId };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer8WithOtherGamingGroupId, testPlayer7WithOtherGamingGroupId };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(testGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);

            players = new List<Player> { testPlayer9UndefeatedWith5Games, testPlayer7WithOtherGamingGroupId };
            playerRanks = new List<int> { 1, 2 };
            playedGame = CreateTestPlayedGame(anotherTestGameDefinitionWithOtherGamingGroupId.Id, players, playerRanks, testUserWithOtherGamingGroup, playedGameSaver);
            testPlayedGames.Add(playedGame);
        }