public void NewObjectsHaveTheSameHashCode()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis();

            Assert.True(nemesis1.GetHashCode() == nemesis2.GetHashCode());
        }
Exemple #2
0
        public void ItReturnsTheNewNemesisIfItWasChanged()
        {
            //change the nemesis
            NemesisData nemesisData = new NemesisData()
            {
                NemesisPlayerId = 19383
            };

            _playerRepositoryMock.Expect(mock => mock.GetNemesisData(_playerId))
            .Return(nemesisData);

            List <Nemesis> nemesisList     = new List <Nemesis>();
            Nemesis        existingNemesis = new Nemesis()
            {
                Id             = _existingNemesisId,
                MinionPlayerId = _playerId
            };

            nemesisList.Add(existingNemesis);
            _dataContextMock.Expect(mock => mock.GetQueryable <Nemesis>())
            .Return(nemesisList.AsQueryable());

            Nemesis actualNemesis = _nemesisRecalculator.RecalculateNemesis(_playerId, _currentUser);

            Assert.AreSame(_savedNemesis, actualNemesis);
        }
        public void NewObjectsHaveTheSameHashCode()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis();

            Assert.True(nemesis1.GetHashCode() == nemesis2.GetHashCode());
        }
        public void TheHashCodeIsDifferentIfTheLossPercentagesAreDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis() { LossPercentage = 1 };

            Assert.False(nemesis1.GetHashCode() == nemesis2.GetHashCode());
        }
Exemple #5
0
        public void ItReturnsFalseIfTheNemesisPlayerIdsAreDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis() { NemesisPlayerId = 1 };

            Assert.False(nemesis1.Equals(nemesis2));
        }
Exemple #6
0
        public void ItReturnsFalseIfTheNumberOfGamesLostAreDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis() { NumberOfGamesLost = 1 };

            Assert.False(nemesis1.Equals(nemesis2));
        }
Exemple #7
0
        public void NewObjectsAreTheSame()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis();

            Assert.True(nemesis1.SameNemesis(nemesis2));
        }
Exemple #8
0
        public void NewObjectsAreEqual()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis();

            Assert.True(nemesis1.Equals(nemesis2));
        }
        public void ItReturnsFalseIfTheMinionPlayerIdIsDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis() { MinionPlayerId = 1 };

            Assert.False(nemesis1.SameNemesis(nemesis2));
        }
        public void NewObjectsAreTheSame()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis();

            Assert.True(nemesis1.SameNemesis(nemesis2));
        }
        public void TheHashCodeIsDifferentIfTheNemesisPlayerIdsAreDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis() { NemesisPlayerId = 1 };

            Assert.False(nemesis1.GetHashCode() == nemesis2.GetHashCode());
        }
Exemple #12
0
        public void ItReturnsFalseIfTheLossPercentageIsDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis() { LossPercentage = 1 };

            Assert.False(nemesis1.Equals(nemesis2));
        }
        public void TheHashCodeIsDifferentIfTheNumberOfGamesLostAreDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis() { NumberOfGamesLost = 1 };

            Assert.False(nemesis1.GetHashCode() == nemesis2.GetHashCode());
        }
Exemple #14
0
        public void NewObjectsAreEqual()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis();

            Assert.True(nemesis1.Equals(nemesis2));
        }
Exemple #15
0
        public void ItReturnsTheUpdatedNemesisIfItWasUpdated()
        {
            int         expectedLossPercentage = 15;
            NemesisData nemesisData            = new NemesisData()
            {
                LossPercentage = expectedLossPercentage
            };

            _playerRepositoryMock.Expect(mock => mock.GetNemesisData(_playerId))
            .Return(nemesisData);

            List <Nemesis> nemesisList     = new List <Nemesis>();
            Nemesis        existingNemesis = new Nemesis()
            {
                Id             = _existingNemesisId,
                MinionPlayerId = _playerId
            };

            nemesisList.Add(existingNemesis);
            _dataContextMock.Expect(mock => mock.GetQueryable <Nemesis>())
            .Return(nemesisList.AsQueryable());

            Nemesis actualNemesis = _nemesisRecalculator.RecalculateNemesis(_playerId, _currentUser);

            Assert.AreSame(_savedNemesis, actualNemesis);
        }
Exemple #16
0
        public void ItReturnsANullNemesisIfTheNewNemesisIsNull()
        {
            _playerRepositoryMock.Expect(mock => mock.GetNemesisData(_playerId))
            .Return(new NullNemesisData());

            Nemesis nullNemesis = _nemesisRecalculator.RecalculateNemesis(_playerId, _currentUser);

            Assert.True(nullNemesis is NullNemesis);
        }
Exemple #17
0
        public void ItReturnsFalseIfTheMinionPlayerIdIsDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis()
            {
                MinionPlayerId = 1
            };

            Assert.False(nemesis1.SameNemesis(nemesis2));
        }
        public void TheHashCodeIsDifferentIfTheNumberOfGamesLostAreDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis()
            {
                NumberOfGamesLost = 1
            };

            Assert.False(nemesis1.GetHashCode() == nemesis2.GetHashCode());
        }
Exemple #19
0
        public void ItReturnsFalseIfTheNumberOfGamesLostAreDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis()
            {
                NumberOfGamesLost = 1
            };

            Assert.False(nemesis1.Equals(nemesis2));
        }
Exemple #20
0
        public void ItReturnsFalseIfTheLossPercentageIsDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis()
            {
                LossPercentage = 1
            };

            Assert.False(nemesis1.Equals(nemesis2));
        }
        public void TheHashCodeIsDifferentIfTheLossPercentagesAreDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis()
            {
                LossPercentage = 1
            };

            Assert.False(nemesis1.GetHashCode() == nemesis2.GetHashCode());
        }
Exemple #22
0
        public void ItReturnsFalseIfTheNemesisPlayerIdsAreDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis()
            {
                NemesisPlayerId = 1
            };

            Assert.False(nemesis1.Equals(nemesis2));
        }
        public void TheHashCodeIsDifferentIfTheNemesisPlayerIdsAreDifferent()
        {
            Nemesis nemesis1 = new Nemesis();
            Nemesis nemesis2 = new Nemesis()
            {
                NemesisPlayerId = 1
            };

            Assert.False(nemesis1.GetHashCode() == nemesis2.GetHashCode());
        }
