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); }
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); }
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(); } }
public Rover(IPlateu plateu) { Plateu = plateu; }
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>(); }
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()); }
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); }
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(); }
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; }