public async Task ThrowIfProcessorNotRegistered() { var emitter = new DependencyCollection() .AddEmitter() .BuildProvider() .GetRequiredService <Emitter>(); await Assert.ThrowsAsync <KeyNotFoundException>(() => emitter.Ask(Mock.Of <Query>())); await Assert.ThrowsAsync <KeyNotFoundException>(() => emitter.Execute(Mock.Of <Command>())); await Assert.ThrowsAsync <KeyNotFoundException>(() => emitter.Send(Mock.Of <ICommand>())); }
public async Task ReturnFromActionQueryProcessorWithContext() { var emitter = new DependencyCollection() .AddInstance(_repository.Object) .AddEmitter() .AddQueryProcessor <Query, IBooRepository, Boo>((query, repository) => repository.GetElement(query.Id)) .BuildProvider() .GetRequiredService <Emitter>(); var getBooQuery = new Query { Id = 1 }; var boo = await emitter.Ask(getBooQuery); boo.Id.Should().Be(getBooQuery.Id); }
public async Task ThrowCancellation(Query query) { var cancellationTokenSource = new CancellationTokenSource(); var token = cancellationTokenSource.Token; cancellationTokenSource.Cancel(); var emitter = new DependencyCollection() .AddInstance(_repository.Object) .AddEmitter() .AddQueryProcessor <Processor>() .BuildProvider() .GetRequiredService <Emitter>(); await Assert.ThrowsAsync <OperationCanceledException>(() => emitter.Ask(query, token)); }
public async Task ReturnFromActionQueryProcessor() { var emitter = new DependencyCollection() .AddEmitter() .AddQueryProcessor <Query, Boo>(q => new Boo { Id = q.Id }) .BuildProvider() .GetRequiredService <Emitter>(); var getBooQuery = new Query { Id = 1 }; var boo = await emitter.Ask(getBooQuery); boo.Id.Should().Be(getBooQuery.Id); }