Пример #1
0
        public void CreateAnswer_AddExistingAnswer_DoNotInsertTwiceInDb()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

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


            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 addedQuestion = questionRepository.Create(question);

            context.SaveChanges();
            var answer = new AnswerTO {
                Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion,
            };
            var result = answerRepository.Create(answer);

            context.SaveChanges();
            //ACT
            answerRepository.Create(result);
            context.SaveChanges();

            //ASSERT
            Assert.AreEqual(1, context.Answers.Count());
        }
Пример #2
0
        public void GetALlAnswers_Successful()
        {
            //ARRANGE
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

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

            //ACT
            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();
            var answer = new AnswerTO {
                Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion,
            };
            var answer2 = new AnswerTO {
                Message = "Oui c'est trop facile les tests avec InMemory", AuthorId = 3, AssociatedQuestion = addedQuestion,
            };
            var answer3 = new AnswerTO {
                Message = "Tu dois d'abord créer un projet web app avec .Net Core", AuthorId = 1, AssociatedQuestion = addedQuestion2,
            };
            var addedAnswer  = answerRepository.Create(answer);
            var addedAnswer2 = answerRepository.Create(answer2);
            var addedAnswer3 = answerRepository.Create(answer3);

            context.SaveChanges();
            //Archiving the question related to the answer 3
            addedQuestion2.IsResolved = true;
            questionRepository.Modify(addedQuestion2);
            context.SaveChanges();
            //ACT
            var test = answerRepository.GetAll();

            //ASSERT
            Assert.AreEqual(3, test.Count());
        }
Пример #3
0
        public void PostAnswer(int problemId, string value)
        {
            Answer answer = new Answer {
                answer = value, problem = problemId
            };
            AnswerRepository answerRepository = new AnswerRepository(Startup.connectionString);

            answerRepository.Create(answer);
        }
Пример #4
0
        public void CreateAnswer_AddNull_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IAnswerRepository answerRepository = new AnswerRepository(context);

            Assert.ThrowsException <ArgumentNullException>(() => answerRepository.Create(null));
        }
        public bool Create(AnswerDTO user)
        {
            try
            {
                bool b1 = ur.Create(Mapper.Map <AnswerEntity>(user));
                if (b1)
                {
                    qr.IncrementAnswers(user.QuestionId);
                }

                return(b1);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }
Пример #6
0
        public void ModifyAnswer_Successful()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

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

            //ACT
            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();
            var answer = new AnswerTO {
                Message = "En fait, c'est facile il faut toujorus faire des tests", AuthorId = 2, AssociatedQuestion = addedQuestion,
            };
            var result = answerRepository.Create(answer);

            context.SaveChanges();
            //ACT
            result.Message = "Message modifié";
            var test = answerRepository.Modify(result);

            context.SaveChanges();

            //ASSERT
            Assert.AreEqual("Message modifié", test.Message);
        }