Exemplo n.º 1
0
        internal async Task <TEvent> Expect <TEvent>(ExpectTimeout timeout, bool scheduled) where TEvent : Event
        {
            if (_subscriptionDroppedError != null)
            {
                throw _subscriptionDroppedError;
            }

            var eventType = _area.Events.Get <TEvent>();

            _pendingExpect = new PendingExpect(eventType, timeout);

            if (!_nextPoints.TryDequeue(out var nextPoint))
            {
                await _pendingExpect.WaitForNextPoint();

                _nextPoints.TryDequeue(out nextPoint);
            }

            if (nextPoint.Scheduled && !scheduled)
            {
                throw new ExpectException($"Expected an unscheduled event: {nextPoint}");
            }
            else if (!nextPoint.Scheduled && scheduled)
            {
                throw new ExpectException($"Expected a scheduled event: {nextPoint}");
            }
            else if (nextPoint.Event is TEvent e)
            {
                return(e);
            }
            else
            {
                throw new ExpectException($"Expected an event of type {eventType}, received {nextPoint.Type}");
            }
        }
Exemplo n.º 2
0
        internal async Task <TQuery> Get <TQuery>(ExpectTimeout timeout) where TQuery : Query
        {
            var pendingGet = null as TimedWait;

            lock (_updateLock)
            {
                if (IsInitial)
                {
                    return((TQuery)_key.Type.New());
                }

                if (IsLatest)
                {
                    return((TQuery)_query);
                }

                pendingGet = timeout.ToTimedWait();

                _pendingGet = pendingGet;
            }

            await pendingGet.Task;

            _pendingGet = null;

            return((TQuery)_query);
        }
Exemplo n.º 3
0
        internal async Task <TQuery> GetQuery <TQuery>(Id instanceId, ExpectTimeout timeout) where TQuery : Query
        {
            var key = _area.Queries.Get <TQuery>().CreateKey(instanceId);

            await GetQueryInstance(key).WaitForLatest(timeout);

            return((TQuery)await _clientDb.ReadQueryContent(key));
        }
Exemplo n.º 4
0
        internal PendingExpect(EventType eventType, ExpectTimeout timeout)
        {
            _eventType = eventType;
            _timeout   = timeout;

            _tokenSource = new CancellationTokenSource(timeout.TimeSpan);

            _tokenSource.Token.Register(SetTimedOut);
        }
Exemplo n.º 5
0
        public async Task <TEvent> Dequeue <TEvent>(ExpectTimeout timeout, bool scheduled) where TEvent : Event
        {
            if (_error != null)
            {
                throw new ExpectException($"Event {typeof(TEvent)} did not occur as expected", _error);
            }

            if (!_nextPoints.TryDequeue(out var nextPoint))
            {
                _nextPointWait = timeout.ToTimedWait();

                if (!_nextPoints.TryDequeue(out nextPoint))
                {
                    try
                    {
                        await _nextPointWait.Task;
                    }
                    catch (Exception error)
                    {
                        throw new ExpectException($"Event {typeof(TEvent)} did not occur as expected", error);
                    }
                    finally
                    {
                        _nextPointWait = null;
                    }

                    _nextPoints.TryDequeue(out nextPoint);
                }
            }

            if (nextPoint.Scheduled && !scheduled)
            {
                throw new ExpectException($"Expected an unscheduled event: {nextPoint}");
            }
            else if (!nextPoint.Scheduled && scheduled)
            {
                throw new ExpectException($"Expected a scheduled event: {nextPoint}");
            }
            else if (nextPoint.Event is TEvent e)
            {
                return(e);
            }
            else
            {
                throw new ExpectException($"Expected an event of type {typeof(TEvent)}, received {nextPoint.Type.DeclaredType}");
            }
        }
Exemplo n.º 6
0
        internal async Task WaitForLatest(ExpectTimeout timeout)
        {
            var latestWait = null as TimedWait;

            lock (_updateLock)
            {
                if (IsLatest)
                {
                    return;
                }

                latestWait = timeout.ToTimedWait();

                _latestWait = latestWait;
            }

            await latestWait.Task;

            _latestWait = null;
        }
Exemplo n.º 7
0
        internal async Task ExpectDone(ExpectTimeout timeout)
        {
            var pendingDone = null as TimedWait;

            lock (_updateLock)
            {
                if (IsLatest && IsDone)
                {
                    return;
                }

                pendingDone = timeout.ToTimedWait();

                _pendingDone = pendingDone;
            }

            await pendingDone.Task;

            _pendingDone = null;
        }
Exemplo n.º 8
0
 internal Task <TEvent> Expect <TEvent>(ExpectTimeout timeout, bool scheduled) where TEvent : Event =>
 _app.Expect <TEvent>(timeout, scheduled);
Exemplo n.º 9
0
 internal Task ExpectDone(Id instanceId, ExpectTimeout timeout) =>
 GetInstance(instanceId).ExpectDone(timeout);
Exemplo n.º 10
0
 internal Task <TQuery> GetQuery <TQuery>(Id instanceId, ExpectTimeout timeout) where TQuery : Query =>
 GetInstance(instanceId).Get <TQuery>(timeout);
Exemplo n.º 11
0
 internal Task ExpectDone(Id instanceId, ExpectTimeout timeout) =>
 _app.ExpectDone(instanceId, timeout);
Exemplo n.º 12
0
 internal Task <TQuery> GetQuery <TQuery>(Id instanceId, ExpectTimeout timeout) where TQuery : Query =>
 _app.GetQuery <TQuery>(instanceId, timeout);
Exemplo n.º 13
0
        protected async Task <TEvent> ExpectScheduled <TEvent>(ExpectTimeout timeout = null) where TEvent : Event
        {
            var host = await GetOrStartHost();

            return(await host.Expect <TEvent>(timeout ?? ExpectTimeout.Default, scheduled : true));
        }
Exemplo n.º 14
0
 protected Task <TEvent> ExpectScheduled <TEvent>(ExpectTimeout timeout = null) where TEvent : Event =>
 Timeline.Expect <TEvent>(timeout ?? ExpectTimeout.Default, scheduled : true);
Exemplo n.º 15
0
 protected Task <TQuery> GetQuery <TQuery>(ExpectTimeout timeout = null) where TQuery : Query =>
 GetQuery <TQuery>(Id.Unassigned, timeout);
Exemplo n.º 16
0
 internal Task <TEvent> Expect <TEvent>(ExpectTimeout timeout, bool scheduled) where TEvent : Event =>
 _expectQueue.Dequeue <TEvent>(timeout, scheduled);
Exemplo n.º 17
0
        protected async Task <TQuery> GetQuery <TQuery>(Id instanceId, ExpectTimeout timeout = null) where TQuery : Query
        {
            var host = await GetOrStartHost();

            return(await host.GetQuery <TQuery>(instanceId, timeout ?? ExpectTimeout.Default));
        }