Ejemplo n.º 1
0
        public void ItReloadsTheGameDefinitionIfValidationFails()
        {
            var viewModel = new GameDefinitionEditViewModel();
            autoMocker.ClassUnderTest.ModelState.AddModelError("key", "message");

            var viewResult = autoMocker.ClassUnderTest.Edit(viewModel, currentUser) as ViewResult;

            Assert.AreSame(viewModel, viewResult.Model);
        }
Ejemplo n.º 2
0
        public void ItStaysOnTheEditPageIfValidationFails()
        {
            var viewModel = new GameDefinitionEditViewModel();

            autoMocker.ClassUnderTest.ModelState.AddModelError("key", "message");

            var viewResult = autoMocker.ClassUnderTest.Edit(viewModel, currentUser) as ViewResult;

            Assert.AreEqual(MVC.GameDefinition.Views.Edit, viewResult.ViewName);
        }
Ejemplo n.º 3
0
        public void ItRedirectsToTheGamingGroupIndexAndGameDefinitionsSectionAfterSaving()
        {
            var viewModel = new GameDefinitionEditViewModel
            {
                Name = "some name"
            };
            var baseUrl = "base url";
            var expectedUrl = baseUrl + "#" + GamingGroupController.SECTION_ANCHOR_GAMEDEFINITIONS;
            urlHelperMock.BackToRecord(BackToRecordOptions.All);
            urlHelperMock.Replay();
            urlHelperMock.Expect(mock => mock.Action(MVC.GamingGroup.ActionNames.Index, MVC.GamingGroup.Name))
                    .Return(baseUrl);

            var redirectResult = autoMocker.ClassUnderTest.Edit(viewModel, currentUser) as RedirectResult;

            Assert.AreEqual(expectedUrl, redirectResult.Url);
        }
Ejemplo n.º 4
0
        public void ItSavesTheGameDefinitionIfValidationPasses()
        {
            var viewModel = new GameDefinitionEditViewModel
            {
                Name = "some name"
            };

            autoMocker.ClassUnderTest.Edit(viewModel, currentUser);

            var arguments = autoMocker.Get<IGameDefinitionSaver>().GetArgumentsForCallsMadeOn(mock => mock.UpdateGameDefinition(
                Arg<GameDefinitionUpdateRequest>.Is.Anything,
                Arg<ApplicationUser>.Is.Anything));
            var gameDefinitionUpdateRequest = arguments[0][0] as GameDefinitionUpdateRequest;
            Assert.That(gameDefinitionUpdateRequest, Is.Not.Null);
            Assert.That(gameDefinitionUpdateRequest.Active, Is.EqualTo(viewModel.Active));
            Assert.That(gameDefinitionUpdateRequest.BoardGameGeekGameDefinitionId, Is.EqualTo(viewModel.BoardGameGeekGameDefinitionId));
            Assert.That(gameDefinitionUpdateRequest.Description, Is.EqualTo(viewModel.Description));
            Assert.That(gameDefinitionUpdateRequest.GameDefinitionId, Is.EqualTo(viewModel.GameDefinitionId));
            Assert.That(gameDefinitionUpdateRequest.Name, Is.EqualTo(viewModel.Name));
        }
 public virtual ActionResult Edit(GameDefinitionEditViewModel viewModel, ApplicationUser currentUser)
 {
     if (ModelState.IsValid)
     {
         viewModel.Name = viewModel.Name.Trim();
         var gameDefinitionUpdateRequest = Mapper.Map<GameDefinitionUpdateRequest>(viewModel);
         _gameDefinitionSaver.UpdateGameDefinition(gameDefinitionUpdateRequest, currentUser);
         return new RedirectResult(Url.Action(MVC.GamingGroup.ActionNames.Index, MVC.GamingGroup.Name)
                                   + "#" + GamingGroupController.SECTION_ANCHOR_GAMEDEFINITIONS);
     }
     return View(MVC.GameDefinition.Views.Edit, viewModel);
 }