public GameDefinitionSummaryViewModel Build(GameDefinitionSummary gameDefinitionSummary, ApplicationUser currentUser) { var viewModel = new GameDefinitionSummaryViewModel { Id = gameDefinitionSummary.Id, Name = gameDefinitionSummary.Name, Description = gameDefinitionSummary.Description, TotalNumberOfGamesPlayed = gameDefinitionSummary.TotalNumberOfGamesPlayed, GamingGroupId = gameDefinitionSummary.GamingGroupId, GamingGroupName = gameDefinitionSummary.GamingGroupName, BoardGameGeekInfo = _transformer.Transform <BoardGameGeekInfoViewModel>(gameDefinitionSummary.BoardGameGeekInfo), UserCanEdit = (currentUser != null && gameDefinitionSummary.GamingGroupId == currentUser.CurrentGamingGroupId) }; if (!(gameDefinitionSummary.Champion is NullChampion)) { viewModel.ChampionName = gameDefinitionSummary.Champion.Player.Name; viewModel.ChampionPlayerId = gameDefinitionSummary.Champion.Player.Id; } if (!(gameDefinitionSummary.PreviousChampion is NullChampion)) { viewModel.PreviousChampionName = gameDefinitionSummary.PreviousChampion.Player.Name; viewModel.PreviousChampionPlayerId = gameDefinitionSummary.PreviousChampion.Player.Id; } return(viewModel); }
public void FixtureSetUp() { transformer = new GameDefinitionSummaryViewModelBuilder(); List <PlayedGame> playedGames = new List <PlayedGame>(); playedGames.Add(new PlayedGame() { Id = 10 }); playedGames.Add(new PlayedGame() { Id = 11 }); championPlayer = new Player { Name = championName, Id = championPlayerId }; previousChampionPlayer = new Player { Name = previousChampionName, Id = previousChampionPlayerId }; champion = new Champion { Player = championPlayer, }; previousChampion = new Champion { Player = previousChampionPlayer }; gameDefinitionSummary = new GameDefinitionSummary() { Id = 1, Name = "game definition name", Description = "game definition description", GamingGroupId = gamingGroupid, GamingGroupName = "gaming group name", PlayedGames = playedGames, Champion = champion, PreviousChampion = previousChampion }; currentUser = new ApplicationUser() { CurrentGamingGroupId = gamingGroupid }; viewModel = transformer.Build(gameDefinitionSummary, currentUser); }
public void FixtureSetUp() { _transformer = new GameDefinitionSummaryViewModelBuilder(new Transformer(), new WeightTierCalculator()); List <PlayedGame> playedGames = new List <PlayedGame>(); playedGames.Add(new PlayedGame() { Id = 10 }); playedGames.Add(new PlayedGame() { Id = 11 }); _championPlayer = new Player { Name = _championName, Id = _championPlayerId }; _previousChampionPlayer = new Player { Name = _previousChampionName, Id = _previousChampionPlayerId }; _champion = new Champion { Player = _championPlayer, }; _previousChampion = new Champion { Player = _previousChampionPlayer }; _gameDefinitionSummary = new GameDefinitionSummary() { Id = 1, Name = "game definition name", Description = "game definition description", GamingGroupId = _gamingGroupid, GamingGroupName = "gaming group name", PlayedGames = playedGames, Champion = _champion, PreviousChampion = _previousChampion }; _currentUser = new ApplicationUser() { CurrentGamingGroupId = _gamingGroupid }; _viewModel = _transformer.Build(_gameDefinitionSummary, _currentUser); }
public void It_Returns_The_Game_Definitions_In_The_Specific_Gaming_Group_With_The_Specified_Date_Filter_Ordered_By_Total_Games_Played_Descending() { //--arrange var gamingGroupId = 1; var currentUser = new ApplicationUser(); var dateRangeFilter = new BasicDateRangeFilter(); var expectedResults = new List <GameDefinitionSummary> { new GameDefinitionSummary(), new GameDefinitionSummary() }; var expectedResult1 = new GameDefinitionSummaryViewModel { TotalNumberOfGamesPlayed = 1 }; var expectedResult2 = new GameDefinitionSummaryViewModel() { TotalNumberOfGamesPlayed = 2 }; autoMocker.Get <IGameDefinitionRetriever>().Expect(mock => mock.GetAllGameDefinitions(gamingGroupId, dateRangeFilter)).Return(expectedResults); autoMocker.Get <IGameDefinitionSummaryViewModelBuilder>().Expect(mock => mock.Build(expectedResults[0], currentUser)).Return(expectedResult1); autoMocker.Get <IGameDefinitionSummaryViewModelBuilder>().Expect(mock => mock.Build(expectedResults[1], currentUser)).Return(expectedResult2); //--act var result = autoMocker.ClassUnderTest.GetGamingGroupGameDefinitions(gamingGroupId, currentUser, dateRangeFilter); //--assert var viewResult = result as PartialViewResult; viewResult.ShouldNotBeNull(); viewResult.ViewName.ShouldBe(MVC.GameDefinition.Views._GameDefinitionsPartial); var model = viewResult.Model as List <GameDefinitionSummaryViewModel>; model.ShouldNotBeNull(); model.Count.ShouldBe(2); //--the second result is the one that has more total games and should be first model[0].ShouldBeSameAs(expectedResult2); model[1].ShouldBeSameAs(expectedResult1); }