Exemplo n.º 1
0
        public void Can_OnGet()
        {
            var inputsModel = new InputsModel(new Query(new SchoolServiceMock()));

            inputsModel.OnGet();
            Assert.NotNull(inputsModel.Values);
        }
Exemplo n.º 2
0
        public ActionResult Inputs()
        {
            ModelState.AddModelError("", "Example error message for the form");
            var model = new InputsModel();

            return(View(model));
        }
Exemplo n.º 3
0
        private static void StartTheRobot()
        {
            var minCoordinate = Coordinate.CreateInstance(-100_000, -100_000);
            var maxCoordinate = Coordinate.CreateInstance(100_000, 100_000);

            var commandsCount    = PrintOutInput("Please enter the number of robot commands:");
            var startingPosition = PrintOutInput("Please enter the starting position coordinates {x y}:");
            var commands         = new List <string>();

            for (var i = 1; i <= int.Parse(commandsCount); i++)
            {
                var cmd = PrintOutInput($"Please enter the command number ({i}):");
                commands.Add(cmd);
            }

            var inputs = new InputsModel
            {
                StartingPosition = startingPosition,
                Commands         = commands
            };

            _robot = RobotFactory.CreateRobot(inputs, minCoordinate, maxCoordinate);

            _robot.StartCleaning();
        }
Exemplo n.º 4
0
        public static Instructions CreateInstructions(InputsModel inputsModel)
        {
            var coordinate = inputsModel.StartingPosition.Trim().Split(' ');

            int.TryParse(coordinate[0], out var x);
            int.TryParse(coordinate[1], out var y);
            var startingPosition = Coordinate.CreateInstance(x, y);

            var movements = new List <IMovement>();

            foreach (var command in inputsModel.Commands)
            {
                var cmd       = command.Trim().Split(' ');
                var direction = cmd[0].ToUpper() switch
                {
                    "E" => Direction.East,
                    "W" => Direction.West,
                    "N" => Direction.North,
                    "S" => Direction.South
                };

                int.TryParse(cmd[1], out var steps);
                movements.Add(new Movement(direction, steps));
            }

            return(new Instructions(startingPosition, movements));
        }
    }
Exemplo n.º 5
0
        public ActionResult Inputs(InputsModelPost postModel)
        {
            ModelState.AddModelError("", "Error displayed from form POST");
            var model = new InputsModel {
                PostModel = postModel
            };

            return(View(model));
        }
Exemplo n.º 6
0
        public void Can_RedirectTo_OutputsPage_OnPost()
        {
            var inputsModel = new InputsModel(new Query(new SchoolServiceMock()));

            inputsModel.OnGet();
            Assert.True(inputsModel.ModelState.IsValid);
            var response_on_submit = inputsModel.OnPost() as RedirectToPageResult;

            Assert.IsType <RedirectToPageResult>(response_on_submit);
            Assert.Equal("/Outputs", response_on_submit.PageName);
        }
Exemplo n.º 7
0
        public async Task <Result> Handle(ListInputQuery request, CancellationToken cancellationToken)
        {
            Result result;

            try
            {
                Expression <Func <Input, bool> > filter = null;
                int?skip = request.Skip.ToNullableInt();
                int?top  = request.Top.ToNullableInt();

                var inputDomains = await _inputReadRepository.ListAsync(filter, skip, top);

                var inputModels = _mapper.Map <IEnumerable <InputModel> >(inputDomains);
                var count       = inputModels.Count();
                var inputsModel = new InputsModel {
                    Value = inputModels, Count = count, NextLink = null
                };

                result = Result.Ok(inputsModel);
            }
            catch (FilterODataException)
            {
                result = Result.Fail(new System.Collections.Generic.List <Failure>()
                {
                    new HandlerFault()
                    {
                        Code    = HandlerFaultCode.InvalidQueryFilter.Name,
                        Message = HandlerFailures.InvalidQueryFilter,
                        Target  = "$filter"
                    }
                }
                                     );
            }
            catch
            {
                result = Result.Fail(CustomFailures.ListInputFailure);
            }
            return(result);
        }
Exemplo n.º 8
0
        public void Robot_StartCleaning_ShouldReportCleanedPositions()
        {
            // Arrange
            var commands = new List <string>()
            {
                "E 2", "N 1"
            };
            var inputs = new InputsModel
            {
                StartingPosition = "10 22",
                Commands         = commands
            };

            _robot = RobotFactory.CreateRobot(inputs, MinCoordinate, MaxCoordinate);

            // Act
            _robot.StartCleaning();
            // Assert
            var actual   = _robot.CleanedPositions;
            var expected = "Cleaned: 4";

            Assert.That(expected, Is.EqualTo(actual));
            Assert.That(actual, Does.EndWith("4"));
        }
Exemplo n.º 9
0
        public static IRobot CreateRobot(InputsModel inputsModel, Coordinate minCoordinate, Coordinate maxCoordinate)
        {
            var instructions = InstructionsFactory.CreateInstructions(inputsModel);

            return(CreateRobot(instructions, minCoordinate, maxCoordinate));
        }