Exemple #24
0
        public static byte[] Decompress(string file, CompressionType cmp)
        {
            byte[] ret = new byte[0];
            try
            {
                switch (cmp)
                {
                case CompressionType.Uncompressed:
                    ret = File.ReadAllBytes(file);
                    break;

                case CompressionType.Kosinski:
                    ret = Kosinski.Decompress(file);
                    break;

                case CompressionType.KosinskiM:
                    ret = ModuledKosinski.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                case CompressionType.Nemesis:
                    ret = Nemesis.Decompress(file);
                    break;

                case CompressionType.Enigma:
                    ret = Enigma.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                case CompressionType.SZDD:
                    ret = SZDDComp.SZDDComp.Decompress(file);
                    break;

                case CompressionType.Comper:
                    ret = Comper.Decompress(file);
                    break;

                case CompressionType.KosinskiPlus:
                    ret = KosinskiPlus.Decompress(file);
                    break;

                case CompressionType.KosinskiPlusM:
                    ret = ModuledKosinskiPlus.Decompress(file, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("cmp", "Invalid compression type " + cmp + "!");
                }
            }
            catch
            {
                LevelData.Log("Unable to read file \"" + file + "\" with compression " + cmp.ToString() + ":");
                throw;
            }
            return(ret);
        }
Exemple #25
0
 private static void PopulateNemesisData(Nemesis nemesis, PlayerDetailsViewModel playerDetailsViewModel)
 {
     playerDetailsViewModel.HasNemesis = !(nemesis is NullNemesis);
     if (playerDetailsViewModel.HasNemesis)
     {
         playerDetailsViewModel.NemesisPlayerId = nemesis.NemesisPlayerId;
         playerDetailsViewModel.NemesisName     = nemesis.NemesisPlayer.Name;
         playerDetailsViewModel.NumberOfGamesLostVersusNemesis = nemesis.NumberOfGamesLost;
         playerDetailsViewModel.LossPercentageVersusPlayer     = nemesis.LossPercentage;
     }
 }
Exemple #26
0
 private Nemesis UpdateExistingNemesisIfNeeded(ApplicationUser currentUser, Nemesis existingNemesis, Nemesis newNemesis)
 {
     if (!newNemesis.Equals(existingNemesis))
     {
         existingNemesis.NumberOfGamesLost = newNemesis.NumberOfGamesLost;
         existingNemesis.LossPercentage    = newNemesis.LossPercentage;
         Nemesis returnNemesis = dataContext.Save <Nemesis>(existingNemesis, currentUser);
         dataContext.CommitAllChanges();
         return(returnNemesis);
     }
     return(existingNemesis);
 }
Exemple #27
0
        /// <summary>
        /// Verify button click
        /// </summary>
        private void btnVerify_Click(object sender, EventArgs e)
        {
            txtResult.Clear();
            int from   = (int)numFrom.Value;
            int to     = (int)numTo.Value;
            int length = to - from;

            byte[] range = GetBytes(from, length, _data);
            try { byte[] result = Nemesis.Decompress(range); txtResult.Text = "Nemesis (" + length + " bytes)"; return; } catch { }
            try  { byte[] result = Enigma.Decompress(range, Endianness.BigEndian); txtResult.Text = "Enigma (" + length + " bytes)"; return; } catch {  }
            try { byte[] result = Kosinski.Decompress(range); txtResult.Text = "Kosinski (" + length + " bytes)"; return; } catch { }
            txtResult.Text = "Not Compressed (" + length + " bytes)";
        }
        public void SetUp()
        {
            _playerRepositoryMock = MockRepository.GenerateMock<IPlayerRepository>();
            _dataContextMock = MockRepository.GenerateMock<IDataContext>();
            _nemesisRecalculator = new NemesisRecalculator(_dataContextMock, _playerRepositoryMock);

            _currentUser = new ApplicationUser();
            _minionPlayer = new Player()
            {
                NemesisId = _existingNemesisId
            };
            _dataContextMock.Expect(mock => mock.FindById<Player>(_playerId))
                .Return(_minionPlayer);
            _savedNemesis = new Nemesis() { Id = _newNemesisId };
            _dataContextMock.Expect(mock => mock.Save<Nemesis>(Arg<Nemesis>.Is.Anything, Arg<ApplicationUser>.Is.Anything))
                .Return(_savedNemesis);
        }
Exemple #29
0
        public virtual Nemesis RecalculateNemesis(int playerId, ApplicationUser currentUser)
        {
            Player minionPlayer = dataContext.FindById <Player>(playerId);

            NemesisData nemesisData = playerRepository.GetNemesisData(playerId);

            if (nemesisData is NullNemesisData)
            {
                ClearNemesisId(currentUser, minionPlayer);

                return(new NullNemesis());
            }

            Nemesis existingNemesis = dataContext.GetQueryable <Nemesis>()
                                      .Where(nemesis => nemesis.Id == minionPlayer.NemesisId)
                                      .FirstOrDefault();

            Nemesis newNemesis = new Nemesis()
            {
                LossPercentage    = nemesisData.LossPercentage,
                NumberOfGamesLost = nemesisData.NumberOfGamesLost,
                NemesisPlayerId   = nemesisData.NemesisPlayerId,
                MinionPlayerId    = playerId
            };

            Nemesis savedNemesis;

            if (newNemesis.SameNemesis(existingNemesis))
            {
                savedNemesis = UpdateExistingNemesisIfNeeded(currentUser, existingNemesis, newNemesis);
            }
            else
            {
                savedNemesis = dataContext.Save <Nemesis>(newNemesis, currentUser);
                dataContext.CommitAllChanges();
                minionPlayer.PreviousNemesisId = minionPlayer.NemesisId;
                minionPlayer.NemesisId         = savedNemesis.Id;
                dataContext.Save <Player>(minionPlayer, currentUser);
            }

            return(savedNemesis);
        }
Exemple #30
0
        public void SetUp()
        {
            _playerRepositoryMock = MockRepository.GenerateMock <IPlayerRepository>();
            _dataContextMock      = MockRepository.GenerateMock <IDataContext>();
            _nemesisRecalculator  = new NemesisRecalculator(_dataContextMock, _playerRepositoryMock);

            _currentUser  = new ApplicationUser();
            _minionPlayer = new Player()
            {
                NemesisId = _existingNemesisId
            };
            _dataContextMock.Expect(mock => mock.FindById <Player>(_playerId))
            .Return(_minionPlayer);
            _savedNemesis = new Nemesis()
            {
                Id = _newNemesisId
            };
            _dataContextMock.Expect(mock => mock.Save <Nemesis>(Arg <Nemesis> .Is.Anything, Arg <ApplicationUser> .Is.Anything))
            .Return(_savedNemesis);
        }
        public virtual Nemesis RecalculateNemesis(int playerId, ApplicationUser currentUser)
        {
            var minionPlayer = dataContext.FindById<Player>(playerId);

            var nemesisData = playerRepository.GetNemesisData(playerId);

            if (nemesisData is NullNemesisData)
            {
                ClearNemesisId(currentUser, minionPlayer);

                return new NullNemesis();
            }

            var existingNemesis = dataContext
                                        .GetQueryable<Nemesis>()
                                        .FirstOrDefault(nemesis => nemesis.Id == minionPlayer.NemesisId);

            var newNemesis = new Nemesis()
            {
                LossPercentage = nemesisData.LossPercentage,
                NumberOfGamesLost = nemesisData.NumberOfGamesLost,
                NemesisPlayerId = nemesisData.NemesisPlayerId,
                MinionPlayerId = playerId
            };

            Nemesis savedNemesis;

            if (newNemesis.SameNemesis(existingNemesis))
            {
                savedNemesis = UpdateExistingNemesisIfNeeded(currentUser, existingNemesis, newNemesis);
            }else
            {
                savedNemesis = dataContext.Save<Nemesis>(newNemesis, currentUser);
                dataContext.CommitAllChanges();
                minionPlayer.PreviousNemesisId = minionPlayer.NemesisId;
                minionPlayer.NemesisId = savedNemesis.Id;
                dataContext.Save<Player>(minionPlayer, currentUser);
            }

            return savedNemesis;
        }
Exemple #32
0
        public void ItUpdatesTheExistingNemesisIfOnlyTheDataHasChanged()
        {
            int         nemesisPlayerId = 1;
            int         gamesLost       = 1;
            int         lossPercentage  = 1;
            NemesisData nemesisData     = new NemesisData()
            {
                NemesisPlayerId   = nemesisPlayerId,
                NumberOfGamesLost = gamesLost,
                LossPercentage    = lossPercentage
            };

            _playerRepositoryMock.Expect(mock => mock.GetNemesisData(_playerId))
            .Return(nemesisData);

            List <Nemesis> nemesisList     = new List <Nemesis>();
            Nemesis        existingNemesis = new Nemesis()
            {
                Id = _existingNemesisId,
                NemesisPlayerId = nemesisPlayerId,
                MinionPlayerId  = _playerId,
                //add 1 so the data is different
                NumberOfGamesLost = gamesLost + 1,
                LossPercentage    = lossPercentage
            };

            nemesisList.Add(existingNemesis);
            _dataContextMock.Expect(mock => mock.GetQueryable <Nemesis>())
            .Return(nemesisList.AsQueryable());

            _nemesisRecalculator.RecalculateNemesis(_playerId, _currentUser);

            _dataContextMock.AssertWasCalled(mock => mock.Save <Nemesis>(
                                                 Arg <Nemesis> .Matches(nem => nem.Id == _existingNemesisId &&
                                                                        nem.MinionPlayerId == _playerId &&
                                                                        nem.NemesisPlayerId == nemesisPlayerId &&
                                                                        nem.NumberOfGamesLost == nemesisData.NumberOfGamesLost &&
                                                                        nem.LossPercentage == nemesisData.LossPercentage),
                                                 Arg <ApplicationUser> .Is.Anything));
        }
Exemple #33
0
        public void ItReturnsTheExistingNemesisIfNothingChanged()
        {
            NemesisData nemesisData = new NemesisData();

            playerRepositoryMock.Expect(mock => mock.GetNemesisData(playerId))
            .Return(nemesisData);

            List <Nemesis> nemesisList     = new List <Nemesis>();
            Nemesis        existingNemesis = new Nemesis()
            {
                Id             = existingNemesisId,
                MinionPlayerId = playerId
            };

            nemesisList.Add(existingNemesis);
            dataContextMock.Expect(mock => mock.GetQueryable <Nemesis>())
            .Return(nemesisList.AsQueryable());

            Nemesis actualNemesis = nemesisRecalculator.RecalculateNemesis(playerId, currentUser);

            Assert.AreSame(existingNemesis, actualNemesis);
        }
        public void ItReturnsTheNewNemesisIfItWasChanged()
        {
            //change the nemesis
            NemesisData nemesisData = new NemesisData() { NemesisPlayerId = 19383 };
            _playerRepositoryMock.Expect(mock => mock.GetNemesisData(_playerId))
                            .Return(nemesisData);

            List<Nemesis> nemesisList = new List<Nemesis>();
            Nemesis existingNemesis = new Nemesis()
            {
                Id = _existingNemesisId,
                MinionPlayerId = _playerId

            };
            nemesisList.Add(existingNemesis);
            _dataContextMock.Expect(mock => mock.GetQueryable<Nemesis>())
                .Return(nemesisList.AsQueryable());

            Nemesis actualNemesis = _nemesisRecalculator.RecalculateNemesis(_playerId, _currentUser);

            Assert.AreSame(_savedNemesis, actualNemesis);
        }
        public void ItReturnsTheUpdatedNemesisIfItWasUpdated()
        {
            int expectedLossPercentage = 15;
            NemesisData nemesisData = new NemesisData() { LossPercentage = expectedLossPercentage };
            _playerRepositoryMock.Expect(mock => mock.GetNemesisData(_playerId))
                            .Return(nemesisData);

            List<Nemesis> nemesisList = new List<Nemesis>();
            Nemesis existingNemesis = new Nemesis()
            {
                Id = _existingNemesisId,
                MinionPlayerId = _playerId
                
            };
            nemesisList.Add(existingNemesis);
            _dataContextMock.Expect(mock => mock.GetQueryable<Nemesis>())
                .Return(nemesisList.AsQueryable());

            Nemesis actualNemesis = _nemesisRecalculator.RecalculateNemesis(_playerId, _currentUser);

            Assert.AreSame(_savedNemesis, actualNemesis);
        }
        public void ItUpdatesTheExistingNemesisIfOnlyTheDataHasChanged()
        {
            int nemesisPlayerId = 1;
            int gamesLost = 1;
            int lossPercentage = 1;
            NemesisData nemesisData = new NemesisData()
            {
                NemesisPlayerId = nemesisPlayerId,
                NumberOfGamesLost = gamesLost,
                LossPercentage = lossPercentage
            };
            _playerRepositoryMock.Expect(mock => mock.GetNemesisData(_playerId))
                            .Return(nemesisData);

            List<Nemesis> nemesisList = new List<Nemesis>();
            Nemesis existingNemesis = new Nemesis()
            {
                Id = _existingNemesisId,
                NemesisPlayerId = nemesisPlayerId,
                MinionPlayerId = _playerId,
                //add 1 so the data is different
                NumberOfGamesLost = gamesLost + 1,
                LossPercentage = lossPercentage
            };
            nemesisList.Add(existingNemesis);
            _dataContextMock.Expect(mock => mock.GetQueryable<Nemesis>())
                .Return(nemesisList.AsQueryable());

            _nemesisRecalculator.RecalculateNemesis(_playerId, _currentUser);

            _dataContextMock.AssertWasCalled(mock => mock.Save<Nemesis>(
                Arg<Nemesis>.Matches(nem => nem.Id == _existingNemesisId
                                        && nem.MinionPlayerId == _playerId
                                        && nem.NemesisPlayerId == nemesisPlayerId
                                        && nem.NumberOfGamesLost == nemesisData.NumberOfGamesLost
                                        && nem.LossPercentage == nemesisData.LossPercentage),
                Arg<ApplicationUser>.Is.Anything));
        }
        public void SetUp()
        {
            autoMocker = new RhinoAutoMocker<PlayerRetriever>();
            autoMocker.PartialMockTheClassUnderTest();
          
            expectedChampion = new Champion()
            {
                Id = 100,
                PlayerId = 101,
                Player = new Player()
            };
            expectedNemesis = new Nemesis()
            {
                Id = 155,
                NemesisPlayerId = 8888,
                NemesisPlayer = new Player()
            };
            expectedPriorNemesis = new Nemesis()
            {
                Id = 22222,
                NemesisPlayerId = 4444,
                NemesisPlayer = new Player()
            };
            var nemesisForPlayerWithOnlyACurrentNemesis = new Nemesis
            {
                Id = 33333,
                NemesisPlayer = new Player()
            };
            player = new Player()
            {
                Id = 1351,
                Name = "the player",
                PlayerGameResults = new List<PlayerGameResult>(),
                GamingGroup = new GamingGroup{ Id = gamingGroupId },
                GamingGroupId = gamingGroupId,
                Active = true,
                NemesisId = expectedNemesis.Id,
                Nemesis = expectedNemesis,
                PreviousNemesisId = expectedPriorNemesis.Id,
                PreviousNemesis = expectedPriorNemesis
            };
            expectedFormerChampionGame = new GameDefinition
            {
                Id = 111,
                PreviousChampionId = player.Id,
                GamingGroupId = gamingGroupId
            };
            playerWithNoNemesisEver = new Player()
            {
                Id = 161266939,
                GamingGroup = new GamingGroup { Id = gamingGroupId },
                GamingGroupId = gamingGroupId
            };
            playerWithOnlyACurrentNemesis = new Player()
            {
                Id = 888484,
                NemesisId = 7,
                Nemesis = nemesisForPlayerWithOnlyACurrentNemesis,
                GamingGroup = new GamingGroup { Id = gamingGroupId },
                GamingGroupId = gamingGroupId
            };
            playerWithAChampionship = new Player()
            {
                Id = 101,
                GamingGroup = new GamingGroup { Id = gamingGroupId }
            };

            var players = new List<Player>()
            {
                player,
                playerWithNoNemesisEver,
                playerWithOnlyACurrentNemesis,
                playerWithAChampionship
            };

            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<Player>())
                                               .Return(players.AsQueryable());

            expectedPlayerStatistics = new PlayerStatistics
            {
                NemePointsSummary = new NemePointsSummary(1, 2, 4)
            };

            autoMocker.ClassUnderTest.Expect(repo => repo.GetPlayerStatistics(Arg<int>.Is.Anything))
                .Repeat.Once()
                .Return(expectedPlayerStatistics);

            autoMocker.ClassUnderTest.Expect(mock => mock.GetPlayerGameResultsWithPlayedGameAndGameDefinition(
                Arg<int>.Is.Anything, 
                Arg<int>.Is.Anything))
                            .Repeat.Once()
                            .Return(player.PlayerGameResults.ToList());

            this.expectedMinions = new List<Player>();
            autoMocker.ClassUnderTest.Expect(mock => mock.GetMinions(Arg<int>.Is.Anything))
                .Return(this.expectedMinions);

            expectedPlayerGameSummaries = new List<PlayerGameSummary>
            {
                new PlayerGameSummary()
            };
            autoMocker.Get<IPlayerRepository>().Expect(mock => mock.GetPlayerGameSummaries(Arg<int>.Is.Anything))
                                .Return(expectedPlayerGameSummaries);

            expectedChampionedGames = new List<Champion> { expectedChampion };
            autoMocker.ClassUnderTest.Expect(mock => mock.GetChampionedGames(Arg<int>.Is.Anything))
                .Return(expectedChampionedGames);

            expectedFormerChampionedGames = new List<GameDefinition> { expectedFormerChampionGame };
            autoMocker.ClassUnderTest.Expect(mock => mock.GetFormerChampionedGames(Arg<int>.Is.Anything))
                .Return(expectedFormerChampionedGames);

            expectedPlayerVersusPlayerStatistics = new List<PlayerVersusPlayerStatistics>();
            autoMocker.Get<IPlayerRepository>().Expect(mock => mock.GetPlayerVersusPlayersStatistics(Arg<int>.Is.Anything))
                      .Return(expectedPlayerVersusPlayerStatistics);

            autoMocker.Get<IPlayerRepository>().Expect(mock => mock.GetLongestWinningStreak(player.Id)).Return(expectedLongestWinningStreak);

            autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<PlayerAchievement>()).Return(new List<PlayerAchievement>().AsQueryable());

        }
