public int DeleteAnswer(int id)
        {
            SqlObject.CommandText = StoredProcedures.Answers.DeleteAnswer;
            SqlObject.Parameters  = new object[] { id };
            int result = _repository.Delete(id);

            return(result);
        }
        public bool Delete(AnswerDTO ID)
        {
            bool b1 = ur.Delete(Mapper.Map <AnswerEntity>(ID));

            if (b1)
            {
                qr.DecrementAnswers(ID.QuestionId);
            }
            return(b1);
        }
Esempio n. 3
0
        public void DeleteAnswer_ProvidingNull_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 <KeyNotFoundException>(() => answerRepository.Delete(null));
        }
Esempio n. 4
0
        public void DeleteAnswer_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 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();

            //ACT
            var test = answerRepository.Delete(addedAnswer3);

            context.SaveChanges();

            //ASSERT
            Assert.AreEqual(2, context.Answers.Count());
        }
Esempio n. 5
0
        public void DeleteAnswer()
        {
            if (SelectedAnswer != null)
            {
                Answer answer = SelectedAnswer.ToPoco();

                AnswerRepository.Delete(answer.AnswerID);

                SelectedQuestion.Answers.Remove(answer);
                Answers.Remove(SelectedAnswer);
                AnswerRepository.Save();
                RaisePropertyChanged("Answers");
            }
        }
Esempio n. 6
0
        public void Delete(int answerId)
        {
            using (IUnitOfWork unitOfWork = context.CreateUnitOfWork())
            {
                Answer answer = answerRepo.GetById(answerId);

                if (!answerRepo.Delete(answer))
                {
                    throw new FailedOperationException("Failed to delete Answer.", answer);
                }

                unitOfWork.SaveChanges();
            }
        }
        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);
        }
Esempio n. 8
0
        public void DeleteQuestion()
        {
            //CAST QUESTIONVIEWMODEL TO QUESTION
            Question question = SelectedQuestion.ToPoco();

            //DELETE QUESTION ANSWERS
            var answers = question.Answers;

            foreach (var a in answers)
            {
                AnswerRepository.Delete(a.AnswerID);
            }

            //REMOVE QUESTION
            QuestionRepository.Delete(question.QuestionID);
            QuestionRepository.Save();

            Questions.Remove(SelectedQuestion);
            ResetData();
        }
        public void testDelete()
        {
            // Arrange
            repo.Add(entity);
            repo.SaveChanges();
            int count = repo.All().Count();

            Guid id = repo.GetByHomeworkIdAndStudentId(hwId, studentId).Id;

            // Act
            repo.Delete(entity);
            repo.SaveChanges();
            // Assert

            Assert.True(repo.GetById(id).IsDeleted == true);
            Assert.True(repo.All().Count() == count - 1);
            Assert.True(repo.GetById(id).IsDeleted);

            this.repo.HardDelete(entity);
            this.repo.SaveChanges();

            //TODO add all remaining methods
        }
Esempio n. 10
0
        public void DeleteAnswer_ProvidingNonExistingAnswer_ThrowException()
        {
            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 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,
            };

            Assert.ThrowsException <ArgumentException>(() => answerRepository.Delete(answer));
        }
Esempio n. 11
0
 public bool Delete(int id)
 {
     AnswerRepository.Delete(id);
     return(true);
 }