Ejemplo n.º 1
0
        public async Task <CharacterView> AddTemporaryHpAsync(Guid id, AddTemporaryHp command)
        {
            var character = await _characterRepository.GetByIdAsync(id);

            character.Hp.AddTemporaryHp(command.TemporaryHp);
            await _characterRepository.SaveAsync(character);

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

            return(characterView);
        }
Ejemplo n.º 2
0
        public async Task AddTemporaryHpAsync_ShouldAddTempHpAndReturnCharacterView()
        {
            // Arrange
            var id          = Guid.NewGuid();
            var character   = new Character("SomeName", new HitPoints(42));
            var temporaryHp = new AddTemporaryHp {
                TemporaryHp = 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.AddTemporaryHpAsync(id, temporaryHp);

            // 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(42);
            result.TemporaryHp.Should().Be(5);
        }