public void MovieTagsController_GetAll_ReturnAllMovieTags() { //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.GetAllAsync()).Returns(responseTask); //Act var result = movieTagsController.GetAll().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_GetAll_MovieTagServiceReturnsNull_ReturnEmptyList() { //Arrange IEnumerable <MovieTagsDomainModel> movieTags = null; Task <IEnumerable <MovieTagsDomainModel> > responseTask = Task.FromResult(movieTags); int expectedCount = 0; int expectedStatusCode = 200; MovieTagsController movieTagsController = new MovieTagsController(_mockMovieTagService.Object); _mockMovieTagService.Setup(x => x.GetAllAsync()).Returns(responseTask); //Act var result = movieTagsController.GetAll().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.AreEqual(expectedStatusCode, ((OkObjectResult)result).StatusCode); }