Exemple #38
0
 public void ComparingToAnObjectWhichIsNotANemesisReturnsFalse()
 {
     Nemesis nemesis1 = new Nemesis();
     Assert.False(nemesis1.Equals(new object()));
 }
Exemple #39
0
        public void ANullObjectIsNotEqual()
        {
            Nemesis nemesis1 = new Nemesis();

            Assert.False(nemesis1.Equals(null));
        }
 private Nemesis UpdateExistingNemesisIfNeeded(ApplicationUser currentUser, Nemesis existingNemesis, Nemesis newNemesis)
 {
     if (!newNemesis.Equals(existingNemesis))
     {
         existingNemesis.NumberOfGamesLost = newNemesis.NumberOfGamesLost;
         existingNemesis.LossPercentage = newNemesis.LossPercentage;
         var returnNemesis = dataContext.Save<Nemesis>(existingNemesis, currentUser);
         dataContext.CommitAllChanges();
         return returnNemesis;
     }
     return existingNemesis;
 }
Exemple #41
0
        public void TestFixtureSetUp()
        {
            _autoMocker = new RhinoAutoMocker <PlayerDetailsViewModelBuilder>();

            //TODO shouldn't have to do this. Probably need a test base
            AutomapperConfiguration.Configure();

            currentUser = new ApplicationUser()
            {
                CurrentGamingGroupId = gamingGroupId,
                Id = "application user id"
            };

            var gameDefinition1 = new GameDefinition()
            {
                Name = "test game 1",
                Id   = gameDefinitionIdThatIsChampionedByCurrentPlayer,
            };

            gameDefinitionThatIsFormerlyChampionedByCurrentPlayer = new GameDefinition
            {
                Name = "formerly championed game",
                Id   = gameDefinitionIdThatIsFormerlyChampionedByCurrentPlayer
            };
            gameDefinitionThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer = new GameDefinition
            {
                Name = "currently and formerly championed game",
                Id   = gameDefinitionIdThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer
            };
            var playedGame1 = new PlayedGame()
            {
                Id             = 1,
                GameDefinition = gameDefinition1
            };

            var playedGame2 = new PlayedGame()
            {
                Id = 2,
                GameDefinitionId = gameDefinitionIdThatIsFormerlyChampionedByCurrentPlayer
            };
            var playerGameResults = new List <PlayerGameResult>()
            {
                new PlayerGameResult()
                {
                    PlayedGameId = 12, PlayedGame = playedGame1
                },
                new PlayerGameResult()
                {
                    PlayedGameId = 13, PlayedGame = playedGame2
                }
            };

            normalPlayer = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerName                = "Jim",
                OpposingPlayerId                  = 1,
                OpposingPlayerActive              = false,
                NumberOfGamesWonVersusThisPlayer  = 10,
                NumberOfGamesLostVersusThisPlayer = 10
            };

            playerWithNoGamesPlayed = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerId = 2
            };

            minionPlayer = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerName = "Minion Player",
                OpposingPlayerId   = 5,
                NumberOfGamesWonVersusThisPlayer  = 20,
                NumberOfGamesLostVersusThisPlayer = 0
            };

            nemesisPlayer = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerName = "nemesis player",
                OpposingPlayerId   = 3,
                NumberOfGamesWonVersusThisPlayer  = 0,
                NumberOfGamesLostVersusThisPlayer = 100
            };

            previousNemesisPlayer = new PlayerVersusPlayerStatistics

            {
                OpposingPlayerName = "Previous Nemesis Player",
                OpposingPlayerId   = 13,
                NumberOfGamesWonVersusThisPlayer  = 0,
                NumberOfGamesLostVersusThisPlayer = 42
            };

            var nemesis = new Nemesis()
            {
                NemesisPlayerId   = nemesisPlayer.OpposingPlayerId,
                NumberOfGamesLost = 3,
                LossPercentage    = 75,
                NemesisPlayer     = new Player()
                {
                    Name = "Ace Nemesis",
                }
            };

            var previousNemesis = new Nemesis()
            {
                NemesisPlayerId   = previousNemesisPlayer.OpposingPlayerId,
                NumberOfGamesLost = 5,
                LossPercentage    = 66,
                NemesisPlayer     = new Player()
                {
                    Name = "Bravo Nemesis",
                }
            };

            playerDetails = new PlayerDetails()
            {
                Id = playerId,
                ApplicationUserId = currentUser.Id,
                Active            = true,
                Name = "Skipper",
                LongestWinningStreak = 39,
                PlayerGameResults    = playerGameResults,
                PlayerStats          = new PlayerStatistics()
                {
                    TotalGames            = 5,
                    NemePointsSummary     = new NemePointsSummary(1, 3, 5),
                    AveragePlayersPerGame = 3,
                    TotalGamesLost        = 1,
                    TotalGamesWon         = 4,
                    WinPercentage         = 20
                },
                CurrentNemesis  = nemesis,
                PreviousNemesis = previousNemesis,
                Minions         = new List <Player>
                {
                    new Player
                    {
                        Id = minionPlayer.OpposingPlayerId
                    }
                },
                GamingGroupId   = gamingGroupId,
                GamingGroupName = "gaming group name",
                PlayerVersusPlayersStatistics = new List <PlayerVersusPlayerStatistics>
                {
                    normalPlayer,
                    playerWithNoGamesPlayed,
                    nemesisPlayer,
                    previousNemesisPlayer,
                    minionPlayer
                },
                PlayerGameSummaries = new List <PlayerGameSummary>
                {
                    new PlayerGameSummary
                    {
                        GameDefinitionId = gameDefinitionIdThatIsChampionedByCurrentPlayer
                    },
                    new PlayerGameSummary
                    {
                        GameDefinitionId = gameDefinitionIdThatIsFormerlyChampionedByCurrentPlayer
                    },
                    new PlayerGameSummary
                    {
                        GameDefinitionId = gameDefinitionIdThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer
                    }
                },
                NemePointsSummary = new NemePointsSummary(1, 3, 5),
                Achievements      = new List <PlayerAchievementWinner>
                {
                    new PlayerAchievementWinner()
                }
            };

            _autoMocker.Get <IGameResultViewModelBuilder>().Expect(build => build.Build(playerGameResults[0]))
            .Repeat
            .Once()
            .Return(new Models.PlayedGame.GameResultViewModel()
            {
                PlayedGameId = playerGameResults[0].PlayedGameId
            });
            _autoMocker.Get <IGameResultViewModelBuilder>().Expect(build => build.Build(playerGameResults[1]))
            .Repeat
            .Once()
            .Return(new Models.PlayedGame.GameResultViewModel()
            {
                PlayedGameId = playerGameResults[1].PlayedGameId
            });
            foreach (var player in playerDetails.Minions)
            {
                _autoMocker.Get <IMinionViewModelBuilder>().Expect(mock => mock.Build(player))
                .Return(new MinionViewModel()
                {
                    MinionPlayerId = player.Id
                });
            }

            var championedGames = new List <Champion>
            {
                new Champion {
                    GameDefinition = gameDefinition1, GameDefinitionId = gameDefinitionIdThatIsChampionedByCurrentPlayer
                },
                new Champion {
                    GameDefinition = gameDefinitionThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer, GameDefinitionId = gameDefinitionIdThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer
                }
            };

            playerDetails.ChampionedGames = championedGames;

            var formerChampionedGames = new List <GameDefinition>
            {
                gameDefinitionThatIsFormerlyChampionedByCurrentPlayer,
                gameDefinitionThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer
            };

            playerDetails.FormerChampionedGames = formerChampionedGames;

            foreach (var achievement in playerDetails.Achievements)
            {
                _autoMocker.Get <ITransformer>()
                .Expect(mock => mock.Transform <PlayerAchievementSummaryViewModel>(achievement))
                .Return(new PlayerAchievementSummaryViewModel());
            }

            playerDetailsViewModel = _autoMocker.ClassUnderTest.Build(playerDetails, twitterMinionBraggingUrl, currentUser);
        }
