Exemple #1
0
        public void Question_UpdateCorrect()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IQuestionRepository QRepo = new QuestionRepository(context);

            var question = new QuestionTO
            {
                Questioning  = "Am I a construction vehicule ?",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "Stan", LastName = "The Cat"
                }
            };

            var insertedQuestion = QRepo.Insert(question);

            QRepo.Save();

            insertedQuestion.Questioning = "Stupid Question";
            var result = QRepo.Update(insertedQuestion);

            QRepo.Save();

            Assert.AreEqual("Stupid Question", QRepo.Get(result.Id).Questioning);
        }
        public void Question_ArchiveSuccesfull()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IQuestionRepository QRepo = new QuestionRepository(context);

            var question = new QuestionTO
            {
                Questioning  = "Gif or Gif ?",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "William", LastName = "Shake"
                }
            };

            var added = QRepo.Insert(question);

            QRepo.Save();

            var result = QRepo.Archive(added);

            QRepo.Save();

            Assert.IsTrue(QRepo.Get(added.Id).IsArchived);
        }
        public void InsertQuestion_NullException()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IQuestionRepository QRepo = new QuestionRepository(context);

            Assert.ThrowsException <ArgumentNullException>(() => QRepo.Insert(null));
        }
Exemple #4
0
        public void Question_Get_NothingToGet()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IQuestionRepository QRepo = new QuestionRepository(context);

            Assert.ThrowsException <ArgumentException>(() => QRepo.Get(-15));
        }
        public void ArchiveAnswer_Correct()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IAnswerRepository   ARepo = new AnswerRepository(context);
            IQuestionRepository QRepo = new QuestionRepository(context);

            var question = new QuestionTO
            {
                Questioning  = "Not hungry",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "Don't wanna", LastName = "Eat"
                }
            };

            var addedQuestion = QRepo.Insert(question);

            QRepo.Save();

            var answer = new AnswerTO
            {
                Answering  = "must be the donuts",
                AnswerTime = DateTime.Now.AddHours(1),
                QuestionId = addedQuestion.Id,
                Savior     = new UserTO {
                    FirstName = "Any", LastName = "Officer"
                }
            };

            var addedAnswer = ARepo.Insert(answer);

            ARepo.Save();

            Assert.AreEqual(1, ARepo.GetAll().Count());

            var deletedAnswer = ARepo.Delete(addedAnswer);

            ARepo.Save();
            var all = ARepo.GetAll();

            Assert.AreEqual(0, all.Count());
            Assert.IsTrue(deletedAnswer);
            Assert.IsTrue(ARepo.Get(addedAnswer.Id).IsDeleted);
        }
        public void Question_GetAll()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IQuestionRepository QRepo = new QuestionRepository(context);

            var question1 = new QuestionTO
            {
                Questioning  = "Great Power Blah blah blah",
                CreationDate = DateTime.Now,
                State        = State.Resolved,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "Peter", LastName = "Pan"
                }
            };
            var question2 = new QuestionTO
            {
                Questioning  = "How to cure RDR2",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "Arthur", LastName = "Morgan"
                }
            };
            var question3 = new QuestionTO
            {
                Questioning  = "Why no tracking ?",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = true,
                LostSoul     = new UserTO {
                    FirstName = "Pro", LastName = "Stalker"
                }
            };

            QRepo.Insert(question1);
            QRepo.Insert(question2);
            QRepo.Insert(question3);
            QRepo.Save();

            var result = QRepo.GetAll();

            Assert.AreEqual(2, result.Count());
        }
        public void GetAnswer_CantAddWithoutAQuestion()
        {
            var options             = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context             = new QAndAContext(options);
            IAnswerRepository ARepo = new AnswerRepository(context);

            var answer = new AnswerTO
            {
                Answering  = "must be the donuts",
                AnswerTime = DateTime.Now.AddHours(1),
                Savior     = new UserTO {
                    FirstName = "Any", LastName = "Officer"
                }
            };

            Assert.ThrowsException <NullReferenceException>(() => ARepo.Insert(answer));
        }
Exemple #8
0
        public void UpdateAnswer_Correct()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IAnswerRepository   ARepo = new AnswerRepository(context);
            IQuestionRepository QRepo = new QuestionRepository(context);

            var question = new QuestionTO
            {
                Questioning  = "Maybe it's working",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "Call me", LastName = "Kevin"
                }
            };

            var addedQuestion = QRepo.Insert(question);

            QRepo.Save();

            var answer = new AnswerTO
            {
                Answering  = "No shit Sherlock",
                AnswerTime = DateTime.Now.AddHours(1),
                QuestionId = addedQuestion.Id,
                Savior     = new UserTO {
                    FirstName = "Dr", LastName = "Watson"
                }
            };

            var addedAnswer = ARepo.Insert(answer);

            ARepo.Save();

            addedAnswer.Answering = "Can't be right";
            var updatedAnswer = ARepo.Update(addedAnswer);

            ARepo.Save();

            Assert.AreEqual(1, ARepo.GetAll().Count());
            Assert.AreEqual(1, QRepo.Get(addedAnswer.QuestionId).Answers.Count());
            Assert.AreEqual("Can't be right", ARepo.Get(updatedAnswer.Id).Answering);
        }
        public void InsertAnswer_NonExistingQuestion()
        {
            var options             = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context             = new QAndAContext(options);
            IAnswerRepository ARepo = new AnswerRepository(context);

            var answer = new AnswerTO
            {
                Answering  = "No shit Sherlock",
                AnswerTime = DateTime.Now.AddHours(1),
                QuestionId = 20,
                Savior     = new UserTO {
                    FirstName = "Dr", LastName = "Watson"
                }
            };

            Assert.ThrowsException <NullReferenceException>(() => ARepo.Insert(answer));
        }
