public void AddTemporaryHpAddsTempHp() { int maxHp = 12; int currentHp = 5; int oldTempHp = 0; int newTempHp = 3; Character character = new Character() { MaxHp = maxHp, CurrentHp = currentHp, TempHp = oldTempHp }; TempHp tempHp = new TempHp() { Hp = newTempHp }; var mockDal = new Mock <ICharacterData>(); CharacterManager characterManager = new CharacterManager(mockDal.Object); mockDal.Setup(dal => dal.UpdateCharacter(character)).Returns(character); Character updatedCharacter = characterManager.AddTemporaryHp(character, tempHp); Assert.Equal(maxHp, updatedCharacter.MaxHp); Assert.Equal(currentHp, updatedCharacter.CurrentHp); Assert.Equal(newTempHp, updatedCharacter.TempHp); }
public ActionResult PostTempHp(long id, TempHp tempHp) { Character character = _characterManager.Get(id); if (character == null) { return(NotFound()); } character = _characterManager.AddTemporaryHp(character, tempHp); return(CreatedAtAction(nameof(GetCharacter), new { id = character.Id }, character)); }
public void AddTemporaryHpWithLessDoesNotReplacesExisting() { int oldTempHp = 4; int newTempHp = 3; Character character = new Character() { TempHp = oldTempHp }; TempHp tempHp = new TempHp() { Hp = newTempHp }; var mockDal = new Mock <ICharacterData>(); CharacterManager characterManager = new CharacterManager(mockDal.Object); mockDal.Setup(dal => dal.UpdateCharacter(character)).Returns(character); Character updatedCharacter = characterManager.AddTemporaryHp(character, tempHp); Assert.Equal(oldTempHp, updatedCharacter.TempHp); }
public Character AddTemporaryHp(Character character, TempHp tempHp) { character.TempHp = Math.Max(tempHp.Hp, character.TempHp); return(_characterData.UpdateCharacter(character)); }