Given_TestQuery_AndTestQueryHandlerNotRegistered_When_SendAsync_Then_HandlerNotFoundExceptionIsThrown() { //Arrange var query = new TestQuery { ReturnValue = "ReturnValue" }; Func <Type, object> resolver = type => null; var queryBus = new QueryBus(resolver); //Act Func <Task> handleAction = () => queryBus.SendAsync(query); //Assert Assert.ThrowsAsync <HandlerNotFoundException>(() => handleAction.Invoke()); }
Given_TestQuery_AndTestQueryHandlerNotRegistered_When_SendAsync_Then_HandlerNotFoundExceptionIsThrown() { //Arrange var services = new ServiceCollection(); var query = new TestQuery { ReturnValue = "ReturnValue" }; var serviceProvider = services.BuildServiceProvider(); var queryBus = new QueryBus(serviceProvider.GetService); //Act Func <Task> handleAction = () => queryBus.SendAsync(query); //Assert Assert.ThrowsAsync <HandlerNotFoundException>(() => handleAction.Invoke()); }
public async Task Given_TestQuery_When_SendAsync_Then_ResultIsReturned() { //Arrange var query = new TestQuery { ReturnValue = "ReturnValue" }; var queryHandler = new TestQueryHandler(); Func <Type, object> resolver = type => { return(queryHandler); }; var queryBus = new QueryBus(resolver); //Act var result = await queryBus.SendAsync(query, CancellationToken.None); //Assert Assert.That(result, Is.EqualTo(query.ReturnValue)); }
public async Task Given_TestQuery_When_SendAsync_Then_ResultIsReturned() { //Arrange var services = new ServiceCollection(); var query = new TestQuery { ReturnValue = "ReturnValue" }; var queryHandler = new TestQueryHandler(); services.AddScoped <IQueryHandler <TestQuery, string> >(provider => queryHandler); var serviceProvider = services.BuildServiceProvider(); var queryBus = new QueryBus(serviceProvider.GetService); //Act var result = await queryBus.SendAsync(query, CancellationToken.None); //Assert Assert.That(result, Is.EqualTo(query.ReturnValue)); }