Exemplo n.º 1
0
        public void Initialize()
        {
            _messageBus     = Substitute.For <IQueue>();
            _cabRideService = Substitute.For <ICabRideService>();
            _driveCustomerToTrainStationMapper = Substitute.For <IDriveCustomerToTrainStationMapper>();
            _cabRideMapper = Substitute.For <ICabRideMapper>();

            _driveCustomerToTrainStationMapper
            .MapToCustomerId(Arg.Any <DriveCustomerToTrainStation>())
            .Returns(_fixture.Create <Id <Customer> >());

            _driveCustomerToTrainStationMapper
            .MapToCustomerLocation(Arg.Any <DriveCustomerToTrainStation>())
            .Returns(_fixture.Create <Location>());

            _cabRideMapper
            .MapFailedEvent(Arg.Any <DriveCustomerToTrainStation>(), Arg.Any <Exception>())
            .Returns(_fixture.Create <DriveCustomerToTrainStationFailed>());

            _cabRideMapper
            .MapSuccessEvent(Arg.Any <Ride>())
            .Returns(_fixture.Create <DroveCustomerToTrainStation>());

            _sut = new DriveCustomerToTrainStationHandler(_messageBus, _cabRideService, _driveCustomerToTrainStationMapper, _cabRideMapper);
        }
Exemplo n.º 2
0
        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);
        }