public void MovieTagsController_GetByTagIdAsync_ReturnMovieTagsByMovieId() { //Arrange List <MovieTagsDomainModel> movieTagsList = new List <MovieTagsDomainModel>(); movieTagsList.Add(_movieTagDomainModel); IEnumerable <MovieTagsDomainModel> movieTags = movieTagsList; Task <IEnumerable <MovieTagsDomainModel> > responseTask = Task.FromResult(movieTags); int expectedCount = 1; int expectedStatusCode = 200; MovieTagsController movieTagsController = new MovieTagsController(_mockMovieTagService.Object); _mockMovieTagService.Setup(x => x.GetByTagId(It.IsAny <int>())).Returns(responseTask); //Act var result = movieTagsController.GetByTagIdAsync(_movieTagDomainModel.TagId).ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultList = ((OkObjectResult)result).Value; var movieTagDomainModelResultList = (List <MovieTagsDomainModel>)resultList; //Assert Assert.IsNotNull(resultList); Assert.AreEqual(movieTagDomainModelResultList.Count, expectedCount); Assert.IsInstanceOfType(movieTagDomainModelResultList[0], typeof(MovieTagsDomainModel)); Assert.AreEqual(movieTagDomainModelResultList[0].MovieId, _movieTagDomainModel.MovieId); Assert.AreEqual(movieTagDomainModelResultList[0].TagId, _movieTagDomainModel.TagId); Assert.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }
public void MovieTagsController_GetByTagIdAsync_ServiceReturnsNull_Returns404() { //Arrange IEnumerable <MovieTagsDomainModel> movieTags = null; Task <IEnumerable <MovieTagsDomainModel> > responseTask = Task.FromResult(movieTags); int expectedStatusCode = 404; string expectedMessage = Messages.MOVIETAG_DOES_NOT_EXIST; MovieTagsController movieTagsController = new MovieTagsController(_mockMovieTagService.Object); _mockMovieTagService.Setup(x => x.GetByTagId(It.IsAny <int>())).Returns(responseTask); //Act var result = movieTagsController.GetByTagIdAsync(_movieTagDomainModel.TagId).ConfigureAwait(false).GetAwaiter().GetResult().Result; var resultMessage = (NotFoundObjectResult)result; //Assert Assert.IsNotNull(resultMessage); Assert.AreEqual(resultMessage.Value.ToString(), expectedMessage); Assert.AreEqual(expectedStatusCode, resultMessage.StatusCode); }