예제 #1
0
        public async Task <CharacterView> HealHpAsync(Guid id, HealHp command)
        {
            var character = await _characterRepository.GetByIdAsync(id);

            character.Hp.HealHp(command.Hp);
            await _characterRepository.SaveAsync(character);

            var characterView = new CharacterView(character);
            await _eventBus.PublishAsync <CharacterView>(characterView);

            return(characterView);
        }
예제 #2
0
        public async Task HealHpAsync_ShouldHealHpAndReturnCharacterView()
        {
            // Arrange
            var id        = Guid.NewGuid();
            var character = new Character("SomeName", new HitPoints(42));

            character.Hp.CurrentHp = 30;
            var healingHp = new HealHp {
                Hp = 5
            };

            _characterRepository.Setup(x => x.GetByIdAsync(It.Is <Guid>(expected => expected == id)))
            .ReturnsAsync(character);
            _characterRepository.Setup(x => x.SaveAsync(It.IsAny <Character>()));
            _eventBus.Setup(x => x.PublishAsync <CharacterView>(It.IsAny <CharacterView>()));
            // Act
            CharacterView result = await _instance.HealHpAsync(id, healingHp);

            // Assert
            _characterRepository.Verify(x => x.SaveAsync(It.Is <Character>(expected => expected == character)), Times.Once);
            _eventBus.Verify(x => x.PublishAsync <CharacterView>(It.Is <CharacterView>(expected => expected == result)), Times.Once);
            result.CurrentHp.Should().Be(35);
        }