Example #1
0
        public async Task <Lock> ChangeStateAsync(Guid id, string userId, LockState newState)
        {
            var entity = await _locksRepository.GetByIdAsync(id, userId).ConfigureAwait(false);

            if (entity == null)
            {
                return(null);
            }

            if (entity.State.Equals(newState))
            {
                return(entity);
            }

            var oldState = entity.State;

            entity.State = newState;

            var updatedLock = await _locksRepository.UpdateAsync(entity, userId).ConfigureAwait(false);

            if (updatedLock != null)
            {
                await _eventPublisher.SendLockChangedMessageAsync(updatedLock, oldState, newState, userId)
                .ConfigureAwait(false);
            }

            return(updatedLock);
        }
        public async Task UpdateAsync_CreateAndUpdate_LockUpdated()
        {
            // Arrage
            var @lock = _fixure.Create <Locks.Entities.Lock>();

            @lock.State = LockState.Created;
            var created = await _repository.TryCreateAsync(@lock, _userId);

            created.State = LockState.Locked;

            // Act
            var result = await _repository.UpdateAsync(created, _userId);

            // Assert
            result.Should().BeEquivalentTo(created, opt => opt.WithStrictOrdering());
        }