Exemple #42
0
        public void ItRecalculatesTheNemesisOfTheCurrentPlayersMinionsIfThePlayerIsGoingInactive()
        {
            var player = MockRepository.GeneratePartialMock <Player>();

            player.Name   = "player name";
            player.Active = false;
            player.Id     = 151516;
            player.Expect(mock => mock.AlreadyInDatabase())
            .Return(true);

            const int EXPECTED_PLAYER_ID1 = 1;
            const int EXPECTED_PLAYER_ID2 = 2;

            var activeMinion1 = new Player
            {
                Id = EXPECTED_PLAYER_ID1
            };
            var activeNemesis = new Nemesis
            {
                NemesisPlayerId = player.Id,
            };

            activeMinion1.Nemesis = activeNemesis;

            var activeMinion2 = new Player
            {
                Id = EXPECTED_PLAYER_ID2
            };
            var secondActiveNemesis = new Nemesis
            {
                NemesisPlayerId = player.Id,
            };

            activeMinion2.Nemesis = secondActiveNemesis;

            var inactiveMinion = new Player
            {
                Id     = -1,
                Active = false
            };
            var inactiveNemesis = new Nemesis
            {
                NemesisPlayerId = player.Id
            };

            inactiveMinion.Nemesis = inactiveNemesis;

            var minionPlayers = new List <Player>
            {
                activeMinion1,
                activeMinion2,
                inactiveMinion
            }.AsQueryable();

            _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>())
            .Repeat.Any()
            .Return(minionPlayers);

            _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <GameDefinition>())
            .Return(new List <GameDefinition>().AsQueryable());

            _autoMocker.ClassUnderTest.Save(player, _currentUser);

            _autoMocker.Get <INemesisRecalculator>().AssertWasCalled(mock => mock.RecalculateNemesis(activeMinion1.Id, _currentUser, _autoMocker.Get <IDataContext>()));
            _autoMocker.Get <INemesisRecalculator>().AssertWasCalled(mock => mock.RecalculateNemesis(activeMinion2.Id, _currentUser, _autoMocker.Get <IDataContext>()));
            _autoMocker.Get <INemesisRecalculator>().AssertWasNotCalled(mock => mock.RecalculateNemesis(inactiveMinion.Id, _currentUser, _autoMocker.Get <IDataContext>()));
        }
