Ejemplo n.º 1
0
        public async Task RunQueueBacklogAsync_LocksAndUnlocks()
        {
            var asyncEventWorker          = Substitute.For <IAsyncEventWorker>();
            var asyncEventWorkerLockCache = Substitute.For <IAsyncEventWorkerLockCache>();
            var sut = new LockingAsyncEventWorker(asyncEventWorker, asyncEventWorkerLockCache);

            await sut.RunQueueBacklogAsync("queue1");

            Received.InOrder(() =>
            {
                asyncEventWorkerLockCache.EnsureInitialized();
                asyncEventWorkerLockCache.EnterQueueAsync("queue1");
                asyncEventWorker.RunQueueBacklogAsync("queue1");
                asyncEventWorkerLockCache.ExitQueue("queue1");
            });
        }
Ejemplo n.º 2
0
        public async Task RunQueueBacklogAsync_UnlocksOnException()
        {
            var asyncEventWorker          = Substitute.For <IAsyncEventWorker>();
            var asyncEventWorkerLockCache = Substitute.For <IAsyncEventWorkerLockCache>();
            var sut = new LockingAsyncEventWorker(asyncEventWorker, asyncEventWorkerLockCache);

            asyncEventWorker.RunQueueBacklogAsync("queue1").Throws(new DomainException());

            await Assert.ThrowsAsync <DomainException>(async() => await sut.RunQueueBacklogAsync("queue1"));

            Received.InOrder(() =>
            {
                asyncEventWorkerLockCache.EnsureInitialized();
                asyncEventWorkerLockCache.EnterQueueAsync("queue1");
                asyncEventWorkerLockCache.ExitQueue("queue1");
            });
        }