Esempio n. 1
0
        public IActionResult Test(string course, string exercise, string seed, bool getSolution)
        {
            IExerciseContract contract = GetExercise(course, exercise);

            if (contract != null)
            {
                TestViewModel model = new TestViewModel()
                {
                    CourseName        = course,
                    ExerciseName      = contract.Name,
                    ExerciseFileName  = contract.FileName,
                    ExerciseViewModel = contract.GetViewModel(seed),
                    SolutionCells     = GetSolutionCell(contract)
                };
                if (getSolution)
                {
                    foreach (var item in GetSolutionCells(contract, seed))
                    {
                        int cell = model.SolutionCells.IndexOf(model.SolutionCells.Where(x => x.Row == item.Row && x.Column == item.Column).Single());
                        model.SolutionCells[cell] = item;
                    }
                }
                model.SolutionCells = model.SolutionCells.OrderBy(x => x.Column).ToList();
                model.SolutionCells = model.SolutionCells.OrderBy(x => x.Row).ToList();
                return(View(model));
            }
            return(View("Error"));
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        public IActionResult Test(TestViewModel model)
        {
            IExerciseContract contract = GetExercise(model.CourseName, model.ExerciseName);

            if (contract != null)
            {
                var solution = contract.GenerateSolution(model.Seed);
                model.SolutionCells     = ValidateSolution(solution, model.SolutionCells);
                model.ExerciseViewModel = contract.GetViewModel(model.Seed);
                return(View(model));
            }

            return(View("Error"));
        }