Exemple #43
0
        public void ANullObjectIsNotTheSame()
        {
            Nemesis nemesis1 = new Nemesis();

            Assert.False(nemesis1.SameNemesis(null));
        }
        public void ANullObjectIsNotTheSame()
        {
            Nemesis nemesis1 = new Nemesis();

            Assert.False(nemesis1.SameNemesis(null));
        }
Exemple #45
0
        public static void Compress(byte[] file, string destination, CompressionType cmp)
        {
            try
            {
                switch (cmp)
                {
                case CompressionType.Uncompressed:
                    File.WriteAllBytes(destination, file);
                    break;

                case CompressionType.Kosinski:
                    using (MemoryStream input = new MemoryStream(file))
                    {
                        using (FileStream output = File.Create(destination))
                        {
                            using (PaddedStream paddedOutput = new PaddedStream(output, 2, PaddedStreamMode.Write))
                            {
                                Kosinski.Compress(input, paddedOutput);
                            }
                        }
                    }
                    break;

                case CompressionType.KosinskiM:
                    using (MemoryStream input = new MemoryStream(file))
                    {
                        using (FileStream output = File.Create(destination))
                        {
                            using (PaddedStream paddedOutput = new PaddedStream(output, 2, PaddedStreamMode.Write))
                            {
                                ModuledKosinski.Compress(input, paddedOutput, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                            }
                        }
                    }
                    break;

                case CompressionType.Nemesis:
                    Nemesis.Compress(file, destination);
                    break;

                case CompressionType.Enigma:
                    Enigma.Compress(file, destination, LevelData.littleendian ? Endianness.LittleEndian : Endianness.BigEndian);
                    break;

                case CompressionType.SZDD:
                    SZDDComp.SZDDComp.Compress(file, destination);
                    break;

                case CompressionType.Comper:
                    Comper.Compress(file, destination);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("cmp", "Invalid compression type " + cmp + "!");
                }
            }
            catch
            {
                LevelData.Log("Unable to write file \"" + destination + "\" with compression " + cmp.ToString() + ":");
                throw;
            }
        }
Exemple #46
0
        public void ComparingToAnObjectWhichIsNotANemesisReturnsFalse()
        {
            Nemesis nemesis1 = new Nemesis();

            Assert.False(nemesis1.Equals(new object()));
        }
 private static void PopulateNemesisData(Nemesis nemesis, PlayerDetailsViewModel playerDetailsViewModel)
 {
     playerDetailsViewModel.HasNemesis = !(nemesis is NullNemesis);
     if (playerDetailsViewModel.HasNemesis)
     {
         playerDetailsViewModel.NemesisPlayerId = nemesis.NemesisPlayerId;
         playerDetailsViewModel.NemesisName = nemesis.NemesisPlayer.Name;
         playerDetailsViewModel.NumberOfGamesLostVersusNemesis = nemesis.NumberOfGamesLost;
         playerDetailsViewModel.LossPercentageVersusPlayer = nemesis.LossPercentage;
     }
 }
Exemple #48
0
        public void TestFixtureSetUp()
        {
            AutomapperConfiguration.Configure();
            minionViewModelBuilderMock = MockRepository.GenerateMock<IMinionViewModelBuilder>();
            mapperFactory = MockRepository.GenerateStub<IMapperFactory>();

            currentUser = new ApplicationUser()
            {
                CurrentGamingGroupId = gamingGroupId,
                Id = "application user id"
            };

            var gameDefinition1 = new GameDefinition()
            {
                Name = "test game 1",
                Id = gameDefinitionIdThatIsChampionedByCurrentPlayer,
            };
            gameDefinitionThatIsFormerlyChampionedByCurrentPlayer = new GameDefinition
            {
                Name = "formerly championed game",
                Id = gameDefinitionIdThatIsFormerlyChampionedByCurrentPlayer
            };
            gameDefinitionThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer = new GameDefinition
            {
                Name = "currently and formerly championed game",
                Id = gameDefinitionIdThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer
            };
            var playedGame1 = new PlayedGame()
            {
                Id = 1,
                GameDefinition = gameDefinition1
            };

            var playedGame2 = new PlayedGame()
            {
                Id = 2,
                GameDefinitionId = gameDefinitionIdThatIsFormerlyChampionedByCurrentPlayer
            };
            var playerGameResults = new List<PlayerGameResult>()
            {
                new PlayerGameResult(){ PlayedGameId = 12, PlayedGame = playedGame1 },
                new PlayerGameResult(){ PlayedGameId = 13, PlayedGame = playedGame2 }
            };

            normalPlayer = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerName = "Jim",
                OpposingPlayerId = 1,
                OpposingPlayerActive = false,
                NumberOfGamesWonVersusThisPlayer = 10,
                NumberOfGamesLostVersusThisPlayer = 10
            };

            playerWithNoGamesPlayed = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerId = 2
            };

            minionPlayer = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerName = "Minion Player",
                OpposingPlayerId = 5,
                NumberOfGamesWonVersusThisPlayer = 20,
                NumberOfGamesLostVersusThisPlayer = 0
            };

            nemesisPlayer = new PlayerVersusPlayerStatistics
            {
                OpposingPlayerName = "nemesis player",
                OpposingPlayerId = 3,
                NumberOfGamesWonVersusThisPlayer = 0,
                NumberOfGamesLostVersusThisPlayer = 100
            };

            previousNemesisPlayer = new PlayerVersusPlayerStatistics

            {
                OpposingPlayerName = "Previous Nemesis Player",
                OpposingPlayerId = 13,
                NumberOfGamesWonVersusThisPlayer = 0,
                NumberOfGamesLostVersusThisPlayer = 42
            };

            var nemesis = new Nemesis()
            {
                NemesisPlayerId = nemesisPlayer.OpposingPlayerId,
                NumberOfGamesLost = 3,
                LossPercentage = 75,
                NemesisPlayer = new Player()
                {
                    Name = "Ace Nemesis",
                }
            };

            var previousNemesis = new Nemesis()
            {
                NemesisPlayerId = previousNemesisPlayer.OpposingPlayerId,
                NumberOfGamesLost = 5,
                LossPercentage = 66,
                NemesisPlayer = new Player()
                {
                    Name = "Bravo Nemesis",
                }
            };

            playerDetails = new PlayerDetails()
            {
                Id = playerId,
                ApplicationUserId = currentUser.Id,
                Active = true,
                Name = "Skipper",
                LongestWinningStreak = 39,
                PlayerGameResults = playerGameResults,
                PlayerStats = new PlayerStatistics()
                {
                    TotalGames = 5,
                    NemePointsSummary = new NemePointsSummary(1, 3, 5),
                    AveragePlayersPerGame = 3,
                    TotalGamesLost = 1,
                    TotalGamesWon = 4,
                    WinPercentage = 20
                },
                CurrentNemesis = nemesis,
                PreviousNemesis = previousNemesis,
                Minions = new List<Player>
                {
                    new Player
                    {
                        Id = minionPlayer.OpposingPlayerId
                    }
                },
                GamingGroupId = gamingGroupId,
                GamingGroupName = "gaming group name",
                PlayerVersusPlayersStatistics = new List<PlayerVersusPlayerStatistics>
                {
                    normalPlayer,
                    playerWithNoGamesPlayed,
                    nemesisPlayer,
                    previousNemesisPlayer,
                    minionPlayer
                },
                PlayerGameSummaries = new List<PlayerGameSummary>
                {
                    new PlayerGameSummary
                    {
                        GameDefinitionId = gameDefinitionIdThatIsChampionedByCurrentPlayer
                    },
                    new PlayerGameSummary
                    {
                        GameDefinitionId = gameDefinitionIdThatIsFormerlyChampionedByCurrentPlayer
                    },
                    new PlayerGameSummary
                    {
                        GameDefinitionId = gameDefinitionIdThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer
                    }
                },
                NemePointsSummary = new NemePointsSummary(1, 3, 5)
            };

            gameResultViewModelBuilder
                = MockRepository.GenerateMock<IGameResultViewModelBuilder>();
            gameResultViewModelBuilder.Expect(build => build.Build(playerGameResults[0]))
                    .Repeat
                    .Once()
                    .Return(new Models.PlayedGame.GameResultViewModel() { PlayedGameId = playerGameResults[0].PlayedGameId });
            gameResultViewModelBuilder.Expect(build => build.Build(playerGameResults[1]))
                    .Repeat
                    .Once()
                    .Return(new Models.PlayedGame.GameResultViewModel() { PlayedGameId = playerGameResults[1].PlayedGameId });
            foreach (var player in playerDetails.Minions)
            {
                minionViewModelBuilderMock.Expect(mock => mock.Build(player))
                    .Return(new MinionViewModel() { MinionPlayerId = player.Id });
            }

            var championedGames = new List<Champion>
            {
                new Champion { GameDefinition = gameDefinition1, GameDefinitionId = gameDefinitionIdThatIsChampionedByCurrentPlayer },
                new Champion { GameDefinition = gameDefinitionThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer, GameDefinitionId = gameDefinitionIdThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer }
            };
            playerDetails.ChampionedGames = championedGames;

            var formerChampionedGames = new List<GameDefinition>
            {
                gameDefinitionThatIsFormerlyChampionedByCurrentPlayer,
                gameDefinitionThatIsBothCurrentlyAndFormerlyChampionedByCurrentPlayer
            };
            playerDetails.FormerChampionedGames = formerChampionedGames;

          

            builder = new PlayerDetailsViewModelBuilder(gameResultViewModelBuilder, minionViewModelBuilderMock, mapperFactory);

            playerDetailsViewModel = builder.Build(playerDetails, twitterMinionBraggingUrl, currentUser);
        }
Exemple #49
0
        public void ANullObjectIsNotEqual()
        {
            Nemesis nemesis1 = new Nemesis();

            Assert.False(nemesis1.Equals(null));
        }
 public void ANewNemesisDoesNotShareAHashCodeWithANewNonNemesisObject()
 {
     Nemesis nemesis1 = new Nemesis();
     Assert.False(nemesis1.GetHashCode() == (new object()).GetHashCode());
 }
Exemple #51
0
        static void Main(string[] args)
        {
            LongOpt[] opts = new[] {
                new LongOpt("help", Argument.No, null, 'h'),
                new LongOpt("compress", Argument.Required, null, 'c'),
                new LongOpt("decompress", Argument.Required, null, 'd'),
                new LongOpt("recompress", Argument.Required, null, 'r'),
                new LongOpt("same-filename", Argument.No, null, 's'),
                new LongOpt("little-endian", Argument.No, null, 'l'),
                new LongOpt("no-size", Argument.No, null, 'n')
            };
            Getopt          getopt       = new Getopt("KensSharp", args, Getopt.digest(opts), opts);
            Mode?           mode         = null;
            CompressionType?type         = null;
            Endianness      endian       = Endianness.BigEndian;
            bool            size         = true;
            bool            samefilename = false;
            int             opt          = getopt.getopt();

            while (opt != -1)
            {
                switch (opt)
                {
                case 'h':
                    ShowHelp();
                    return;

                case 'c':
                    mode = Mode.Compress;
                    type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true);
                    break;

                case 'd':
                    mode = Mode.Decompress;
                    type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true);
                    break;

                case 'r':
                    mode = Mode.Recompress;
                    type = (CompressionType)Enum.Parse(typeof(CompressionType), getopt.Optarg, true);
                    break;

                case 's':
                    samefilename = true;
                    break;

                case 'l':
                    endian = Endianness.LittleEndian;
                    break;

                case 'n':
                    size = false;
                    break;
                }
                opt = getopt.getopt();
            }
            if (mode == null || type == null || getopt.Optind + (mode == Mode.Recompress | samefilename ? 0 : 1) >= args.Length)
            {
                ShowHelp();
                return;
            }
            string input = args[getopt.Optind];
            string output;

            if (getopt.Optind + 1 == args.Length)
            {
                output = input;
            }
            else
            {
                output = args[getopt.Optind + 1];
            }
            if (samefilename && input != "-")
            {
                switch (mode)
                {
                case Mode.Compress:
                    switch (type)
                    {
                    case CompressionType.Kosinski:
                        output = Path.ChangeExtension(input, "kos");
                        break;

                    case CompressionType.Enigma:
                        output = Path.ChangeExtension(input, "eni");
                        break;

                    case CompressionType.Nemesis:
                        output = Path.ChangeExtension(input, "nem");
                        break;

                    case CompressionType.Saxman:
                        output = Path.ChangeExtension(input, "sax");
                        break;

                    case CompressionType.KosinskiModuled:
                        output = Path.ChangeExtension(input, "kosm");
                        break;
                    }
                    break;

                case Mode.Decompress:
                    output = Path.ChangeExtension(input, "unc");
                    break;
                }
            }
            byte[] indata  = ReadInput(input);
            byte[] outdata = null;
            switch (mode)
            {
            case Mode.Compress:
                switch (type)
                {
                case CompressionType.Kosinski:
                    outdata = Kosinski.Compress(indata);
                    break;

                case CompressionType.Enigma:
                    outdata = Enigma.Compress(indata, endian);
                    break;

                case CompressionType.Nemesis:
                    outdata = Nemesis.Compress(indata);
                    break;

                case CompressionType.Saxman:
                    outdata = Saxman.Compress(indata, size);
                    break;

                case CompressionType.ModuledKosinski:
                    outdata = ModuledKosinski.Compress(indata, endian);
                    break;
                }
                break;

            case Mode.Decompress:
                switch (type)
                {
                case CompressionType.Kosinski:
                    outdata = Kosinski.Decompress(indata);
                    break;

                case CompressionType.Enigma:
                    outdata = Enigma.Decompress(indata, endian);
                    break;

                case CompressionType.Nemesis:
                    outdata = Nemesis.Decompress(indata);
                    break;

                case CompressionType.Saxman:
                    outdata = Saxman.Decompress(indata);
                    break;

                case CompressionType.ModuledKosinski:
                    outdata = ModuledKosinski.Decompress(indata, endian);
                    break;
                }
                break;

            case Mode.Recompress:
                switch (type)
                {
                case CompressionType.Kosinski:
                    outdata = Kosinski.Compress(Kosinski.Decompress(indata));
                    break;

                case CompressionType.Enigma:
                    outdata = Enigma.Compress(Enigma.Decompress(indata, endian), endian);
                    break;

                case CompressionType.Nemesis:
                    outdata = Nemesis.Compress(Nemesis.Decompress(indata));
                    break;

                case CompressionType.Saxman:
                    outdata = Saxman.Compress(Saxman.Decompress(indata), size);
                    break;

                case CompressionType.ModuledKosinski:
                    outdata = ModuledKosinski.Compress(ModuledKosinski.Decompress(indata, endian), endian);
                    break;
                }
                break;
            }
            WriteOutput(output, outdata);
        }
Exemple #52
0
 public void Insert(Nemesis nemesis)
 {
     _sqlite_cmd.CommandText = string.Format("INSERT INTO nemesis (name, level, versionId, life) VALUES ('{0}', {1}, {2}, {3});", nemesis.Name, nemesis.Level, nemesis.VersionId, nemesis.Life);
     _sqlite_cmd.ExecuteNonQuery();
 }
        public void SetUp()
        {
            _autoMocker = new RhinoAutoMocker <PlayerRetriever>();
            _autoMocker.PartialMockTheClassUnderTest();

            _expectedChampion = new Champion()
            {
                Id       = 100,
                PlayerId = 101,
                Player   = new Player()
            };
            _expectedNemesis = new Nemesis()
            {
                Id = 155,
                NemesisPlayerId = 8888,
                NemesisPlayer   = new Player()
            };
            _expectedPriorNemesis = new Nemesis()
            {
                Id = 22222,
                NemesisPlayerId = 4444,
                NemesisPlayer   = new Player()
            };
            var nemesisForPlayerWithOnlyACurrentNemesis = new Nemesis
            {
                Id            = 33333,
                NemesisPlayer = new Player()
            };

            _player = new Player()
            {
                Id   = 1351,
                Name = "the player",
                PlayerGameResults = new List <PlayerGameResult>(),
                GamingGroup       = new GamingGroup {
                    Id = _gamingGroupId, Name = "some gaming group name"
                },
                GamingGroupId     = _gamingGroupId,
                Active            = true,
                NemesisId         = _expectedNemesis.Id,
                Nemesis           = _expectedNemesis,
                PreviousNemesisId = _expectedPriorNemesis.Id,
                PreviousNemesis   = _expectedPriorNemesis,
                ApplicationUserId = "some user id"
            };
            _expectedFormerChampionGame = new GameDefinition
            {
                Id = 111,
                PreviousChampionId = _player.Id,
                GamingGroupId      = _gamingGroupId
            };
            _playerWithNoNemesisEver = new Player()
            {
                Id          = 161266939,
                GamingGroup = new GamingGroup {
                    Id = _gamingGroupId
                },
                GamingGroupId = _gamingGroupId
            };
            _playerWithOnlyACurrentNemesis = new Player()
            {
                Id          = 888484,
                NemesisId   = 7,
                Nemesis     = nemesisForPlayerWithOnlyACurrentNemesis,
                GamingGroup = new GamingGroup {
                    Id = _gamingGroupId
                },
                GamingGroupId = _gamingGroupId
            };
            _playerWithAChampionship = new Player()
            {
                Id          = 101,
                GamingGroup = new GamingGroup {
                    Id = _gamingGroupId
                }
            };

            var players = new List <Player>()
            {
                _player,
                _playerWithNoNemesisEver,
                _playerWithOnlyACurrentNemesis,
                _playerWithAChampionship
            };

            _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>())
            .Return(players.AsQueryable());

            _expectedPlayerStatistics = new PlayerStatistics
            {
                NemePointsSummary = new NemePointsSummary(1, 2, 4)
            };

            _autoMocker.ClassUnderTest.Expect(repo => repo.GetPlayerStatistics(Arg <int> .Is.Anything))
            .Repeat.Once()
            .Return(_expectedPlayerStatistics);

            var queryableApplicationUser = new List <ApplicationUser>
            {
                new ApplicationUser
                {
                    Id    = _player.ApplicationUserId,
                    Email = _expectedEmail
                }
            }.AsQueryable();

            _autoMocker.Get <IDataContext>()
            .Expect(mock => mock.GetQueryable <ApplicationUser>())
            .Return(queryableApplicationUser);

            _autoMocker.ClassUnderTest.Expect(mock => mock.GetPlayerGameResultsWithPlayedGameAndGameDefinition(
                                                  Arg <int> .Is.Anything,
                                                  Arg <int> .Is.Anything))
            .Repeat.Once()
            .Return(_player.PlayerGameResults.ToList());

            _expectedMinions = new List <Player>();
            _autoMocker.ClassUnderTest.Expect(mock => mock.GetMinions(Arg <int> .Is.Anything))
            .Return(_expectedMinions);

            _expectedPlayerGameSummaries = new List <PlayerGameSummary>
            {
                new PlayerGameSummary()
            };
            _autoMocker.Get <IPlayerRepository>().Expect(mock => mock.GetPlayerGameSummaries(Arg <int> .Is.Anything, Arg <IDataContext> .Is.Anything))
            .Return(_expectedPlayerGameSummaries);

            _expectedChampionedGames = new List <Champion> {
                _expectedChampion
            };
            _autoMocker.ClassUnderTest.Expect(mock => mock.GetChampionedGames(Arg <int> .Is.Anything))
            .Return(_expectedChampionedGames);

            _expectedFormerChampionedGames = new List <GameDefinition> {
                _expectedFormerChampionGame
            };
            _autoMocker.ClassUnderTest.Expect(mock => mock.GetFormerChampionedGames(Arg <int> .Is.Anything))
            .Return(_expectedFormerChampionedGames);

            _expectedPlayerVersusPlayerStatistics = new List <PlayerVersusPlayerStatistics>();
            _autoMocker.Get <IPlayerRepository>().Expect(mock => mock.GetPlayerVersusPlayersStatistics(Arg <int> .Is.Anything, Arg <IDataContext> .Is.Anything))
            .Return(_expectedPlayerVersusPlayerStatistics);

            _autoMocker.Get <IPlayerRepository>().Expect(mock => mock.GetLongestWinningStreak(Arg <int> .Is.Equal(_player.Id), Arg <IDataContext> .Is.Anything)).Return(_expectedLongestWinningStreak);

            _expectedPlayerAchievementWinnersPageableList = new List <PlayerAchievementWinner>
            {
                new PlayerAchievementWinner(),
                new PlayerAchievementWinner()
            }.ToPagedList(1, 2);

            _autoMocker.Get <IRecentPlayerAchievementsUnlockedRetriever>()
            .Expect(mock => mock.GetResults(Arg <GetRecentPlayerAchievementsUnlockedQuery> .Is.Anything))
            .Return(_expectedPlayerAchievementWinnersPageableList);
        }
