Exemplo n.º 1
0
        public static ValidationResult ValidateExercise(IExerciseContract exercise, string testSeed = "*****@*****.**")
        {
            if (string.IsNullOrEmpty(exercise.Name))
            {
                return(ValidationResult.MISSING_EXERCISE_NAME);
            }
            if (string.IsNullOrEmpty(exercise.FileName))
            {
                return(ValidationResult.MISSING_EXERCISE_FILE_NAME);
            }

            //Validate ViewModel
            try
            {
                var viewModel = exercise.GetViewModel(testSeed);
            }
            catch (Exception)
            {
                return(ValidationResult.VIEW_MODEL_ERROR);
            }

            //Input Definition
            Dictionary <Cell, InputDefinition> inputDefinitions;

            try
            {
                inputDefinitions = exercise.GetInputDefiniton();
                if (inputDefinitions.Count < 1)
                {
                    return(ValidationResult.NO_INPUT_DEFINITION_FOUND);
                }
            }
            catch (Exception)
            {
                return(ValidationResult.INPUT_DEFINITION_ERROR);
            }

            //Solution
            try
            {
                var solution = exercise.GenerateSolution(testSeed);
                foreach (var item in solution)
                {
                    if (!inputDefinitions.ContainsKey(item.Key))
                    {
                        return(ValidationResult.INPUT_MISSING_FOR_SOLUTION);
                    }
                }
            }
            catch (Exception)
            {
                return(ValidationResult.SOLUTION_ERROR);
            }


            return(ValidationResult.VALID);
        }
Exemplo n.º 2
0
        private List <SolutionCell> GetSolutionCell(IExerciseContract contract)
        {
            List <SolutionCell> solutions = new List <SolutionCell>();

            foreach (var item in contract.GetInputDefiniton())
            {
                solutions.Add(new SolutionCell()
                {
                    Row       = item.Key.Row,
                    Column    = item.Key.Column,
                    InputType = item.Value.InputType,
                    Label     = item.Value.Label
                });
            }

            return(solutions);
        }
Exemplo n.º 3
0
        private List <SolutionCell> GetSolutionCells(IExerciseContract contract, string seed)
        {
            List <SolutionCell> solutions = new List <SolutionCell>();
            var definitions = contract.GetInputDefiniton();

            foreach (var item in contract.GenerateSolution(seed))
            {
                solutions.Add(new SolutionCell()
                {
                    Row       = item.Key.Row,
                    Column    = item.Key.Column,
                    Input     = item.Value.GetExpected(),
                    InputType = definitions[item.Key].InputType,
                    Label     = definitions[item.Key].Label,
                    State     = InputStatus.Correct
                });
            }

            return(solutions);
        }