public async Task ShouldProcessCommandsAndTransmitCurrentPosition()
        {
            var manouvreCommandParameter = RoverCommandParametersBuilder.WithOneSafeMoveCommand();

            var commandRetrieverStub = new Mock <IRetrieveRoverCommands>();

            commandRetrieverStub
            .Setup(x => x.GetAll())
            .ReturnsAsync(new[]
            {
                manouvreCommandParameter
            })
            .Verifiable();

            var transmitterStub = new Mock <ITransmitRoverPosition>();

            transmitterStub
            .Setup(x => x.Transmit(It.IsAny <CurrentRoverPosition>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            var useCase = new RoverOperationUsecase(
                commandRetrieverStub.Object,
                transmitterStub.Object);

            await useCase.StartRoverOperation();

            commandRetrieverStub.Verify(x => x.GetAll(), Times.Once);
            transmitterStub.Verify(x =>
                                   x.Transmit(It.IsAny <CurrentRoverPosition>()),
                                   Times.Once);
        }
        public async Task ShouldNotTransmitPositionIfThereAreNoManouvreCommandsToProcess()
        {
            var commandRetrieverStub = new Mock <IRetrieveRoverCommands>();

            commandRetrieverStub
            .Setup(x => x.GetAll())
            .ReturnsAsync(new[]
            {
                RoverCommandParametersBuilder.WithNoManouvreCommands()
            });

            var transmitterStub = new Mock <ITransmitRoverPosition>();

            transmitterStub
            .Setup(x => x.Transmit(It.IsAny <CurrentRoverPosition>()))
            .Returns(Task.CompletedTask)
            .Verifiable();

            var useCase = new RoverOperationUsecase(
                commandRetrieverStub.Object,
                transmitterStub.Object);

            await useCase.StartRoverOperation();

            transmitterStub.Verify(x => x.Transmit(It.IsAny <CurrentRoverPosition>()), Times.Never);
        }
        public async Task ShouldThrowIfThereAreNoCommandsToProcess()
        {
            var commandRetrieverStub = new Mock <IRetrieveRoverCommands>();

            commandRetrieverStub
            .Setup(x => x.GetAll())
            .ReturnsAsync(Array.Empty <RoverCommandParameters>());

            var useCase = new RoverOperationUsecase(
                commandRetrieverStub.Object,
                new Mock <ITransmitRoverPosition>().Object);

            await Assert.ThrowsAsync <ArgumentOutOfRangeException>(() => useCase.StartRoverOperation());
        }
        public async Task ShouldThrowIfCommandForcesRoverToMoveOffTerrain()
        {
            var commandRetrieverStub = new Mock <IRetrieveRoverCommands>();

            commandRetrieverStub
            .Setup(x => x.GetAll())
            .ReturnsAsync(new[]
            {
                RoverCommandParametersBuilder.WithUnsafeManouvreCommand()
            });

            var useCase = new RoverOperationUsecase(
                commandRetrieverStub.Object,
                new Mock <ITransmitRoverPosition>().Object);

            await Assert.ThrowsAsync <InvalidOperationException>(() => useCase.StartRoverOperation());
        }
Example #5
0
        public static void Main(string[] args)
        {
            try
            {
                var roverOpertionUsecase = new RoverOperationUsecase(
                    new CommandLineInputParser(args),
                    TransmitterToUse);

                roverOpertionUsecase.StartRoverOperation().Wait();
            }
            catch (AggregateException aggex)
            {
                Console.WriteLine(aggex.Flatten().InnerException.Message);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        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 async Task ShouldMoveRoverAndTransmitPosition()
        {
            var startingX       = 1;
            var startingY       = 1;
            var startingHeading = Direction.North;

            Mock <IRetrieveRoverCommands> commandRetrieverStub = CreateCommandRetrieverStubWith(
                startingX, startingY, startingHeading);

            var positionProvidedToTransmitter = default(CurrentRoverPosition);
            var transmitterStub = CreateRoverPositionTransmitterStubToInvoke(
                currentPosition => positionProvidedToTransmitter = currentPosition);

            var useCase = new RoverOperationUsecase(
                commandRetrieverStub.Object,
                transmitterStub.Object);

            await useCase.StartRoverOperation();

            positionProvidedToTransmitter.Should().NotBeNull();
            positionProvidedToTransmitter.CurrentY.Should().Be(startingY + 1);
            positionProvidedToTransmitter.CurrentX.Should().Be(startingX);
            positionProvidedToTransmitter.CurrentHeading.Should().Be(startingHeading);
        }