Exemple #54
0
        public void ItRecalculatesTheNemesisOfTheCurrentPlayersMinionsIfThePlayerIsGoingInactive()
        {
            var player = MockRepository.GeneratePartialMock<Player>();
            player.Name = "player name";
            player.Active = false;
            player.Id = 151516;
            player.Expect(mock => mock.AlreadyInDatabase())
                .Return(true);

            const int EXPECTED_PLAYER_ID1 = 1;
            const int EXPECTED_PLAYER_ID2 = 2;

            var activeMinion1 = new Player
            {
                Id = EXPECTED_PLAYER_ID1
            };
            var activeNemesis = new Nemesis
            { 
                NemesisPlayerId = player.Id,
            };
            activeMinion1.Nemesis = activeNemesis;

            var activeMinion2 = new Player
            {
                Id = EXPECTED_PLAYER_ID2
            };
            var secondActiveNemesis = new Nemesis
            { 
                NemesisPlayerId = player.Id,
            };
            activeMinion2.Nemesis = secondActiveNemesis;

            var inactiveMinion = new Player
            {
                Id = -1,
                Active = false
            };
            var inactiveNemesis = new Nemesis
            { 
                NemesisPlayerId = player.Id
            };
            inactiveMinion.Nemesis = inactiveNemesis;

            var minionPlayers = new List<Player>
            {
                activeMinion1,
                activeMinion2,
                inactiveMinion
            }.AsQueryable();

            _autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<Player>())
                .Repeat.Any()
                .Return(minionPlayers);

            _autoMocker.ClassUnderTest.Save(player, _currentUser);
            
            _autoMocker.Get<INemesisRecalculator>().AssertWasCalled(mock => mock.RecalculateNemesis(activeMinion1.Id, _currentUser));
            _autoMocker.Get<INemesisRecalculator>().AssertWasCalled(mock => mock.RecalculateNemesis(activeMinion2.Id, _currentUser));
            _autoMocker.Get<INemesisRecalculator>().AssertWasNotCalled(mock => mock.RecalculateNemesis(inactiveMinion.Id, _currentUser));
        }