Exemplo n.º 1
0
        public virtual ActionResult Edit(int id, ApplicationUser currentUser)
        {
            var viewModel           = new PlayedGameEditViewModel();
            var gameDefinitionsList = this.gameDefinitionRetriever.GetAllGameDefinitions(currentUser.CurrentGamingGroupId);

            viewModel.GameDefinitions = gameDefinitionsList.Select(item => new SelectListItem
            {
                Text  = item.Name,
                Value = item.Id.ToString()
            }).ToList();
            viewModel.Players = this.GetAllPlayers(currentUser);

            if (id > 0)
            {
                var playedGame = this.playedGameRetriever.GetPlayedGameDetails(id);
                viewModel.PreviousGameId   = playedGame.Id;
                viewModel.GameDefinitionId = playedGame.GameDefinitionId;
                viewModel.DatePlayed       = playedGame.DatePlayed;
                viewModel.Notes            = playedGame.Notes;

                viewModel.PlayerRanks = playedGame.PlayerGameResults.Select(item => new PlayerRank {
                    GameRank = item.GameRank, PlayerId = item.PlayerId
                }).ToList();
                viewModel.ExistingRankedPlayerNames = playedGame.PlayerGameResults.Select(item => new { item.Player.Name, item.Player.Id }).ToDictionary(p => p.Name, q => q.Id);
                viewModel.Players = this.RemovePlayersFromExistingPlayerRanks(viewModel.Players.ToList(), viewModel.PlayerRanks);
            }

            return(View(viewModel));
        }
Exemplo n.º 2
0
        public virtual ActionResult Create(ApplicationUser currentUser)
        {
            var gameDefinitionSummaries = gameDefinitionRetriever.GetAllGameDefinitions(currentUser.CurrentGamingGroupId);

            SelectList gameDefinitionSummariesSelectList = BuildGameDefinitionSummariesSelectList(gameDefinitionSummaries);
            var        viewModel = new PlayedGameEditViewModel
            {
                GameDefinitions = gameDefinitionSummariesSelectList,
                Players         = this.GetAllPlayers(currentUser)
            };

            return(View(MVC.PlayedGame.Views.Create, viewModel));
        }
Exemplo n.º 3
0
        public void ThatPreviousGameIsDeleted()
        {
            //--Arrange
            var viewModel = new PlayedGameEditViewModel();

            autoMocker.ClassUnderTest.Url.Expect(mock => mock.Action(MVC.GamingGroup.ActionNames.Index, MVC.GamingGroup.Name))
            .Return("some url");

            //--Act
            autoMocker.ClassUnderTest.Edit(viewModel, 1234, base.currentUser);

            //--Assert
            autoMocker.Get <IPlayedGameDeleter>().AssertWasCalled(mock => mock.DeletePlayedGame(Arg <int> .Is.NotNull, Arg <ApplicationUser> .Is.Anything));
        }
Exemplo n.º 4
0
        public void ItStaysOnEditPageIfValidationFails()
        {
            //--Arrange
            var editedGame = new PlayedGameEditViewModel();

            autoMocker.PartialMockTheClassUnderTest();
            autoMocker.ClassUnderTest.ModelState.AddModelError("Model", "is bad you fool");

            //--Act
            var result = autoMocker.ClassUnderTest.Edit(editedGame, 1234, base.currentUser) as RedirectToRouteResult;

            //--Assert
            Assert.AreEqual("Edit", result.RouteValues["action"]);
        }
Exemplo n.º 5
0
        public void ThatEditPostActionReturnsAView()
        {
            //--Arrange
            var editedGame = new PlayedGameEditViewModel();

            autoMocker.PartialMockTheClassUnderTest();
            autoMocker.ClassUnderTest.Expect(mock => mock.Edit(Arg <PlayedGameEditViewModel> .Is.Anything, Arg <int> .Is.NotNull, Arg <ApplicationUser> .Is.Anything)).Return(new ViewResult {
                ViewName = MVC.GamingGroup.Views.Index
            });

            //--Act
            var result = autoMocker.ClassUnderTest.Edit(editedGame, 1234, base.currentUser) as ViewResult;

            //--Assert
            Assert.AreEqual(MVC.GamingGroup.Views.Index, result.ViewName);
        }
Exemplo n.º 6
0
        public void ThatItSavesTheGame()
        {
            //--Arrange
            var editedGame = new NewlyCompletedGame();
            var viewModel  = new PlayedGameEditViewModel();

            Mapper.Map(viewModel, editedGame);

            //--Act
            autoMocker.ClassUnderTest.Edit(viewModel, 1234, currentUser);

            //--Assert
            autoMocker.Get <IPlayedGameCreator>().AssertWasCalled(mock => mock.CreatePlayedGame(
                                                                      Arg <NewlyCompletedGame> .Is.Anything,
                                                                      Arg <TransactionSource> .Is.Anything,
                                                                      Arg <ApplicationUser> .Is.Anything));
        }
Exemplo n.º 7
0
        public void ItSetsTheGameDefinitionsOnTheViewModel()
        {
            int gameDefinitionId = 1;
            var gameDefinitions  = new List <GameDefinitionSummary>
            {
                new GameDefinitionSummary
                {
                    Id = gameDefinitionId
                }
            };

            autoMocker.Get <IGameDefinitionRetriever>().Expect(mock => mock.GetAllGameDefinitions(currentUser.CurrentGamingGroupId))
            .Return(gameDefinitions);

            ViewResult result = autoMocker.ClassUnderTest.Create(currentUser) as ViewResult;

            PlayedGameEditViewModel viewModel = (PlayedGameEditViewModel)result.Model;

            Assert.That(viewModel.GameDefinitions.All(item => item.Value == gameDefinitionId.ToString()), Is.True);
        }
Exemplo n.º 8
0
        public void ItSetsTheSelectedGameDefinitionToTheFirstOneIfThereIsOnlyOne()
        {
            autoMocker = new RhinoAutoMocker <PlayedGameController>();
            autoMocker.Get <IPlayerRetriever>().Expect(x => x.GetAllPlayers(currentUser.CurrentGamingGroupId)).Repeat.Once().Return(allPlayers);

            int gameDefinitionId = 1;
            var gameDefinitions  = new List <GameDefinitionSummary>
            {
                new GameDefinitionSummary
                {
                    Id = gameDefinitionId
                }
            };

            autoMocker.Get <IGameDefinitionRetriever>().Expect(mock => mock.GetAllGameDefinitions(currentUser.CurrentGamingGroupId))
            .IgnoreArguments()
            .Return(gameDefinitions);

            ViewResult result = autoMocker.ClassUnderTest.Create(currentUser) as ViewResult;

            PlayedGameEditViewModel viewModel = (PlayedGameEditViewModel)result.Model;

            Assert.That(viewModel.GameDefinitions.First(x => x.Selected).Value, Is.EqualTo(gameDefinitionId.ToString()));
        }