Exemplo n.º 1
0
        public void It_Returns_Achievement_Details_For_The_Current_User()
        {
            //--arrange
            var achievementId = AchievementId.BusyBee;
            var expectedPlayerAchievementDetails = new PlayerAchievementDetails();

            AutoMocker.Get <IPlayerAchievementRetriever>().Expect(mock => mock.GetPlayerAchievement(Arg <PlayerAchievementQuery> .Is.Anything))
            .Return(expectedPlayerAchievementDetails);
            var expectedPlayerAchievementViewModel = new PlayerAchievementViewModel();

            AutoMocker.Get <ITransformer>().Expect(mock => mock.Transform <PlayerAchievementViewModel>(expectedPlayerAchievementDetails))
            .Return(expectedPlayerAchievementViewModel);

            //--act
            var viewResult = AutoMocker.ClassUnderTest.DetailsForCurrentUser(achievementId, CurrentUser) as ViewResult;

            //--assert
            viewResult.ShouldNotBeNull();
            viewResult.ViewName.ShouldBe(MVC.Achievement.Views.Details);
            var firstCall =
                AutoMocker.Get <IPlayerAchievementRetriever>()
                .GetArgumentsForCallsMadeOn(x => x.GetPlayerAchievement(Arg <PlayerAchievementQuery> .Is.Anything));
            var query = firstCall.AssertFirstCallIsType <PlayerAchievementQuery>();

            query.AchievementId.ShouldBe(achievementId);
            query.ApplicationUserId.ShouldBe(CurrentUser.Id);
            query.GamingGroupId.ShouldBe(CurrentUser.CurrentGamingGroupId);
            var playerAchievementViewModel = viewResult.Model as PlayerAchievementViewModel;

            playerAchievementViewModel.ShouldBe(expectedPlayerAchievementViewModel);
        }
        public void It_Returns_The_Player_Achievement_For_The_Specified_Player()
        {
            //--arrange
            var achievementId = AchievementId.BusyBee;
            int playerId      = 1;
            var expectedPlayerAchievementDetails = new PlayerAchievementDetails();

            _autoMocker.Get <IPlayerAchievementRetriever>().Expect(mock => mock.GetPlayerAchievement(Arg <PlayerAchievementQuery> .Is.Anything))
            .Return(expectedPlayerAchievementDetails);
            var expectedViewModel = new PlayerAchievementViewModel();

            _autoMocker.Get <ITransformer>().Expect(mock => mock.Transform <PlayerAchievementViewModel>(expectedPlayerAchievementDetails))
            .Return(expectedViewModel);

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

            //--assert
            _autoMocker.Get <IPlayerAchievementRetriever>().AssertWasCalled(
                x => x.GetPlayerAchievement(Arg <PlayerAchievementQuery> .Matches(y => y.AchievementId == achievementId && y.PlayerId == playerId)));
            result.ShouldNotBeNull();
            var viewModel = result.Model as PlayerAchievementViewModel;

            viewModel.ShouldNotBeNull();
            viewModel.ShouldBeSameAs(expectedViewModel);
        }
Exemplo n.º 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);
        }
        public virtual PlayerAchievementDetails GetCurrentPlayerAchievementDetails(AchievementId achievementId, ApplicationUser currentUser)
        {
            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);

            if (currentUser.UserName == AnonymousApplicationUser.USER_NAME_ANONYMOUS)
            {
                return(result);
            }

            var playerForCurrentUser = _playerRetriever.GetPlayerForCurrentUser(currentUser.Id, currentUser.CurrentGamingGroupId);

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

                var achievementAwarded = achievement.IsAwardedForThisPlayer(playerForCurrentUser.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.Player.ApplicationUserId == currentUser.Id);

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

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

            return(result);
        }
