Inheritance: IEditableViewModel
Beispiel #1
0
        public override void SetUp()
        {
            base.SetUp();

            gamingGroupSummary = new GamingGroupSummary()
            {
                PlayedGames = new List<PlayedGame>()
            };
            _gamingGroupViewModel = new GamingGroupViewModel();
            dateRangeFilter = new BasicDateRangeFilter();

            autoMocker.ClassUnderTest.Expect(mock => mock.GetGamingGroupSummary(
                Arg<int>.Is.Anything,
                Arg<IDateRangeFilter>.Is.Anything))
                .Repeat.Once()
                .Return(gamingGroupSummary);

            autoMocker.Get<IGamingGroupViewModelBuilder>().Expect(mock => mock.Build(gamingGroupSummary, currentUser))
                .Return(_gamingGroupViewModel);
        }
        public GamingGroupViewModel Build(GamingGroupSummary gamingGroupSummary, ApplicationUser currentUser = null)
        {
            List<PlayedGameDetailsViewModel> details = BuildPlayedGameDetailsViewModels(gamingGroupSummary, currentUser);

            List<PlayerWithNemesisViewModel> playerWithNemesisList
                = (from PlayerWithNemesis playerWithNemesis in gamingGroupSummary.Players
                   select playerWithNemesisViewModelBuilder.Build(playerWithNemesis, currentUser)).ToList();

            var viewModel = new GamingGroupViewModel()
            {
                Id = gamingGroupSummary.Id,
                OwningUserId = gamingGroupSummary.OwningUserId,
                Name = gamingGroupSummary.Name,
                OwningUserName = gamingGroupSummary.OwningUser.UserName,

                Players = playerWithNemesisList,
                GameDefinitionSummaries = gamingGroupSummary.GameDefinitionSummaries
                    .Select(game => gameDefinitionSummaryViewModelBuilder.Build(game, currentUser))
                    .OrderByDescending(game=>game.TotalNumberOfGamesPlayed)
                    .ToList(),
                PlayedGames = new PlayedGamesViewModel
                {
                    PlayedGameDetailsViewModels = details,
                    UserCanEdit = currentUser != null && currentUser.CurrentGamingGroupId == gamingGroupSummary.Id,
                    GamingGroupId = gamingGroupSummary.Id
                },
                PublicDetailsView = new GamingGroupPublicDetailsViewModel
                {
                    GamingGroupId = gamingGroupSummary.Id,
                    PublicDescription = gamingGroupSummary.PublicDescription,
                    Website = gamingGroupSummary.PublicGamingGroupWebsite
                }
            };

            return viewModel;
        }
        public void SetUp()
        {
            playerWithNemesisViewModelBuilderMock = MockRepository.GenerateMock<IPlayerWithNemesisViewModelBuilder>();
            playedGameDetailsViewModelBuilderMock = MockRepository.GenerateMock<IPlayedGameDetailsViewModelBuilder>();
            gameDefinitionSummaryViewModelBuilderMock = MockRepository.GenerateMock<IGameDefinitionSummaryViewModelBuilder>();
            transformer = new GamingGroupViewModelBuilder(
                playedGameDetailsViewModelBuilderMock,
                playerWithNemesisViewModelBuilderMock,
                gameDefinitionSummaryViewModelBuilderMock);
            players = new List<PlayerWithNemesis>()
            {
                new PlayerWithNemesis(){ PlayerId = 1 },
                new PlayerWithNemesis(){ PlayerId = 2 }
            };
            gameDefinitionSummaries = new List<GameDefinitionSummary>
            {
                new GameDefinitionSummary{ Id = 1 },
                new GameDefinitionSummary{ Id = 2 }
            };

            playedGames = new List<PlayedGame>();
            ApplicationUser owningUser = new ApplicationUser()
            {
                Id = "owning user user Id",
                Email = "*****@*****.**",
                UserName = "******"
            };
            ApplicationUser registeredUser = new ApplicationUser()
            {
                Email = "*****@*****.**",
                Id = "registered user id",
                UserName = "******"
            };
            GamingGroupInvitation invitation = new GamingGroupInvitation()
            {
                DateRegistered = DateTime.UtcNow,
                RegisteredUserId = "registered user id",
                RegisteredUser = registeredUser
            };
            gamingGroupSummary = new GamingGroupSummary()
            {
                Id = 1,
                Name = "gaming group",
                OwningUserId = owningUser.Id,
                OwningUser = owningUser,
                GamingGroupInvitations = new List<GamingGroupInvitation>() { invitation },
                Players = players,
                GameDefinitionSummaries = gameDefinitionSummaries,
                PlayedGames = playedGames
            };

            playedGameDetailsViewModelBuilderMock.Expect(mock => mock.Build(
                Arg<PlayedGame>.Is.Anything,
                Arg<ApplicationUser>.Is.Anything,
                Arg<bool>.Is.Anything))
                .Return(new PlayedGameDetailsViewModel());

            currentUser = new ApplicationUser();

            foreach(PlayerWithNemesis playerWithNemesis in players)
            {
                playerWithNemesisViewModelBuilderMock.Expect(mock => mock.Build(playerWithNemesis, this.currentUser))
                    .Return(new PlayerWithNemesisViewModel() { PlayerId = playerWithNemesis.PlayerId });
            }

            foreach (GameDefinitionSummary summary in gameDefinitionSummaries)
            {
                gameDefinitionSummaryViewModelBuilderMock.Expect(mock => mock.Build(summary, currentUser))
                                                  .Return(new GameDefinitionSummaryViewModel { Id = summary.Id });
            }

            viewModel = transformer.Build(gamingGroupSummary, currentUser);
        }