public void GetQuestionById_Successful()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);
            //ARRANGE
            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test!", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };
            var question2 = new QuestionTO {
                IsResolved = false, Message = "Comment créer un projet MVC 6?", Title = "MVC6", Date = date, AuthorId = 2
            };
            var question3 = new QuestionTO {
                IsResolved = false, Message = "Comment faire boucle foreach?", Title = "foreach", Date = date, AuthorId = 2
            };
            var addedQuestion  = questionRepository.Create(question);
            var addedQuestion2 = questionRepository.Create(question2);
            var addedQuestion3 = questionRepository.Create(question3);

            context.SaveChanges();

            //ACT
            var test = questionRepository.GetById(2);

            //ASSERT
            Assert.AreEqual("Comment créer un projet MVC 6?", test.Message);
        }
        ///<summary>
        ///Desativa questionário
        /// </summary>
        public void Desactivateing(int id)
        {
            QuestionRepository repository = new QuestionRepository();
            QuestionEntity     entity     = repository.GetById(id);

            entity.status = false;
            repository.update(entity);
        }
        public Question Add(Question question)
        {
            using (IUnitOfWork unitOfWork = context.CreateUnitOfWork())
            {
                if (questionRepo.Find(x => x.QuestionSort == question.QuestionSort &&
                                      x.PeriodId == question.PeriodId).Any())
                {
                    throw new ArgumentException("Question in this sort position already exists.", nameof(question.QuestionSort));
                }

                int newQuestionId = questionRepo.Insert(question);
                if (newQuestionId <= 0)
                {
                    throw new FailedOperationException("Failed to insert Question.", question);
                }

                unitOfWork.SaveChanges();
                return(questionRepo.GetById(newQuestionId));
            }
        }
Exemple #4
0
        public void GetQuestionById_InvalidArgument(int questionId)
        {
            // Arrange
            SOVAContext        databaseContext    = new SOVAContext(_connectionString);
            QuestionRepository questionRepository = new QuestionRepository(databaseContext);

            // Act
            Question question = questionRepository.GetById(questionId);

            // Assert
            Assert.Null(question);
        }
        public void GetQuestionById_ProvidingNonExistingId_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);

            //ASSERT
            Assert.ThrowsException <ArgumentNullException>(() => questionRepository.GetById(14));
        }
Exemple #6
0
        public IActionResult Edit([FromBody] QuestionViewModel questionViewModel, long id)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            else if (_questionRepository.GetById(id) == null)
            {
                return(NotFound());
            }
            var question = new QuestionModel
            {
                Id             = questionViewModel.Id,
                Question       = questionViewModel.Question,
                Answer         = questionViewModel.Answer,
                Correct_answer = questionViewModel.Correct_answer,
                Level          = questionViewModel.Level
            };

            _questionRepository.Edit(question);
            return(Ok());
        }
Exemple #7
0
        public void GetQuestionById_ValidArgument()
        {
            // Arrange
            SOVAContext        databaseContext    = new SOVAContext(_connectionString);
            QuestionRepository questionRepository = new QuestionRepository(databaseContext);

            int questionId = 19;

            // Act
            Question question = questionRepository.GetById(questionId);

            // Assert
            Assert.Equal(questionId, question.SubmissionId);
        }
Exemple #8
0
        public void GetQuestionById_IncludesSubmission()
        {
            // Arrange
            SOVAContext        databaseContext    = new SOVAContext(_connectionString);
            QuestionRepository questionRepository = new QuestionRepository(databaseContext);

            int submissionId = 19;

            // Act
            Question question = questionRepository.GetById(submissionId);

            // Assert
            Assert.NotNull(question.Submission);
            Assert.NotNull(question.Submission.SoMember);
            Assert.NotNull(question.Submission.CreationDate);
        }
Exemple #9
0
        public string GetQuestion(int id)
        {
            QuestionRepository repository = new QuestionRepository();
            QuestionEntity     question   = repository.GetById(id);

            string json;

            json = JsonConvert.SerializeObject(
                question,
                Formatting.Indented,
                new JsonSerializerSettings {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            });

            return(json);
        }
Exemple #10
0
        public void GetQuestionById_ProvidingNoId_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(context);
            //ARRANGE
            DateTime date     = DateTime.Now;
            var      question = new QuestionTO {
                IsResolved = false, Message = "Je n'arrive pas à faire un test", Title = "Problème avec Tests", Date = date, AuthorId = 1
            };

            //ASSERT
            Assert.ThrowsException <ArgumentException>(() => questionRepository.GetById(question.Id));
        }
        public void AdddNewQuestionThenRetrieveItIsNotNull()
        {
            var options = new DbContextOptionsBuilder <EvaluationContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using (var memoryContext = new EvaluationContext(options))
            {
                // Arrange
                IFormRepository                formRepository                = new FormRepository(memoryContext);
                IQuestionRepository            questionRepository            = new QuestionRepository(memoryContext);
                IQuestionPropositionRepository questionPropositionRepository = new QuestionPropositionRepository(memoryContext);

                #region Form

                var Form1 = new FormTO
                {
                    Name = new MultiLanguageString
                           (
                        "Daily evaluation form",
                        "Formulaire d'évaluation journalier",
                        "Dagelijks evaluatieformulier"
                           ),
                };
                var formAdded1 = formRepository.Add(Form1);
                memoryContext.SaveChanges();

                #endregion

                #region Questions

                var Question1 = new QuestionTO
                {
                    FormId   = formAdded1.Id,
                    Position = 1,
                    Libelle  = new MultiLanguageString
                               (
                        "What is your general impression after this first day of training ?",
                        "Quelle est votre impression générale après cette première journée de formation ?",
                        "Wat is je algemene indruk na deze eerste dag van training ?"
                               ),
                    Type = QuestionType.SingleChoice,
                };

                var Question2 = new QuestionTO
                {
                    FormId   = formAdded1.Id,
                    Position = 2,
                    Libelle  = new MultiLanguageString
                               (
                        "Is the pace right for you ?",
                        "Est-ce que le rythme vous convient ?",
                        "Is het tempo geschikt voor u ?"
                               ),
                    Type = QuestionType.SingleChoice,
                };

                var Question3 = new QuestionTO
                {
                    FormId   = formAdded1.Id,
                    Position = 3,
                    Libelle  = new MultiLanguageString
                               (
                        "Do you have questions related to the subject studied today ?",
                        "Avez-vous des questions relatives à la matière étudiée aujourd’hui ?",
                        "Heb je vragen over het onderwerp dat vandaag is bestudeerd ?"
                               ),
                    Type = QuestionType.Open
                };

                var Question4 = new QuestionTO
                {
                    FormId   = formAdded1.Id,
                    Position = 4,
                    Libelle  = new MultiLanguageString
                               (
                        "Do you have specific questions / particular topics that you would like deepen during this training ?",
                        "Avez-vous des questions spécifiques/sujets particuliers que vous aimeriez approfondir durant cette formation ?",
                        "Heeft u specifieke vragen / specifieke onderwerpen die u graag zou willen verdiepen tijdens deze training ?"
                               ),
                    Type = QuestionType.Open
                };

                var Question5 = new QuestionTO
                {
                    FormId   = formAdded1.Id,
                    Position = 5,
                    Libelle  = new MultiLanguageString
                               (
                        "What objectives do you pursue by following this training ?",
                        "Quels objectifs poursuivez-vous en suivant cette formation ?",
                        "Welke doelstellingen streeft u na door deze training te volgen?"
                               ),
                    Type = QuestionType.Open
                };

                var questionAdded1 = questionRepository.Add(Question1);
                var questionAdded2 = questionRepository.Add(Question2);
                var questionAdded3 = questionRepository.Add(Question3);
                var questionAdded4 = questionRepository.Add(Question4);
                var questionAdded5 = questionRepository.Add(Question5);
                memoryContext.SaveChanges();

                #endregion

                #region QuestionProposition
                var QuestionProposition1 = new QuestionPropositionTO
                {
                    QuestionId = questionAdded1.Id,
                    Libelle    = new MultiLanguageString("good", "bonne", "goed"),
                    Position   = 1
                };

                var QuestionProposition2 = new QuestionPropositionTO
                {
                    QuestionId = questionAdded1.Id,
                    Libelle    = new MultiLanguageString("medium", "moyenne", "gemiddelde"),
                    Position   = 2
                };

                var QuestionProposition3 = new QuestionPropositionTO
                {
                    QuestionId = questionAdded1.Id,
                    Libelle    = new MultiLanguageString("bad", "mauvaise", "slecht"),
                    Position   = 3
                };

                var QuestionProposition4 = new QuestionPropositionTO
                {
                    QuestionId = questionAdded2.Id,
                    Libelle    = new MultiLanguageString("yes", "oui", "ja"),
                    Position   = 1
                };

                var QuestionProposition5 = new QuestionPropositionTO
                {
                    QuestionId = questionAdded2.Id,
                    Libelle    = new MultiLanguageString("too fast", "trop rapide", "te snel"),
                    Position   = 2
                };

                var QuestionProposition6 = new QuestionPropositionTO
                {
                    QuestionId = questionAdded2.Id,
                    Libelle    = new MultiLanguageString("too slow", "trop lent", "te langzaam"),
                    Position   = 3
                };

                var questionPropositionAdded1 = questionPropositionRepository.Add(QuestionProposition1);
                var questionPropositionAdded2 = questionPropositionRepository.Add(QuestionProposition2);
                var questionPropositionAdded3 = questionPropositionRepository.Add(QuestionProposition3);
                var questionPropositionAdded4 = questionPropositionRepository.Add(QuestionProposition4);
                var questionPropositionAdded5 = questionPropositionRepository.Add(QuestionProposition5);
                var questionPropositionAdded6 = questionPropositionRepository.Add(QuestionProposition6);
                memoryContext.SaveChanges();
                #endregion

                // Act
                var result1 = questionRepository.GetById(questionAdded1.Id);
                var result2 = questionRepository.GetById(questionAdded2.Id);
                var result3 = questionRepository.GetById(questionAdded3.Id);

                // Assert
                Assert.IsNotNull(result1);
                Assert.IsNotNull(result2);
                Assert.IsNotNull(result3);

                Assert.AreEqual("Quelle est votre impression générale après cette première journée de formation ?", result1.Libelle.French);
                Assert.AreEqual(2, result2.Position);
                Assert.AreEqual(QuestionType.Open, result3.Type);
            }
        }
        ///<summary>
        ///Atualiza questionário
        /// </summary>
        public QuestionEntity GetById(int id)
        {
            QuestionRepository repository = new QuestionRepository();

            return(repository.GetById(id));
        }