public void PostElevatorDestination_ShouldEnqueueProperCommand()
        {
            //Arrange
            var elevatorId    = _fixture.Create <int>();
            var destinationId = _fixture.Create <int>();

            string           resultQueueId = string.Empty;
            GoToFloorCommand resultAction  = null;

            _elevatorMessagePublisher
            .Setup(s => s.EnqueueRequest(It.IsAny <string>(), It.IsAny <GoToFloorCommand>()))
            .Callback <string, GoToFloorCommand>((id, action) =>
            {
                resultQueueId = id;
                resultAction  = action;
            });

            //Act
            _sut.EnqueueElevatorDestination(elevatorId, destinationId);

            //Assert
            resultQueueId.Should().Be(ElevatorsMessagingHelper.GetQueueId(elevatorId));
            resultAction.Should().NotBeNull();
            resultAction.ElevatorId.Should().Be(elevatorId);
            resultAction.DestinationFloorId.Should().Be(destinationId);
            resultAction.ActionType.Should().Be(ElevatorCommandType.GoToFloor);
        }
        public void PostDoorState_ShouldEnqueueProperCommand(bool open)
        {
            //Arrange
            var elevatorId    = _fixture.Create <int>();
            var destinationId = _fixture.Create <int>();

            string resultQueueId             = string.Empty;
            ElevatorCommandBase resultAction = null;

            _elevatorMessagePublisher
            .Setup(s => s.EnqueueRequest(It.IsAny <string>(), It.IsAny <ElevatorCommandBase>()))
            .Callback <string, ElevatorCommandBase>((id, action) =>
            {
                resultQueueId = id;
                resultAction  = action;
            });

            var expectedAction = open ? ElevatorCommandType.OpenDoor : ElevatorCommandType.CloseDoor;

            //Act
            _sut.EnqueueDoorState(elevatorId, open);

            //Assert
            resultQueueId.Should().Be(ElevatorsMessagingHelper.GetQueueId(elevatorId));
            resultAction.Should().NotBeNull();
            resultAction.ElevatorId.Should().Be(elevatorId);
            resultAction.ActionType.Should().Be(expectedAction);
        }
Exemplo n.º 3
0
        public void EnqueueElevatorDestination(int elevatorId, int floorId)
        {
            _elevatorsValidationHelper.ValidateElevatorId(elevatorId);
            _elevatorsValidationHelper.ValidateFloorId(floorId);

            var action = new GoToFloorCommand
            {
                DestinationFloorId = floorId,
                ElevatorId         = elevatorId
            };

            _elevatorMessagePublisher.EnqueueRequest(ElevatorsMessagingHelper.GetQueueId(elevatorId), action);
        }
Exemplo n.º 4
0
        public void EnqueueDoorState(int elevatorId, bool isOpen)
        {
            _elevatorsValidationHelper.ValidateElevatorId(elevatorId);

            var action = new ElevatorCommandBase
            {
                ElevatorId = elevatorId,
                ActionType = isOpen
                    ? ElevatorCommandType.OpenDoor
                    : ElevatorCommandType.CloseDoor
            };

            _elevatorMessagePublisher.EnqueueRequest(ElevatorsMessagingHelper.GetQueueId(elevatorId), action);
        }
        public static IApplicationBuilder InstantiateElevators(this IApplicationBuilder app)
        {
            var elevatorsValidationHelper = app.ApplicationServices.GetService <IElevatorsValidationHelper>();
            var aggregateRepository       = app.ApplicationServices.GetService <IAggregateRepository>();
            var elevatorActionsConcumer   = app.ApplicationServices.GetService <IElevatorActionsConsumer>();

            for (int i = 0; i < elevatorsValidationHelper.NumberOfElevators; i++)
            {
                var aggregate = aggregateRepository.LoadAsync <Elevator>(i).Result;

                if (aggregate.Version == -1 || !elevatorsValidationHelper.IsValidFloorId(aggregate.CurrentFloor))
                {
                    aggregate.Create(i);
                    aggregateRepository.SaveAsync(aggregate).Wait();
                }

                elevatorActionsConcumer.ReadData(ElevatorsMessagingHelper.GetQueueId(i), new ElevatorActionHandler(aggregateRepository));
            }

            return(app);
        }