public async Task Get() { // arrange var model = new AnswerModel(); _repository.Setup(x => x.GetAsync(It.IsAny <int>())).Returns(Task.FromResult(model)); // act var result = await _controller.Get(1); // assert _repository.Verify(x => x.GetAsync(1), Times.Once); Assert.IsType <OkObjectResult>(result.Result); Assert.IsType <AnswerViewModel>((result.Result as OkObjectResult).Value); }
public async Task Get_WhenCorrectIdGiven_ShouldReturnJsonViewModel() { //Arrange var queryResult = _fixture.Create <GetAnswerQueryResult>(); _queryDispatcherMock.Setup(x => x.DispatchAsync <GetAnswerQuery, GetAnswerQueryResult>(It.IsAny <GetAnswerQuery>())) .Returns(Task.FromResult(queryResult)); //Act var result = await _controller.Get(queryResult.Answer.Id) as JsonResult; //Assert Assert.IsNotNull(result); Assert.AreEqual(result.GetValueFromJsonResult <string>("Text"), queryResult.Answer.Text); Assert.AreEqual(result.GetValueFromJsonResult <int>("Id"), queryResult.Answer.Id); }
public void Get_WhenCorrectIdGiven_ShouldReturnJsonViewModel() { var answerId = 1; var answer = new Answer { Id = answerId, Text = "Text1" }; _mockRepo.Setup(x => x.GetAnswer(answerId)).Returns(Task.FromResult(answer)); var result = _sut.Get(answerId).Result as JsonResult; Assert.IsNotNull(result); Assert.AreEqual(result.GetValueFromJsonResult <string>("Text"), answer.Text); Assert.AreEqual(result.GetValueFromJsonResult <int>("Id"), answer.Id); }
public async Task WhenGetAnswer_ThenGetSuccessful() { //?Given var answerList = new List <Answer>(); var expected = new List <AnswerModel>(); _mockManager.Setup(x => x.Get()) .ReturnsAsync(answerList) .Verifiable(); _mockMapper.Setup(x => x.Map <IEnumerable <AnswerModel> >(answerList)) .Returns(expected) .Verifiable(); //?When var actual = await _answerController.Get(); //?Then Assert.IsAssignableFrom <OkObjectResult>(actual.Result); Assert.Equal(((OkObjectResult)actual.Result).Value, expected); _mockManager.Verify(); _mockMapper.Verify(); }