public async Task CreateQuestion(QuestionRequestModel question) { _questionRepoMock.Setup(u => u.CreateQuestionAsync(It.IsAny <QuestionRequestModel>(), It.IsAny <string>())) .Returns(() => Task.FromResult(questionResponse)); var response = await _questionManager.CreateQuestionAsync(question, "333"); _questionRepoMock.Verify(u => u.CreateQuestionAsync(It.IsAny <QuestionRequestModel>(), It.IsAny <string>()), Times.Once); Assert.NotNull(response.Id); }
public async Task Test_Create_Question() { var mockQuestion = new Question { Id = 1 }; var mockQuestionRepo = new Mock <IQuestionRepository>(); mockQuestionRepo.Setup(u => u.CreateQuestionAsync(It.IsAny <Question>())) .ReturnsAsync(mockQuestion); var questionManager = new QuestionManager(mockQuestionRepo.Object); var questionToTest = new QuestionDto(); var createdQuestion = await questionManager.CreateQuestionAsync(questionToTest); Assert.NotNull(createdQuestion); Assert.Equal(1, createdQuestion.Id); mockQuestionRepo.Verify(u => u.CreateQuestionAsync(It.IsAny <Question>()), Times.Once); }