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 static IEnumerable <PlayerAchievementViewModel> GetPlayerMaxStats() { IAchievementRepository repo = new EFAchievementRepository(); IEnumerable <Achievement> types = repo.Achievements.GroupBy(a => a.AchievementType).Select(grp => grp.FirstOrDefault()).ToList(); var output = new List <PlayerAchievementViewModel>(); foreach (var t in types) { var a = repo.Achievements.Where(b => b.AchievementType == t.AchievementType).OrderByDescending(b => b.Amount).ThenBy(b => b.Timestamp).FirstOrDefault(); if (a != null) { var addMe = new PlayerAchievementViewModel { Player = PlayerProcedures.GetPlayerFormViewModel_FromMembership(a.OwnerMembershipId), Achivement = a, }; output.Add(addMe); } } return(output); }
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); }
public static IEnumerable <PlayerAchievementViewModel> GetLeaderPlayersInStat(string type) { IAchievementRepository repo = new EFAchievementRepository(); var x = repo.Achievements.Where(a => a.AchievementType == type).OrderByDescending(s => s.Amount).ThenBy(a => a.Timestamp).Take(10).ToList(); var output = new List <PlayerAchievementViewModel>(); foreach (var a in x) { if (a != null) { var addMe = new PlayerAchievementViewModel { Player = PlayerProcedures.GetPlayerFormViewModel_FromMembership(a.OwnerMembershipId), Achivement = a, }; output.Add(addMe); } } return(output); }