public void Setup() { lifetimeScope = new Mock <IServiceScope>(); context = new ProducerConsumerContext <object>(Guid.NewGuid(), lifetimeScope.Object); consumer = new Mock <IConsumer <object> >(); resolver = new Mock <IConsumerResolver <object> >(); resolver.Setup(o => o.Resolve(context)).Returns(consumer.Object); }
private async Task <bool> RunAsyncImpl(Action <IProducerConsumerContext <TItem> > onProducedCallback, CancellationToken parentToken) { IServiceScope scope = null; try { scope = CreateChildScope(); ProducerConsumerContext <TItem> context = null; var called = false; try { var id = GenerateIdentifier(scope); context = new ProducerConsumerContext <TItem>(id, scope) { CancellationToken = parentToken, ProductionContext = { ExecutionStrategy = this } }; await AcquireSynchronizationLockAsync(context); await CreateProducerAsync(context); await ProduceAsync(context); if (ShouldExecuteCallback(context)) { onProducedCallback(context); called = true; } } finally { if (!called) { context?.Dispose(); } } return(called); } catch (Exception) { scope?.Dispose(); throw; } }