public async Task DeleteModifiersAsync(NaheulbookExecutionContext executionContext, int characterId, int characterModifierId) { using (var uow = _unitOfWorkFactory.CreateUnitOfWork()) { var character = await uow.Characters.GetWithGroupAsync(characterId); if (character == null) { throw new CharacterNotFoundException(characterId); } _authorizationUtil.EnsureCharacterAccess(executionContext, character); var characterModifier = await uow.CharacterModifiers.GetByIdAndCharacterIdAsync(characterId, characterModifierId); if (characterModifier == null) { throw new CharacterModifierNotFoundException(characterModifierId); } // TODO: workaround, will change after character history rework characterModifier.CharacterId = null; // uow.CharacterModifiers.Remove(characterModifier); uow.CharacterHistoryEntries.Add(_characterHistoryUtil.CreateLogRemoveModifier(characterId, characterModifierId)); await uow.SaveChangesAsync(); var session = _notificationSessionFactory.CreateSession(); session.NotifyCharacterRemoveModifier(characterId, characterModifierId); await session.CommitAsync(); } }
public async Task DeleteModifiersAsync_ShouldLogCharacterHistory() { const int characterId = 4; const int characterModifierId = 2; var characterHistoryEntry = new CharacterHistoryEntry(); _characterHistoryUtil.CreateLogRemoveModifier(characterId, characterModifierId) .Returns(characterHistoryEntry); _unitOfWorkFactory.GetUnitOfWork().Characters.GetWithGroupAsync(Arg.Any <int>()) .Returns(new Character()); _unitOfWorkFactory.GetUnitOfWork().CharacterModifiers.GetByIdAndCharacterIdAsync(Arg.Any <int>(), Arg.Any <int>()) .Returns(new CharacterModifier()); await _service.DeleteModifiersAsync(new NaheulbookExecutionContext(), characterId, characterModifierId); Received.InOrder(() => { _unitOfWorkFactory.GetUnitOfWork().CharacterHistoryEntries.Add(characterHistoryEntry); _unitOfWorkFactory.GetUnitOfWork().SaveChangesAsync(); }); }