public void AddQuizCorrect() { var quizDTO = new QuizDTO { Id = 1, Naam = "Quiz 1" }; var response = new Response <QuizDTO> { DTO = quizDTO }; //Arrange quizService.Setup(x => x.AddQuiz(It.IsAny <QuizDTO>())).Returns(response); //Act var quizViewModel = new QuizViewModelRequest { Naam = "Quiz 1" }; var addQuiz = controller.Create(quizViewModel) as ObjectResult; var entity = addQuiz.Value as QuizViewModelResponse; //Assert Assert.DoesNotThrow(() => controller.Create(quizViewModel)); Assert.That(entity.Id, Is.EqualTo(quizDTO.Id)); Assert.That(entity.Naam, Is.EqualTo(quizDTO.Naam)); }
public static QuizDTO MapQuizViewModelRequestToQuizDTO(QuizViewModelRequest quizmodel) { if (quizmodel == null) { throw new NullReferenceException("quiz model is null"); } return(new QuizDTO { //Id = quizmodel.Id, Naam = quizmodel.Naam, EmailCreator = quizmodel.EmailCreator, FreeQuiz = quizmodel.FreeQuiz, EntryFee = quizmodel.EntryFee }); }
public IActionResult Create(QuizViewModelRequest quizViewModel) { try { var createDTO = QuizViewModelMapper.MapQuizViewModelRequestToQuizDTO(quizViewModel); var response = _service.AddQuiz(createDTO); if (response.DidError) { return(BadRequest(response.Errors)); } var createdQuiz = QuizViewModelMapper.MapQuizDTOToQuizViewModel(response.DTO); return(Created("/api/quiz/GetById/" + createdQuiz.Id, createdQuiz)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }