Exemple #1
0
        public async Task ValidateQuestionAsync_CategoryChangedForRandomQuestionChoice_Throws()
        {
            var database = GetDatabase().Build();

            var question = database.Context
                           .Questions
                           .Include(q => q.QuestionCategory.Classroom)
                           .Single(q => q.Name == "Choice1");

            var newCategoryId = database.Context
                                .QuestionCategories
                                .Single(qc => qc.Name == "Category1")
                                .Id;

            database.Reload();

            question.QuestionCategoryId = newCategoryId;
            question.QuestionCategory   = null;

            var modelErrors = new MockErrorCollection();
            var validator   = new QuestionValidator(database.Context);

            await Assert.ThrowsAsync <InvalidOperationException>
            (
                async() => await validator.ValidateQuestionAsync
                (
                    question,
                    modelErrors,
                    "Class1"
                )
            );
        }
        public static bool IsValidQuestions(List <QuestionInfo> questions)
        {
            if (questions == null || questions.Count == 0)
            {
                if (minQuestionsCount == 0)
                {
                    return(true);
                }

                Error = "Отсутствуют вопросы.";
                return(false);
            }

            if (questions.Count > maxQuestionsCount)
            {
                Error = "Слишком много вопросов.";
                return(false);
            }

            if (questions.Count < minQuestionsCount)
            {
                Error = "Слишком мало вопросов.";
                return(false);
            }

            if (questions.Any(q => !QuestionValidator.IsValid(q)))
            {
                Error = "Присутствуют невалидные вопросы.";
                return(false);
            }

            Error = string.Empty;
            return(true);
        }
Exemple #3
0
        public async Task ValidateQuestionAsync_NewValidQuestion_ReturnsTrueNoErrors()
        {
            var database = GetDatabase().Build();

            var question = new MultipleChoiceQuestion()
            {
                Name = "NewQuestion",
                QuestionCategoryId = database.Context
                                     .QuestionCategories
                                     .Single(qc => qc.Name == "Category1")
                                     .Id
            };

            database.Reload();

            var modelErrors = new MockErrorCollection();
            var validator   = new QuestionValidator(database.Context);

            var result = await validator.ValidateQuestionAsync
                         (
                question,
                modelErrors,
                "Class1"
                         );

            Assert.True(result);
            Assert.False(modelErrors.HasErrors);
        }
Exemple #4
0
        public async Task ValidateQuestionAsync_ModifiedValidQuestion_ReturnsTrueNoErrors()
        {
            var database = GetDatabase().Build();

            var question = database.Context
                           .Questions
                           .Include(q => q.QuestionCategory.Classroom)
                           .Single(q => q.Name == "Question1");

            database.Reload();

            question.Name = "ModifiedQuestion";

            var modelErrors = new MockErrorCollection();
            var validator   = new QuestionValidator(database.Context);

            var result = await validator.ValidateQuestionAsync
                         (
                question,
                modelErrors,
                "Class1"
                         );

            Assert.True(result);
            Assert.False(modelErrors.HasErrors);
        }
Exemple #5
0
        private void ButtonSave_Click(object sender, RoutedEventArgs e)
        {
            if (!CheckText())
            {
                return;
            }

            QuestionInfo question = Question;

            if (!QuestionValidator.IsValid(question))
            {
                CtrlError.ShowError(QuestionValidator.Error);
                return;
            }

            if (questionId != null)
            {
                manager.TestEditControl.EditQuestion(Question);
            }
            else
            {
                manager.TestEditControl.AddQuestion(Question);
            }

            manager.TestEditControl.Back();
        }
Exemple #6
0
        bool CheckText()
        {
            if (!QuestionValidator.IsValidText(CtrlText.Text))
            {
                CtrlErrorText.ShowError(QuestionValidator.Error);
                return(false);
            }

            CtrlErrorText.ClearError();
            return(true);
        }
Exemple #7
0
 public Question EditQuestionVotes(string command, int questionId)
 {
     try
     {
         var question = _context.Questions.SingleOrDefault(ques => ques.Id == questionId);
         question = QuestionValidator.ValidateCommand(question, command);
         _context.Questions.Update(question);
         _context.SaveChanges();
         return(question);
     }
     catch (Exception)
     {
         throw;
     }
 }
 private GrpcQuestionValidator GetGrpcQuestionValidator(QuestionValidator questionValidator)
 {
     if (questionValidator == null)
     {
         return(null);
     }
     return(new GrpcQuestionValidator()
     {
         Max = questionValidator.Max,
         Min = questionValidator.Min,
         MaxLength = questionValidator.MaxLength,
         MinLength = questionValidator.MinLength,
         Required = questionValidator.Required
     });
 }
        public Question Insert(Question question)
        {
            var validator = new QuestionValidator();
            var results   = validator.Validate(question);

            if (results.IsValid)
            {
                repository.Insert(question);

                UoW.Commit();
                return(question);
            }
            else
            {
                var errors = results.Errors.Select(e => e.ErrorMessage).ToList();
                throw new BusinessException(errors);
            }
        }
 public QuestionValidationTest()
 {
     _questionValidator = new QuestionValidator();
 }
Exemple #11
0
 public CourseTestsController(ICourseTestService courseTestService, ITestSubmissionService testSubmissionService)
 {
     this.courseTestService     = courseTestService;
     this.testSubmissionService = testSubmissionService;
     questionValidator          = new QuestionValidator();
 }
Exemple #12
0
        private void Validation(QuestionDto dto)
        {
            var validator = new QuestionValidator();

            validator.ValidateAndThrow(dto);
        }
Exemple #13
0
        public override ValidationResult IsValid()
        {
            var validator = new QuestionValidator();

            return(validator.Validate(this));
        }
 public void TestCleanup()
 {
     _repositoryMock = null;
     _validator      = null;
 }
 public void TestInitialize()
 {
     _repositoryMock = new Mock <IRepository>();
     _validator      = new QuestionValidator();
 }
Exemple #16
0
 public QuestionValidatorTests()
 {
     questionValidator = new QuestionValidator();
 }