Example #1
0
        public void DeleteQuestion_Successful()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(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 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.Delete(addedQuestion3);

            context.SaveChanges();

            //ASSERT
            Assert.AreEqual(2, context.Questions.Count());
        }
Example #2
0
        public void DeleteQuestion_CorrectQuestionSubmitted_ThrowArgumentException()
        {
            //ARRANGE
            var options    = new DbContextOptionsBuilder().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context    = new ApplicationContext(options);
            var repository = new QuestionRepository(context);
            var question   = new Question
            {
                Message   = "Test question",
                PostDate  = DateTime.Now,
                State     = QuestionState.Waiting,
                IsDeleted = false,
                Requester = new ApplicationUser {
                    Id = "aaaaabbbbbcccccdddd", Email = "*****@*****.**"
                }
            };
            var addedQuestion = repository.Insert(question);

            context.SaveChanges();
            //ACT
            var result = repository.Delete(addedQuestion);

            repository.Save();
            //ASSERT
            Assert.IsTrue(result);
        }
Example #3
0
        public void DeleteQuestion_QuestionWithBadIdSubmitted_ThrowArgumentException()
        {
            //ARRANGE
            var options    = new DbContextOptionsBuilder().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context    = new ApplicationContext(options);
            var repository = new QuestionRepository(context);

            //ACT
            //ASSERT
            Assert.ThrowsException <ArgumentException>(() => repository.Delete(new Question {
                Id = 0, Message = "Test question"
            }));
            Assert.ThrowsException <ArgumentException>(() => repository.Delete(new Question {
                Id = -1, Message = "Test question"
            }));
        }
        public int DeleteQuestion(int id)
        {
            SqlObject.CommandText = StoredProcedures.Questions.DeleteQuestion;
            SqlObject.Parameters  = new object[] { id };
            int result = _repository.Delete(id);

            return(result);
        }
        public void Delete_Question_Not_Found_Error()
        {
            BitcoinShowDBContext context = DbContextFactory.GetContext();

            QuestionRepository repository = new QuestionRepository(context);
            Exception          ex         = Assert.Throws <Exception>(() => repository.Delete(99999999));

            Assert.NotNull(ex);
            Assert.Equal("The current Question does not exist.", ex.Message);
        }
Example #6
0
        public JsonResult Delete(int id)
        {
            QuestionRepository.Delete(id);
            QuestionRepository.Save();

            return(new JsonResult()
            {
                Data = "OK", JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #7
0
        public void DeleteQuestion_ProvidingNull_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

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

            Assert.ThrowsException <KeyNotFoundException>(() => questionRepository.Delete(null));
        }
Example #8
0
        public void DeleteQuestion_NullQuestionSubmitted_ThrowArgumentNullException()
        {
            //ARRANGE
            var options    = new DbContextOptionsBuilder().UseInMemoryDatabase(MethodBase.GetCurrentMethod().Name).Options;
            var context    = new ApplicationContext(options);
            var repository = new QuestionRepository(context);

            //ACT
            //ASSERT
            Assert.ThrowsException <ArgumentNullException>(() => repository.Delete(null));
        }
Example #9
0
        public IActionResult Delete([FromBody] QuestionViewModel questionViewModel, long id)
        {
            var question = _questionRepository.GetById(id);

            if (question == null)
            {
                return(NotFound());
            }
            _questionRepository.Delete(question);
            return(Ok());
        }
Example #10
0
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            QuestionRepository qRep  = new QuestionRepository();
            string             strId = Request.QueryString["qId"];

            if (!string.IsNullOrEmpty(strId)) // existiert schon
            {
                qId = Convert.ToInt32(strId);
            }
            qRep.Delete(qId.Value);

            Response.Redirect("~/QuestionList.aspx");
        }
Example #11
0
        public void Delete(int questionId)
        {
            using (IUnitOfWork unitOfWork = context.CreateUnitOfWork())
            {
                Question question = questionRepo.GetById(questionId);

                if (!questionRepo.Delete(question))
                {
                    throw new FailedOperationException("Failed to delete Question.", question);
                }

                unitOfWork.SaveChanges();
            }
        }
Example #12
0
        public void TestDeleteQuestion()
        {
            QuestionRepository questionRepo = new QuestionRepository(DatabaseDummy.DatabaseDummyCreate("TestDeleteQuestion"));

            try
            {
                questionRepo.Delete(10);
                Assert.True(true);
            }
            catch
            {
                Assert.True(false);
            }
        }
        public async Task DeleteQuestionAsync_QuestionIsPreviouslySeeded_DeletesQuestion()
        {
            Question deleted;

            using (var uow = unitOfWorkProvider.Create())
            {
                repository.Delete(Initializer.JavaExperienceQuestion.Id);
                await uow.Commit();

                deleted = await repository.GetAsync(Initializer.JavaExperienceQuestion.Id);
            }

            Assert.Null(deleted);
        }
Example #14
0
        public void DeleteQuestion_ProvidingNonExistingQuestion_ThrowException()
        {
            var options = new DbContextOptionsBuilder <AskContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new AskContext(options);
            IQuestionRepository questionRepository = new QuestionRepository(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
            };

            Assert.ThrowsException <ArgumentException>(() => questionRepository.Delete(question));
        }
        public void Delete_Question_Success()
        {
            var question = new Question
            {
                Title = "Delete_Question_Success"
            };
            BitcoinShowDBContext context = DbContextFactory.GetContext();

            context.Questions.Add(question);
            context.SaveChanges();
            int questionId = question.Id;

            QuestionRepository repository = new QuestionRepository(context);

            repository.Delete(questionId);
            Assert.Null(context.Questions.Find(questionId));
        }
Example #16
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();
        }
Example #17
0
        public HttpResponseMessage DeleteQuestion(int id)
        {
            Question question = QuestionRepository.Get(t => t.QuestionId == id);

            if (question == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            QuestionRepository.Delete(question);

            try
            {
                unitOfWork.SaveChanges();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotFound, ex));
            }
            return(Request.CreateResponse(HttpStatusCode.OK, question));
        }
Example #18
0
 public bool Delete(int id)
 {
     QuestionRepository.Delete(id);
     return(true);
 }
 public void Delete(Question question) => questionRepo.Delete(question);
Example #20
0
        public bool Delete(QuestionDTO ID)
        {
            bool b1 = ur.Delete(Mapper.Map <QuestionEntity>(ID));

            return(b1);
        }