public void ChangePosition_Should_Change_Position_When_Expected_Position() { //Arrange var plateauService = new Mock <IPlateauService>(); plateauService.Setup(foo => foo.GetCurrentPlateau()).Returns(new PlateauModel { Width = 5, Height = 5 }); var roverPositionModel = new RoverPositionModel { X = 2, Y = 4, Direction = Direction.East }; //Act var marsRoverService = new MarsRoverService(_loggerMock); marsRoverService.ChangePosition(roverPositionModel); var currentRoverPositionModel = marsRoverService.GetCurrentRover(); //Assert currentRoverPositionModel.X.Should().Be(roverPositionModel.X); currentRoverPositionModel.Y.Should().Be(roverPositionModel.Y); currentRoverPositionModel.Direction.Should().Be(roverPositionModel.Direction); }
public void CreateMarsRover_Should_Throw_InvalidPosition_When_Negative_Or_Extreme(int x, int y, Direction direction) { //Arrange var plateauService = new Mock <IPlateauService>(); plateauService.Setup(foo => foo.GetCurrentPlateau()).Returns(new PlateauModel { Width = 5, Height = 5 }); var roverPositionModel = new RoverPositionModel { X = x, Y = y, Direction = direction }; var marsRoverService = new MarsRoverService(_loggerMock); //Act void Action() { marsRoverService.CreateMarsRover(roverPositionModel, plateauService.Object); } //Assert Assert.Throws <ValidateMarsRoverPositionException>((Action)Action); }
public void MarsRoverService_ExecuteExplorationPlanWithMissingConstructorArgumentFinalStatusSerializer_ThrowsArgumentNullException() { string testInput = "5 5\n" + "1 2 N\n" + "LMLMLMLMM\n" + "3 3 E\n" + "MMRMMRMRRM\n"; IMarsRoverService marsRoverService = new MarsRoverService(_explorationPlanDeserializer, null); // the missing parameter is finalStatusSerializer ArgumentNullException argumentNullException = Assert.Throws <ArgumentNullException>(() => { string actualOutput = marsRoverService.ExecuteExplorationPlan(testInput); }); Assert.Equal("finalStatusSerializer", argumentNullException.ParamName); }
public void IncorrectDateParams(string date) { MarsRoverService svc = new MarsRoverService(); BaseService baseSvc = new BaseService(); Response response = new Response(); string parsedDate = baseSvc.parseDate(date); if (parsedDate != "01/01/0001") { response = svc.GetMarsRorverPhoto(parsedDate); } Assert.True(response.photos == null || response.photos.Count < 1); }
static void ProcessStart(Mission mission) { try { MarsRoverService service = new MarsRoverService(); service.MissionStart(mission); Console.WriteLine(" >>>> Process End <<<< "); Console.ReadLine(); } catch (Exception ex) { Console.WriteLine(ex.Message, Console.BackgroundColor = ConsoleColor.DarkRed); ProcessStart(mission); } }
public void MarsRoverService_ExecuteExplorationPlan_ValidExplorationPlanInput() { ExplorationPlan explorationPlan = new ExplorationPlan { Plateau = new Plateau { LowerLefttCoordinate = new Coordinate { X = 0, Y = 0 }, UpperRightCoordinate = new Coordinate { X = 5, Y = 5 } }, RoverNavigationPlanList = new List <NavigationPlan> { new NavigationPlan { InitialPosition = new Position { Coordinate = new Coordinate { X = 1, Y = 2 }, DirectionType = DirectionType.N }, InstructionTypeSequence = new List <InstructionType> { InstructionType.L, InstructionType.M, InstructionType.L, InstructionType.M, InstructionType.L, InstructionType.M, InstructionType.L, InstructionType.M, InstructionType.M, } }, new NavigationPlan { InitialPosition = new Position { Coordinate = new Coordinate { X = 3, Y = 3 }, DirectionType = DirectionType.E }, InstructionTypeSequence = new List <InstructionType> { InstructionType.M, InstructionType.M, InstructionType.R, InstructionType.M, InstructionType.M, InstructionType.R, InstructionType.M, InstructionType.R, InstructionType.R, InstructionType.M, } } } }; FinalStatus expectedFinalStatus = new FinalStatus { FinalRoverPositionList = new List <Position> { new Position { Coordinate = new Coordinate { X = 1, Y = 3 }, DirectionType = DirectionType.N }, new Position { Coordinate = new Coordinate { X = 5, Y = 1 }, DirectionType = DirectionType.E } } }; IMarsRoverService marsRoverService = new MarsRoverService(); FinalStatus actualFinalStatus = marsRoverService.ExecuteExplorationPlan(explorationPlan); Assert.Equal(expectedFinalStatus, actualFinalStatus); }
public void Initialize() { service = new MarsRoverService(); }
public void MarsRoverService_ValidDiscoveryPlanInput() { DiscoveryPlan discoveryPlan = new DiscoveryPlan { Plateau = new Plateau { LowerLefttCoordinate = new Coordinate { X = 0, Y = 0 }, UpperRightCoordinate = new Coordinate { X = 5, Y = 5 } }, NavigationPlanList = new List <NavigationPlan> { new NavigationPlan { InitialPosition = new Position { Coordinate = new Coordinate { X = 1, Y = 2 }, WayType = WayType.North }, RuleTypeList = new List <RuleType> { RuleType.Left, RuleType.Move, RuleType.Left, RuleType.Move, RuleType.Left, RuleType.Move, RuleType.Left, RuleType.Move, RuleType.Move, } }, new NavigationPlan { InitialPosition = new Position { Coordinate = new Coordinate { X = 3, Y = 3 }, WayType = WayType.East }, RuleTypeList = new List <RuleType> { RuleType.Move, RuleType.Move, RuleType.Right, RuleType.Move, RuleType.Move, RuleType.Right, RuleType.Move, RuleType.Right, RuleType.Right, RuleType.Move, } } } }; FinalStatus expectedFinalStatus = new FinalStatus { FinalRoverPositionList = new List <Position> { new Position { Coordinate = new Coordinate { X = 1, Y = 3 }, WayType = WayType.North }, new Position { Coordinate = new Coordinate { X = 5, Y = 1 }, WayType = WayType.East } } }; IMarsRoverService marsRoverService = new MarsRoverService(); FinalStatus actualFinalStatus = marsRoverService.ExecuteDiscoveryPlan(discoveryPlan); Assert.Equal(expectedFinalStatus, actualFinalStatus); }
public static List <RoverInfo> MissionStart(MarsRoverService service, Mission mission) { Console.BackgroundColor = ConsoleColor.Black; foreach (PropertyInfo propertyInfo in mission.GetType().GetProperties()) { switch (propertyInfo.Name) { case nameof(mission.Plateau): if (mission.Plateau.IsSuccess) { break; } Console.Write("Plateau Info :"); Plateau plateau = service.AddPlateu(Console.ReadLine()); mission.Plateau = plateau; break; case nameof(mission.RoverCount): if (mission.RoverCount.IsSuccess) { break; } Console.Write("Rover Count:"); RoverCount roverCount = service.AddRoverCount(Console.ReadLine()); mission.RoverCount = roverCount; var rovers = new List <Rover>(); for (int i = 0; i < roverCount.Count; i++) { rovers.Add(new Rover()); } mission.Rovers = rovers; break; case nameof(mission.Rovers): for (int i = 0; i < mission.RoverCount.Count; i++) { if (mission.Rovers[i].IsSuccess) { break; } Console.WriteLine($"{i} - Rover Setup "); RoverInfo roverInfo = service.SetupRoverInfo(Console.ReadLine()); RoverMove roverMove = service.SetupRoverMove(Console.ReadLine()); mission.Rovers[i] = service.AddRover(roverInfo, roverMove); } Console.WriteLine($" Rover Setup End "); break; default: break; } } var result = new List <RoverInfo>(); for (int i = 0; i < mission.RoverCount.Count; i++) { var rover = mission.Rovers[i]; var serviceResult = service.StartDiscovering(mission.Plateau, rover); result.Add(serviceResult); Console.WriteLine($"Info Mission > {i} - Rover : {serviceResult.X} {serviceResult.Y} {serviceResult.Direction}, IsSuccess:{serviceResult.IsSuccess} "); if (!serviceResult.IsSuccess) { Console.WriteLine($" \t Failed Detail: { serviceResult.ErrorMessage }"); } } ; return(result); }