Exemple #10
0
        public void Question_UpdateWrongId()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IQuestionRepository QRepo = new QuestionRepository(context);

            var question = new QuestionTO
            {
                Id           = 90000000,
                Questioning  = "Am I a construction vehicule ?",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "Stan", LastName = "The Cat"
                }
            };

            Assert.ThrowsException <ArgumentNullException>(() => QRepo.Update(question));
        }
        public void InsertQuestion_CorrectFormat()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IQuestionRepository QRepo = new QuestionRepository(context);

            var question = new QuestionTO
            {
                Questioning  = "Maybe it's working",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "Call me", LastName = "Kevin"
                }
            };

            var result = QRepo.Insert(question);

            QRepo.Save();

            Assert.AreEqual("Maybe it's working", result.Questioning);
        }
        public void Question_ArchiveAlreadyArchived()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IQuestionRepository QRepo = new QuestionRepository(context);

            var question = new QuestionTO
            {
                Questioning  = "Crèpes sucré ou salé ?",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = true,
                LostSoul     = new UserTO {
                    FirstName = "Top", LastName = "Chef"
                }
            };

            var test = QRepo.Insert(question);

            QRepo.Save();

            Assert.ThrowsException <ArgumentException>(() => QRepo.Archive(test));
        }
Exemple #13
0
        public void Question_Get()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IQuestionRepository QRepo = new QuestionRepository(context);

            var question = new QuestionTO
            {
                Questioning  = "How can i make money with that ?",
                CreationDate = DateTime.Now,
                State        = State.Resolved,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "Captain", LastName = "Krabs"
                }
            };

            var added = QRepo.Insert(question);

            QRepo.Save();
            var result = QRepo.Get(added.Id);

            Assert.AreEqual("How can i make money with that ?", result.Questioning);
        }
Exemple #14
0
 public AnswerRepository(QAndAContext context)
 {
     this.context = context;
 }
Exemple #15
0
 public QuestionRepository(QAndAContext context)
 {
     this.context = context;
 }
Exemple #16
0
        public void GetAllAnswers_Correct()
        {
            var options = new DbContextOptionsBuilder <QAndAContext>().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context = new QAndAContext(options);
            IAnswerRepository   ARepo = new AnswerRepository(context);
            IQuestionRepository QRepo = new QuestionRepository(context);

            var question1 = new QuestionTO
            {
                Questioning  = "How can I stop being Rickrolled ?",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "Don't wanna", LastName = "Eat"
                }
            };
            var question2 = new QuestionTO
            {
                Questioning  = "Never Gonna what?",
                CreationDate = DateTime.Now,
                State        = State.Pending,
                IsArchived   = false,
                LostSoul     = new UserTO {
                    FirstName = "Rick", LastName = "Ashley"
                }
            };

            var addedQuestion1 = QRepo.Insert(question1);
            var addedQuestion2 = QRepo.Insert(question2);

            QRepo.Save();

            var answer1 = new AnswerTO
            {
                Answering  = "Maybe Someone Else know this",
                AnswerTime = DateTime.Now.AddHours(1),
                QuestionId = addedQuestion1.Id,
                Savior     = new UserTO {
                    FirstName = "Random", LastName = "Joe"
                }
            };
            var answer2 = new AnswerTO
            {
                Answering  = "Why should I know this ? ",
                AnswerTime = DateTime.Now.AddHours(1),
                QuestionId = addedQuestion1.Id,
                Savior     = new UserTO {
                    FirstName = "Someone", LastName = "Else"
                }
            };
            var answer3 = new AnswerTO
            {
                Answering  = "Give you up, Let you down",
                AnswerTime = DateTime.Now.AddHours(1),
                QuestionId = addedQuestion2.Id,
                Savior     = new UserTO {
                    FirstName = "A specific", LastName = "Asshole"
                }
            };

            var addedAnswer1 = ARepo.Insert(answer1);
            var addedAnswer2 = ARepo.Insert(answer2);
            var addedAnswer3 = ARepo.Insert(answer3);

            ARepo.Save();

            Assert.AreEqual(3, ARepo.GetAll().Count());
        }