public virtual void UpdatePlayer(UpdatePlayerRequest updatePlayerRequest, ApplicationUser applicationUser) { var player = _dataContext.FindById<Player>(updatePlayerRequest.PlayerId); var somethingChanged = false; if (updatePlayerRequest.Active.HasValue) { player.Active = updatePlayerRequest.Active.Value; somethingChanged = true; } if (!string.IsNullOrWhiteSpace(updatePlayerRequest.Name)) { player.Name = updatePlayerRequest.Name.Trim(); somethingChanged = true; } if (somethingChanged) { Save(player, applicationUser); } }
public void ItUpdatesThePlayerName() { var updatePlayerRequest = new UpdatePlayerRequest { Name = "a new name", PlayerId = PLAYER_ID }; _autoMocker.ClassUnderTest.UpdatePlayer(updatePlayerRequest, _currentUser); _autoMocker.ClassUnderTest.AssertWasCalled( mock => mock.Save(Arg<Player>.Matches(p => p.Name == updatePlayerRequest.Name), Arg<ApplicationUser>.Is.Same(_currentUser))); }
public void ItUpdatesTheActiveFlag() { var updatePlayerRequest = new UpdatePlayerRequest { Active = true, PlayerId = PLAYER_ID }; _autoMocker.ClassUnderTest.UpdatePlayer(updatePlayerRequest, _currentUser); _autoMocker.ClassUnderTest.AssertWasCalled( mock => mock.Save(Arg<Player>.Matches(p => p.Active == updatePlayerRequest.Active.Value), Arg<ApplicationUser>.Is.Same(_currentUser))); }
public void ItDoesntBotherUpdatingIfNothingWasRequestedToBeUpdated() { var updatePlayerRequest = new UpdatePlayerRequest { Name = null, PlayerId = PLAYER_ID, Active = null }; _autoMocker.ClassUnderTest.UpdatePlayer(updatePlayerRequest, _currentUser); _autoMocker.ClassUnderTest.AssertWasNotCalled( mock => mock.Save(Arg<Player>.Is.Anything, Arg<ApplicationUser>.Is.Same(_currentUser))); }
public virtual HttpResponseMessage UpdatePlayer([FromBody]UpdatePlayerMessage updatePlayerMessage, [FromUri] int playerId, [FromUri]int gamingGroupId) { if (updatePlayerMessage == null) { return Request.CreateErrorResponse(HttpStatusCode.BadRequest, "You must pass at least one valid parameter."); } var requestedPlayer = new UpdatePlayerRequest { PlayerId = playerId, Active = updatePlayerMessage.Active, Name = updatePlayerMessage.PlayerName }; playerSaver.UpdatePlayer(requestedPlayer, CurrentUser); return Request.CreateResponse(HttpStatusCode.NoContent); }
public virtual ActionResult Edit([Bind(Include = "Id,Name,Active,GamingGroupId")] Player player, ApplicationUser currentUser) { if (ModelState.IsValid) { player.Name = player.Name.Trim(); var requestedPlayer = new UpdatePlayerRequest { PlayerId = player.Id, Active = player.Active, Name = player.Name, }; playerSaver.UpdatePlayer(requestedPlayer, currentUser); return new RedirectResult(Url.Action(MVC.GamingGroup.ActionNames.Index, MVC.GamingGroup.Name) + "#" + GamingGroupController.SECTION_ANCHOR_PLAYERS); } var playerEditViewModel = playerEditViewModelBuilder.Build(player); return View(MVC.Player.Views.Edit, playerEditViewModel); }