public void ItOnlyRetrievesTheSpecifiedNumberOfNemeses()
        {
            int numberOfHistoricalRecords  = 1;
            NemesisHistoryData historyData = nemesisHistoryRetriever.GetNemesisHistory(playerIdUnderTest, numberOfHistoricalRecords);

            Assert.True(historyData.PreviousNemeses.All(nemesis => nemesis.MinionPlayerId == playerIdUnderTest));
            Assert.AreEqual(numberOfHistoricalRecords, historyData.PreviousNemeses.Count);
        }
Example #2
0
        public NemesisHistoryData GetNemesisHistory(int playerId, int numberOfPreviousNemesisToReturn)
        {
            NemesisHistoryData nemesisHistoryData = new NemesisHistoryData();

            var nemesisData = (from Nemesis nemesis in dataContext.GetQueryable <Nemesis>().Include(nem => nem.NemesisPlayer)
                               where nemesis.MinionPlayerId == playerId
                               select new
            {
                Nemesis = nemesis,
                IsCurrentNemesis = nemesis.MinionPlayer.NemesisId == nemesis.Id
            })
                              .OrderByDescending(nem => nem.Nemesis.DateCreated)
                              //Take an additional one record in case the first one is the current Nemesis
                              .Take(numberOfPreviousNemesisToReturn + 1)
                              .ToList();

            if (nemesisData.Count > 0)
            {
                int startIndexOfPreviousNemeses = 0;
                if (nemesisData[0].IsCurrentNemesis)
                {
                    nemesisHistoryData.CurrentNemesis = nemesisData[0].Nemesis;
                    startIndexOfPreviousNemeses       = 1;
                }

                for (int i = startIndexOfPreviousNemeses; i < nemesisData.Count; i++)
                {
                    nemesisHistoryData.PreviousNemeses.Add(nemesisData[i].Nemesis);
                }
            }

            if (nemesisHistoryData.CurrentNemesis == null)
            {
                nemesisHistoryData.CurrentNemesis = new NullNemesis();
            }

            return(nemesisHistoryData);
        }
        public void ItReturnsAnEmptyListIfThePlayerOnlyHasACurrentNemesisButNoneOtherPriorToThisOne()
        {
            NemesisHistoryData historyData = nemesisHistoryRetriever.GetNemesisHistory(playerIdWithOneNemesisOnly, 5);

            Assert.AreEqual(0, historyData.PreviousNemeses.Count);
        }
        public void ItReturnsAnEmptyListIfThePlayerHasNeverHadANemesis()
        {
            NemesisHistoryData historyData = nemesisHistoryRetriever.GetNemesisHistory(16531, 5);

            Assert.AreEqual(0, historyData.PreviousNemeses.Count);
        }
        public void ItPopulatesTheMinionPlayerData()
        {
            NemesisHistoryData historyData = nemesisHistoryRetriever.GetNemesisHistory(playerIdUnderTest, 5);

            Assert.NotNull(historyData.CurrentNemesis.MinionPlayer);
        }
        public void TheCurrentNemesisIsForTheSpecifiedPlayer()
        {
            NemesisHistoryData historyData = nemesisHistoryRetriever.GetNemesisHistory(playerIdUnderTest, 5);

            Assert.AreEqual(playerIdUnderTest, historyData.CurrentNemesis.MinionPlayerId);
        }
        public void ThePreviousNemesesAreForTheSpecifiedPlayer()
        {
            NemesisHistoryData historyData = nemesisHistoryRetriever.GetNemesisHistory(playerIdUnderTest, 5);

            Assert.True(historyData.PreviousNemeses.All(nemesis => nemesis.MinionPlayerId == playerIdUnderTest));
        }
        public void ItReturnsANullNemesisForTheCurrentNemesisIfThePlayerHasNoNemesis()
        {
            NemesisHistoryData historyData = nemesisHistoryRetriever.GetNemesisHistory(16531, 5);

            Assert.True(historyData.CurrentNemesis is NullNemesis);
        }