Esempio n. 1
0
        public async Task Query_SessionAndQuery_QueryExecutedWithSession()
        {
            var query = new Mock <IQuery <int> >();
            await _testable.QueryAsync(query.Object);

            query.Verify(q => q.ExecuteAsync(_sqlSession.Object, CancellationToken.None), Times.Once);
        }
        public async Task QueryAsync_NoCancellationToken_Waits()
        {
            var sessionLogger = new XUnitLogger <SqlDatabaseSession>(_output);
            var sess          = new SqlDatabaseSession(_sut, sessionLogger);
            var cqrs          = new CommandQueryContext(sess);

            var result = await cqrs.QueryAsync(new LongQuery());

            result.Should().Be(1);
            _sut.ExecutionTime.Should().BeGreaterThan(TimeSpan.FromSeconds(9));
            _sut.Dispose();
        }
        public async Task QueryAsync_CancellationToken_GetsCancelled()
        {
            var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(3));
            var sessionLogger           = new XUnitLogger <SqlDatabaseSession>(_output);
            var sess = new SqlDatabaseSession(_sut, sessionLogger);
            var cqrs = new CommandQueryContext(sess);

            var resultTask = cqrs.QueryAsync(new LongQuery(), cancellationTokenSource.Token);

            try
            {
                if (!resultTask.Wait(TimeSpan.FromSeconds(5)))
                {
                    throw new TimeoutException("Async Query Cancellation did not happen."); // should have cancelled
                }
            }
            catch (AggregateException agg)
            {
                Assert.True(agg.InnerException.GetType().Name == "SqlException");
            }

            _sut.Dispose();
        }