Exemplo n.º 5
0
            public override void SetUp()
            {
                base.SetUp();

                _playerAchievementDetails = new PlayerAchievementDetails();

                _entityIds = new List <int> {
                    _expectedEntityId1, _expectedEntityId2
                };

                SetUpGameDefinitionStuff();

                SetUpPlayedGameStuff();

                _expectedPlayer1 = new Player
                {
                    Id            = _expectedEntityId1,
                    Name          = "aaa player 1 name",
                    GamingGroupId = 1000,
                    GamingGroup   = new GamingGroup
                    {
                        Name = "Gaming group name 1"
                    }
                };

                _expectedPlayer2 = new Player
                {
                    Id            = _expectedEntityId2,
                    Name          = "bbb player 2 name",
                    GamingGroupId = 1001,
                    GamingGroup   = new GamingGroup
                    {
                        Name = "Gaming group name 2"
                    }
                };

                var playerQueryable = new List <Player>
                {
                    _expectedPlayer2,
                    _expectedPlayer1,
                    new Player()
                }.AsQueryable();

                _autoMocker.Get <IDataContext>().Expect(mock => mock.GetQueryable <Player>()).Return(playerQueryable);
            }
Exemplo n.º 6
0
        internal virtual void SetRelatedEntities(AchievementGroup achievementGroup, PlayerAchievementDetails result, List <int> relatedEntityIds)
        {
            switch (achievementGroup)
            {
            case AchievementGroup.Game:
                var intermediateAnonymousResult = _dataContext.GetQueryable <GameDefinition>()
                                                  .Where(x => relatedEntityIds.Contains(x.Id))
                                                  .Select(x => new
                {
                    AchievementRelatedGameDefinitionSummary = new AchievementRelatedGameDefinitionSummary
                    {
                        Id            = x.Id,
                        Name          = x.Name,
                        GamingGroupId = x.GamingGroupId
                    },
                    x.BoardGameGeekGameDefinitionId
                })
                                                  .OrderBy(x => x.AchievementRelatedGameDefinitionSummary.Name)
                                                  .ToList();

                foreach (var recordWithABoardGameGeekGameDefinitionId in intermediateAnonymousResult.Where(x => x.BoardGameGeekGameDefinitionId != null))
                {
                    recordWithABoardGameGeekGameDefinitionId.AchievementRelatedGameDefinitionSummary.BoardGameGeekInfo =
                        _boardGameGeekGameDefinitionInfoRetriever.GetResults(recordWithABoardGameGeekGameDefinitionId.BoardGameGeekGameDefinitionId.Value);
                }
                result.RelatedGameDefinitions = intermediateAnonymousResult.Select(x => x.AchievementRelatedGameDefinitionSummary).ToList();
                break;

            case AchievementGroup.PlayedGame:
                result.RelatedPlayedGames = _dataContext.GetQueryable <PlayedGame>()
                                            .Where(y => relatedEntityIds.Contains(y.Id))
                                            .Select(x => new AchievementRelatedPlayedGameSummary
                {
                    GameDefinitionId = x.GameDefinitionId,
                    WinnerType       = x.WinnerType,
                    DatePlayed       = x.DatePlayed,
                    BoardGameGeekGameDefinitionId = x.GameDefinition.BoardGameGeekGameDefinitionId,
                    GameDefinitionName            = x.GameDefinition.Name,
                    PlayedGameId      = x.Id,
                    ThumbnailImageUrl = x.GameDefinition.BoardGameGeekGameDefinition.Thumbnail,
                    WinningPlayerName = x.PlayerGameResults.FirstOrDefault(y => y.GameRank == 1).Player.Name,
                    WinningPlayerId   = x.PlayerGameResults.FirstOrDefault(y => y.GameRank == 1).PlayerId
                })
                                            .OrderByDescending(x => x.DatePlayed)
                                            .ToList();
                break;

            case AchievementGroup.Player:
                result.RelatedPlayers = _dataContext.GetQueryable <Player>()
                                        .Where(x => relatedEntityIds.Contains(x.Id))
                                        .Select(x => new AchievementRelatedPlayerSummary
                {
                    PlayerId        = x.Id,
                    PlayerName      = x.Name,
                    GamingGroupId   = x.GamingGroupId,
                    GamingGroupName = x.GamingGroup.Name
                }).ToList();
                break;

            case AchievementGroup.NotApplicable:
                break;
            }
        }