コード例 #1
0
        public void It_Uses_The_Player_Information_For_The_Users_Current_Gaming_Group_Related_Player_If_ApplicationUserId_Is_Passed_Instead_Of_Player_Id()
        {
            //--arrange
            var currentUser = new ApplicationUser
            {
                Id = "some user id",
                CurrentGamingGroupId = 718
            };
            var expectedPlayer = new Player
            {
                Id   = 14,
                Name = "player name"
            };

            _autoMocker.Get <IPlayerRetriever>()
            .Expect(mock => mock.GetPlayerForCurrentUser(currentUser.Id, currentUser.CurrentGamingGroupId.Value))
            .Return(expectedPlayer);

            //--act
            var query  = new PlayerAchievementQuery(_achievementId, currentUser.Id, currentUser.CurrentGamingGroupId.Value);
            var result = _autoMocker.ClassUnderTest.GetPlayerAchievement(query);

            //--assert
            result.PlayerName.ShouldBe(expectedPlayer.Name);
            result.PlayerId.ShouldBe(expectedPlayer.Id);
        }
コード例 #2
0
        public virtual ActionResult DetailsForCurrentUser(AchievementId achievementId, ApplicationUser currentUser)
        {
            var achievementQuery           = new PlayerAchievementQuery(achievementId, currentUser.Id, currentUser.CurrentGamingGroupId);
            var playerAchievementDetails   = _playerAchievementRetriever.GetPlayerAchievement(achievementQuery);
            var playerAchievementViewModel =
                _transformer.Transform <PlayerAchievementViewModel>(playerAchievementDetails);

            return(View(MVC.Achievement.Views.Details, playerAchievementViewModel));
        }
コード例 #3
0
        public virtual PlayerAchievementDetails GetPlayerAchievement(PlayerAchievementQuery playerAchievementQuery)
        {
            var achievementId = playerAchievementQuery.AchievementId;
            var achievement   = _achievementRetriever.GetAchievement(achievementId);

            var result = new PlayerAchievementDetails
            {
                AchievementId   = achievementId,
                Description     = achievement.Description,
                IconClass       = achievement.IconClass,
                AchievementName = achievement.Name,
                LevelThresholds = achievement.LevelThresholds
            };

            result.NumberOfPlayersWithThisAchievement = _dataContext.GetQueryable <PlayerAchievement>().Count(y => y.AchievementId == achievementId);


            Player player;

            if (playerAchievementQuery.PlayerId.HasValue)
            {
                player = _dataContext.FindById <Player>(playerAchievementQuery.PlayerId);
            }
            else
            {
                player = _playerRetriever.GetPlayerForCurrentUser(playerAchievementQuery.ApplicationUserId, playerAchievementQuery.GamingGroupId.Value);
            }

            if (player != null)
            {
                result.PlayerId   = player.Id;
                result.PlayerName = player.Name;

                var achievementAwarded = achievement.IsAwardedForThisPlayer(player.Id);

                result.AchievementLevel = achievementAwarded.LevelAwarded;
                result.PlayerProgress   = achievementAwarded.PlayerProgress;

                SetRelatedEntities(achievement.Group, result, achievementAwarded.RelatedEntities);
            }

            var playerAchievement = _dataContext
                                    .GetQueryable <PlayerAchievement>()
                                    .FirstOrDefault(x => x.AchievementId == achievementId && x.PlayerId == playerAchievementQuery.PlayerId);

            if (playerAchievement == null)
            {
                return(result);
            }

            result.DateCreated     = playerAchievement.DateCreated;
            result.LastUpdatedDate = playerAchievement.LastUpdatedDate;

            return(result);
        }
コード例 #4
0
        public void It_Returns_The_Number_Of_Players_With_The_Achievement()
        {
            //--arrange

            //--act
            var query  = new PlayerAchievementQuery(_achievementId, _expectedPlayer.Id);
            var result = _autoMocker.ClassUnderTest.GetPlayerAchievement(query);

            //--assert
            result.NumberOfPlayersWithThisAchievement.ShouldBe(2);
        }
