Exemplo n.º 1
0
        public async Task Dispose_DisposeSessionPool_DestroyAllSessions()
        {
            var mockCreator  = new Mock <Func <Task <Session> > >();
            var mockSession1 = new Mock <Session>(null, null, null, null, null);
            var mockSession2 = new Mock <Session>(null, null, null, null, null);

            mockCreator.SetupSequence(x => x()).ReturnsAsync(mockSession1.Object).ReturnsAsync(mockSession2.Object);

            var pool = new SessionPool(mockCreator.Object, QldbDriverBuilder.CreateDefaultRetryHandler(NullLogger.Instance), 2, NullLogger.Instance);

            var session1 = await pool.GetSession();

            var session2 = await pool.GetSession();

            session1.Release();
            session2.Release();

            await pool.DisposeAsync();

            mockSession1.Verify(s => s.End(It.IsAny <CancellationToken>()), Times.Exactly(1));
            mockSession2.Verify(s => s.End(It.IsAny <CancellationToken>()), Times.Exactly(1));
        }