public Task Transmit(CurrentRoverPosition currentRoverPosition) { // Usually this will be some sort of DTO to decouple // domain value type from its outgoing representation Console.WriteLine(currentRoverPosition.ToString()); return(Task.CompletedTask); }
public async Task StartRoverOperation() { var commandsToExecute = await roverCommandRetriever.GetAll(); EnsureNotEmpty(commandsToExecute); // Assumption: we are going to operate rovers sequentially // i.e. the first rover will execute all its commands, then the next and so on... foreach (var roverCommand in commandsToExecute) { if (roverCommand.ManouvreCommands.Any()) { var rover = RoverFactory.CreateWith(roverCommand); foreach (var manouvreCommand in roverCommand.ManouvreCommands) { // This is not necessarily the prettiest because if NASA asks me to extend // the capability of the Rover, then I will have to change rover, use case, // parser and add an extra RoverCommands member. This surface area could be // reduced by moving the responsbility of instantiating the rover and // mapping input to rover functions via delegates, into the parser itself // since each parser will need to determine that for itself anyway. The use // case will then simply loop over all the commands and execute them one by // one without having to know which is which (i.e. no switch...case). // Ofcourse, this only works as long as the commands have a homogenous // signature and return types. For now though, this will do since we are not // extending rover behaviour! CurrentRoverPosition currentRoverPosition = default; switch (manouvreCommand) { case RoverCommands.TurnLeft: currentRoverPosition = rover.TurnLeft(); break; case RoverCommands.TurnRight: currentRoverPosition = rover.TurnRight(); break; case RoverCommands.Move: currentRoverPosition = rover.Move(); break; default: throw new InvalidOperationException( $"Rover command {manouvreCommand} is not supported!"); } await roverPositionTransmitter.Transmit( currentRoverPosition); } } } }
public void ShouldProcessCommandsAndMoveRover2() { var testTransmitter = new TestTransmitter(); Program.TransmitterToUse = testTransmitter; Program.Main(new[] { "5 5", "1 2 N", "LML" }); var expectedFinalPositionOfRover = new CurrentRoverPosition(Guid.NewGuid(), 0, 2, Direction.South); testTransmitter.FinalRoverPosition .CurrentX.Should().Be(expectedFinalPositionOfRover.CurrentX); testTransmitter.FinalRoverPosition .CurrentY.Should().Be(expectedFinalPositionOfRover.CurrentY); testTransmitter.FinalRoverPosition .CurrentHeading.Should().Be(expectedFinalPositionOfRover.CurrentHeading); }
public async Task ShouldProcessCommandsAndMoveRover() { var testTransmitter = new TestTransmitter(); var useCase = new RoverOperationUsecase( new CommandLineInputParser(new[] { "5 5", "1 2 N", "LML" }), testTransmitter); // even though the rover will have undergone intermediate positions, // I only need to assert on the final position. If that's correct, // then the rover obviously made the right movements to end up at the final position var expectedFinalPositionOfRover = new CurrentRoverPosition(Guid.NewGuid(), 0, 2, Direction.South); await useCase.StartRoverOperation(); testTransmitter.FinalRoverPosition .CurrentX.Should().Be(expectedFinalPositionOfRover.CurrentX); testTransmitter.FinalRoverPosition .CurrentY.Should().Be(expectedFinalPositionOfRover.CurrentY); testTransmitter.FinalRoverPosition .CurrentHeading.Should().Be(expectedFinalPositionOfRover.CurrentHeading); }
public Task Transmit(CurrentRoverPosition currentRoverPosition) { FinalRoverPosition = currentRoverPosition; return(Task.CompletedTask); }