public void Initialize() { _bus = Substitute.For <IBus>(); _cabRideService = Substitute.For <ICabRideService>(); _cabRideService .BringCustomerToTheTrainStation(Arg.Any <Id <Customer> >(), Arg.Any <Location>()) .Returns(_fixture.Create <Ride>()); // Bootstrap var serviceProvider = new ServiceCollection() .UseDispatchingBroker() .AddTransient((s) => _bus) .AddTransient((s) => _cabRideService) .BuildServiceProvider(); _sut = serviceProvider.GetService <DriveCustomerToTrainStationHandler>(); }
public async Task Handle(DriveCustomerToTrainStation message) { Ride ride; try { var customerId = _driveCustomerToTrainStationMapper.MapToCustomerId(message); var customerLocation = _driveCustomerToTrainStationMapper.MapToCustomerLocation(message); ride = await _cabRideService.BringCustomerToTheTrainStation(customerId, customerLocation); } catch (Exception e) { var failed = _cabRideMapper.MapFailedEvent(message, e); await _messageBus.Enqueue(failed); return; } var success = _cabRideMapper.MapSuccessEvent(ride); await _messageBus.Enqueue(success); }