private int CreateOrCheckId(int?id) { if (id.HasValue) { var idValue = id.Value; if (_actorContext.Contains(idValue)) { throw Error.AlreadyExists($"Actor with id {idValue} already exists"); } using (Lock.Enter(_freeIds)) { _freeIds.Remove(idValue); } return(idValue); } var actorId = Interlocked.Increment(ref _nextId); while (_actorContext.Contains(actorId)) { actorId = Interlocked.Increment(ref _nextId); } return(actorId); }
public void Contains() { _actorContext.Add(_actor); _actorContext.Contains(_actor.Id).Should().BeTrue(); }