示例#1
0
        public virtual ActionResult Details(int id, ApplicationUser currentUser, [System.Web.Http.FromUri] BasicDateRangeFilter dateRangeFilter = null)
        {
            if (dateRangeFilter == null)
            {
                dateRangeFilter = new BasicDateRangeFilter();
            }
            string errorMessage;

            if (!dateRangeFilter.IsValid(out errorMessage))
            {
                ModelState.AddModelError("dateRangeFilter", errorMessage);
            }

            var gamingGroupSummary = GetGamingGroupSummary(id, dateRangeFilter);
            var viewModel          = new GamingGroupViewModel
            {
                PublicDetailsView = new GamingGroupPublicDetailsViewModel
                {
                    GamingGroupId     = gamingGroupSummary.Id,
                    GamingGroupName   = gamingGroupSummary.Name,
                    PublicDescription = gamingGroupSummary.PublicDescription,
                    Website           = gamingGroupSummary.PublicGamingGroupWebsite,
                    Active            = gamingGroupSummary.Active
                },
                DateRangeFilter = dateRangeFilter,
                UserCanEdit     = currentUser.CurrentGamingGroupId == id
            };

            return(View(MVC.GamingGroup.Views.Details, viewModel));
        }
示例#2
0
        public virtual ActionResult GrantAccess(GamingGroupViewModel model, ApplicationUser currentUser)
        {
            if (ModelState.IsValid)
            {
                gamingGroupAccessGranter.CreateInvitation(model.InviteeEmail, currentUser);
                return(RedirectToAction(MVC.GamingGroup.ActionNames.Index));
            }

            return(RedirectToAction(MVC.GamingGroup.ActionNames.Index, model));
        }
示例#3
0
        public void ItDoesCreateInvitationIfTheEmailIsEmpty()
        {
            var model = new GamingGroupViewModel
            {
                InviteeEmail = string.Empty
            };

            autoMocker.ClassUnderTest.ViewData.ModelState.AddModelError("EmptyEmail", new Exception());
            autoMocker.ClassUnderTest.GrantAccess(model, currentUser);

            Assert.IsFalse(autoMocker.ClassUnderTest.ModelState.IsValid);
            autoMocker.Get <IGamingGroupAccessGranter>().AssertWasNotCalled(mock => mock.CreateInvitation(model.InviteeEmail, currentUser));
        }
示例#4
0
        public void ItGrantsAccessToTheSpecifiedEmailAddress()
        {
            var model = new GamingGroupViewModel
            {
                InviteeEmail = "*****@*****.**"
            };

            autoMocker.Get <IGamingGroupAccessGranter>().Expect(mock => mock.CreateInvitation(model.InviteeEmail, currentUser))
            .Repeat.Once();

            autoMocker.ClassUnderTest.GrantAccess(model, currentUser);

            autoMocker.Get <IGamingGroupAccessGranter>().VerifyAllExpectations();
        }
示例#5
0
        public virtual ActionResult Index(ApplicationUser currentUser)
        {
            var gamingGroupSummary = this.GetGamingGroupSummary(currentUser.CurrentGamingGroupId);

            GamingGroupViewModel viewModel = gamingGroupViewModelBuilder.Build(gamingGroupSummary, currentUser);

            viewModel.PlayedGames.ShowSearchLinkInResultsHeader = true;

            ViewBag.RecentGamesSectionAnchorText    = SECTION_ANCHOR_RECENT_GAMES;
            ViewBag.PlayerSectionAnchorText         = SECTION_ANCHOR_PLAYERS;
            ViewBag.GameDefinitionSectionAnchorText = SECTION_ANCHOR_GAMEDEFINITIONS;

            return(View(MVC.GamingGroup.Views.Index, viewModel));
        }
示例#6
0
        public override void SetUp()
        {
            base.SetUp();

            gamingGroupSummary = new GamingGroupSummary()
            {
                PlayedGames = new List <PlayedGame>()
            };
            gamingGroupViewModel = new GamingGroupViewModel();

            autoMocker.Get <IGamingGroupRetriever>().Expect(mock => mock.GetGamingGroupDetails(
                                                                currentUser.CurrentGamingGroupId,
                                                                GamingGroupController.MAX_NUMBER_OF_RECENT_GAMES))
            .Repeat.Once()
            .Return(gamingGroupSummary);

            autoMocker.Get <IGamingGroupViewModelBuilder>().Expect(mock => mock.Build(gamingGroupSummary, currentUser))
            .Return(gamingGroupViewModel);
        }
示例#7
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);
        }
示例#8
0
        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,
                    PanelTitle    = string.Format("Last {0} Played Games", details.Count),
                    UserCanEdit   = currentUser != null && currentUser.CurrentGamingGroupId == gamingGroupSummary.Id,
                    GamingGroupId = gamingGroupSummary.Id
                },
                PublicDetailsView = new GamingGroupPublicDetailsViewModel
                {
                    GamingGroupId     = gamingGroupSummary.Id,
                    PublicDescription = gamingGroupSummary.PublicDescription,
                    Website           = gamingGroupSummary.PublicGamingGroupWebsite
                }
            };

            return(viewModel);
        }
示例#9
0
        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))
            .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);
        }