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();
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandQueryContextTests"/> class.
 /// This happens for each separate test (NOT once for all tests in class).
 /// </summary>
 public CommandQueryContextTests()
 {
     _sqlSession = new Mock <IDatabaseSession>();
     _testable   = new CommandQueryContext(_sqlSession.Object);
 }