public bool Validate(Location location, IPlateu plateu)
        {
            var isXValid = location.X >= 0 && location.X <= plateu?.Size?.Width;
            var isYValid = location.Y >= 0 && location.Y <= plateu?.Size?.Height;

            return(isXValid && isYValid);
        }
 public CommandManager(IPlateu plateu, ICommandMapper commandMapper, ICommandInvoker commandInvoker, IOutputGenerator outputGenerator)
 {
     rovers               = new List <IRover>();
     this.plateu          = plateu;
     this.commandMapper   = commandMapper;
     this.commandInvoker  = commandInvoker;
     this.outputGenerator = outputGenerator;
     this.commandInvoker.SetPlateu(this.plateu);
     this.commandInvoker.SetRovers(rovers);
 }
Example #3
0
        public void WhenSetPlateuCommandExecutingPlateuShouldBeSet(Mock <ISetPlateuSizeCommand> command,
                                                                   IPlateu plateu, CommandInvoker sut)
        {
            command.Setup(p => p.CommandType).Returns(CommandType.SetPlateauSize);

            sut.SetPlateu(plateu);
            sut.SetCommands(new List <ICommand> {
                command.Object
            });
            sut.InvokeCommands();

            command.Verify(p => p.SetReceiver(plateu), Times.Once);
        }
Example #4
0
 public void Land(IPlateu plateu, Location location, Direction direction)
 {
     if (locationValidator.Validate(location, plateu))
     {
         this.Location  = location;
         this.Plateu    = plateu;
         this.Direction = direction;
         this.isLanded  = true;
     }
     else
     {
         throw new OutOfBoundaryLandingException();
     }
 }
Example #5
0
 public Rover(IPlateu plateu)
 {
     Plateu = plateu;
 }
Example #6
0
        public void WhenRoverTriesToMoveOutOfPlateuThrowsException(IList <Movement> movements,
                                                                   [Frozen] Mock <ILocationValidator> locationValidator, IPlateu plateu
                                                                   , Location validLocation, Direction direction, Rover sut)
        {
            locationValidator.Setup(x => x.Validate(It.IsAny <Location>(), It.IsAny <IPlateu>())).Returns(true);

            sut.Land(plateu, validLocation, direction);

            locationValidator.Setup(x => x.Validate(It.IsAny <Location>(), It.IsAny <IPlateu>())).Returns(false);

            Action actual = () => sut.Move(movements);

            actual.Should().Throw <OutOfBoundaryMovementException>();
        }
Example #7
0
        public void WhenRoverIsLandingItValidatesTheLocationIsValidOrNot(Location location, IPlateu plateu, Direction direction,
                                                                         [Frozen] Mock <ILocationValidator> validator, Rover sut)
        {
            validator.Setup(p => p.Validate(location, plateu)).Returns(true);//any value

            sut.Land(plateu, location, direction);

            validator.Verify(x => x.Validate(location, plateu), Times.Once());
        }
Example #8
0
        public void GivenValidLocationAndDirectionForLandingProportiesShouldBeSetCorrectly(int expectedX, int expectedY, Direction expectedDirection, IPlateu expectedPlateu,
                                                                                           [Frozen] Mock <ILocationValidator> locationValidator, Rover sut)
        {
            var expectedLocation = new Location(expectedX, expectedY);

            locationValidator.Setup(x => x.Validate(expectedLocation, expectedPlateu)).Returns(true);
            sut.Land(expectedPlateu, expectedLocation, expectedDirection);

            sut.Location.Should().BeEquivalentTo(expectedLocation);
            sut.Direction.Should().Be(expectedDirection);
            sut.Plateu.Should().BeEquivalentTo(expectedPlateu);
        }
Example #9
0
        public void WhenRoverLandsSuccesfullyIsLandedPropertyShouldBeTrue([Frozen] Mock <ILocationValidator> locationValidator
                                                                          , Location anyLocation, IPlateu anyPlateu, Direction anyDirection, Rover sut)
        {
            locationValidator.Setup(x => x.Validate(It.IsAny <Location>(), It.IsAny <IPlateu>())).Returns(true);
            sut.Land(anyPlateu, anyLocation, anyDirection);
            var actual = sut.IsLanded();

            actual.Should().BeTrue();
        }
Example #10
0
 public void SetReceivers(IRover rover, IPlateu plateu)
 {
     this.rover  = rover;
     this.plateu = plateu;
 }
 public void SetPlateu(IPlateu plateu)
 {
     this.plateu = plateu;
 }
 public void SetReceiver(IPlateu plateu)
 {
     this.plateu = plateu;
 }