コード例 #5
0
        public void It_Sets_The_Player_Achievement_Dates_If_The_Specified_Player_Has_Earned_The_Achievement()
        {
            //--arrange

            //--act
            var query  = new PlayerAchievementQuery(_achievementId, _expectedPlayer.Id);
            var result = _autoMocker.ClassUnderTest.GetPlayerAchievement(query);

            //--assert
            result.DateCreated.ShouldBe(_playerAchievement.DateCreated);
            result.LastUpdatedDate.ShouldBe(_playerAchievement.LastUpdatedDate);
        }
コード例 #6
0
        public void It_Sets_The_Players_Related_Entities()
        {
            //--arrange

            //--act
            var query  = new PlayerAchievementQuery(_achievementId, _expectedPlayer.Id);
            var result = _autoMocker.ClassUnderTest.GetPlayerAchievement(query);

            //--assert
            _autoMocker.ClassUnderTest.Expect(mock => mock.SetRelatedEntities(
                                                  Arg <AchievementGroup> .Is.Same(_expectedAchievement.Group),
                                                  Arg <PlayerAchievementDetails> .Is.Anything,
                                                  Arg <List <int> > .Is.Same(ExpectedAchievementAwarded.RelatedEntities)));
        }
コード例 #7
0
        public void It_Sets_The_Players_Achievement_Progress_Information()
        {
            //--arrange
            _autoMocker.Get <IDataContext>().Expect(mock => mock.FindById <Player>(_expectedPlayer.Id))
            .Return(_expectedPlayer);

            //--act
            var query  = new PlayerAchievementQuery(_achievementId, _expectedPlayer.Id);
            var result = _autoMocker.ClassUnderTest.GetPlayerAchievement(query);

            //--assert
            result.AchievementLevel.ShouldBe(ExpectedAchievementAwarded.LevelAwarded);
            result.PlayerProgress.ShouldBe(ExpectedAchievementAwarded.PlayerProgress);
        }
コード例 #8
0
        public void It_Sets_The_Player_Information()
        {
            //--arrange
            _autoMocker.Get <IDataContext>().Expect(mock => mock.FindById <Player>(_expectedPlayer.Id))
            .Return(_expectedPlayer);

            //--act
            var query  = new PlayerAchievementQuery(_achievementId, _expectedPlayer.Id);
            var result = _autoMocker.ClassUnderTest.GetPlayerAchievement(query);

            //--assert
            result.PlayerName.ShouldBe(_expectedPlayer.Name);
            result.PlayerId.ShouldBe(_expectedPlayer.Id);
        }
コード例 #9
0
        public virtual ActionResult PlayerAchievement(AchievementId achievementId, int playerId)
        {
            var query = new PlayerAchievementQuery(achievementId, playerId);
            var playerAchievementDetails = _playerAchievementRetriever.GetPlayerAchievement(query);

            if (playerAchievementDetails == null)
            {
                return(new HttpNotFoundResult());
            }

            var playerAchievementViewModel =
                _transformer.Transform <PlayerAchievementViewModel>(playerAchievementDetails);

            return(View(MVC.Achievement.Views.Details, playerAchievementViewModel));
        }
コード例 #10
0
        public void It_Returns_Basic_Achievement_Data()
        {
            //--arrange
            var expectedAchievement = new FakeAchievement();

            //--act
            var query  = new PlayerAchievementQuery(_achievementId, _expectedPlayer.Id);
            var result = _autoMocker.ClassUnderTest.GetPlayerAchievement(query);

            //--assert
            result.ShouldNotBeNull();
            result.AchievementId.ShouldBe(expectedAchievement.Id);
            result.Description.ShouldBe(expectedAchievement.Description);
            result.IconClass.ShouldBe(expectedAchievement.IconClass);
            result.LevelThresholds.ShouldBe(expectedAchievement.LevelThresholds);
        }
コード例 #11
0
        public void It_Returns_A_404_If_The_Player_Doesnt_Have_The_Achievement()
        {
            //--arrange
            var achievementId          = AchievementId.BusyBee;
            int playerId               = -1;
            var playerAchievementQuery = new PlayerAchievementQuery(achievementId, playerId);

            _autoMocker.Get <IPlayerAchievementRetriever>().Expect(mock => mock.GetPlayerAchievement(playerAchievementQuery))
            .IgnoreArguments()
            .Return(null);

            //--act
            var result = _autoMocker.ClassUnderTest.PlayerAchievement(achievementId, playerId);

            //--assert
            result.ShouldBeAssignableTo <HttpNotFoundResult>();
        }