Пример #1
0
        public async Task create_airplane_with_existing_registration_number_failed_published_create_airplane_rejected()
        {
            _airplanesRepository.GetAsync(_airplaneRegistraionNumber)
            .Returns(new Airplane(_id, _airplaneRegistraionNumber, _model, _availableSeats, _requiredCrew));

            try
            {
                await _commandHandler.HandleAsync(_command, _correlationContext);
            }
            catch (Exception ex)
            {
                if (ex is BeComfyException)
                {
                    await _busPublisher.PublishAsync(new CreateAirplaneRejected(_command.AirplaneId,
                                                                                _command.AirplaneRegistrationNumber, _command.AirplaneModel, "airplane_already_exists",
                                                                                $"Airplane with registration number: '{_command.AirplaneRegistrationNumber}' already exists."
                                                                                ), _correlationContext);
                }
            }

            await _busPublisher
            .Received()
            .PublishAsync(Arg.Is <CreateAirplaneRejected>(e =>
                                                          e.Id == _command.AirplaneId &&
                                                          e.AirplaneRegistrationNumber == _command.AirplaneRegistrationNumber &&
                                                          e.Code == "airplane_already_exists" &&
                                                          e.Reason == $"Airplane with registration number: '{_command.AirplaneRegistrationNumber}' already exists."
                                                          ), _correlationContext);

            await _airplanesRepository.DeleteAsync(_id);
        }
Пример #2
0
        public async Task Handle_Async_Published_Delete_TodoItem_Rejected_If_TodoItem_With_Given_Id_Does_Not_Exist()
        {
            DeleteTodo command = new DeleteTodo(_id);

            _todoItemRepository
            .ExistsAsync(_id)
            .Returns(false);

            await Act(command);

            await _busPublisher
            .Received()
            .PublishAsync(Arg.Is <DeleteTodoItemRejected>(e => e.Id == command.Id && e.Code == "todo_item_does_not_exist" && e.Reason == $"TodoItem with id: '{command.Id}' was not found."), _context);
        }
Пример #3
0
        public async Task Handle_Async_Published_Create_TodoItem_Rejected_If_TodoItem_With_Given_Id_Exists()
        {
            CreateTodo command = new CreateTodo(_id, _title, _description, _isDone, _userId);

            _todoItemRepository
            .ExistsAsync(_id)
            .Returns(true);

            await Act(command);

            await _busPublisher
            .Received()
            .PublishAsync(Arg.Is <CreateTodoItemRejected>(e => e.Id == command.Id && e.Code == "todo_item_already_exists" && e.Reason == "Todo Item: already exists."), _context);
        }
Пример #4
0
        public async Task Handle_Async_Published_Update_TodoItem_Rejected_If_TodoItem_With_Given_Id_Does_Not_Exist()
        {
            UpdateTodo command = new UpdateTodo(_id, _title, _description, _isDone, _userId);

            _todoItemRepository
            .GetAsync(_id)
            .ReturnsNull();

            await Act(command);

            await _busPublisher
            .Received()
            .PublishAsync(Arg.Is <UpdateTodoItemRejected>(e => e.Id == command.Id && e.Code == "todo_item_does_not_exist" && e.Reason == $"TodoItem with id: '{command.Id}' was not found."), _context);
        }
Пример #5
0
        public async Task HandleAsync_If_Vehicle_Is_Tracked_Vehicle_Tracking_Stopped_Event_Published()
        {
            // Arrange
            _trackedVehicleRepository
            .ExistsAsync(_vehicleId)
            .Returns(true);

            // Act
            await _stopVehicleTrackingHandler.HandleAsync(_command);

            // Assert
            await _busPublisher
            .Received()
            .PublishAsync(Arg.Is <VehicleTrackingStoppedEvent>(e => e.VehicleId == _vehicleId));
        }
Пример #6
0
        public async Task HandleAsync_If_Vehicle_Is_Already_Tracked_Track_Rejection_Event_Published()
        {
            // Arrange
            _trackedVehicleRepository
            .ExistsAsync(_vehicleId)
            .Returns(true);

            // Act
            await _trackVehicleHandler.HandleAsync(_command);

            // Assert
            await _busPublisher
            .Received()
            .PublishAsync(Arg.Is <TrackVehicleRejectedEvent>(e => e.VehicleId == _vehicleId && e.Code == "vehicle_already_tracked"));
        }