Exemplo n.º 1
0
        public void DeleteQuizCorrect()
        {
            var quizDTO = new QuizDTO
            {
                Id   = 1,
                Naam = "Quiz 1"
            };

            var response = new Response <int> {
                DTO = 1
            };

            //Arrange
            quizService.Setup(x => x.Delete(1)).Returns(response);

            //Act
            var quizViewModel = new QuizViewModelResponse
            {
                Id   = 1,
                Naam = "Quiz 1"
            };

            var deleteQuiz = controller.Delete(quizViewModel.Id) as ObjectResult;

            //var entity = deleteQuiz.Value as QuizViewModelResponse;

            //Assert
            Assert.DoesNotThrow(() => controller.Delete(quizViewModel.Id));
        }
Exemplo n.º 2
0
        public void UpdateQuizCorrect()
        {
            var quizDTO = new QuizDTO
            {
                Id   = 1,
                Naam = "Quiz 1"
            };

            var response = new Response <QuizDTO> {
                DTO = quizDTO
            };

            //Arrange
            quizService.Setup(x => x.Update(It.IsAny <QuizDTO>())).Returns(response);

            //Act
            var quizViewModel = new QuizViewModelResponse
            {
                Id   = 1,
                Naam = "Quiz 1"
            };

            var updateQuiz = controller.Update(quizViewModel) as ObjectResult;
            var entity     = updateQuiz.Value as QuizViewModelResponse;

            //Assert
            Assert.DoesNotThrow(() => controller.Update(quizViewModel));
            Assert.That(entity.Id, Is.EqualTo(quizDTO.Id));
            Assert.That(entity.Naam, Is.EqualTo(quizDTO.Naam));
        }
Exemplo n.º 3
0
 public static QuizDTO MapQuizViewModelToQuizDTO(QuizViewModelResponse quizmodel)
 {
     if (quizmodel == null)
     {
         throw new NullReferenceException("quiz model is null");
     }
     return(new QuizDTO
     {
         Id = quizmodel.Id,
         Naam = quizmodel.Naam,
         EmailCreator = quizmodel.EmailCreator,
     });
 }
Exemplo n.º 4
0
        public IActionResult Update(QuizViewModelResponse quizViewModel)
        {
            try
            {
                var quizDTO = QuizViewModelMapper.MapQuizViewModelToQuizDTO(quizViewModel);
                var quiz    = _service.Update(quizDTO);
                if (quiz == null)
                {
                    return(BadRequest("Error updating quiz"));
                }

                if (quiz.DidError)
                {
                    return(BadRequest(quiz.Errors));
                }

                var quizReturn = QuizViewModelMapper.MapQuizDTOToQuizViewModel(quiz.DTO);
                return(Created("/api/quiz/GetById/" + quizReturn.Id, quizReturn));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }