Beispiel #1
0
        public async Task Test_MovieController_GetById_Should_Be_Ok()
        {
            var fakeMovie = new Movie();

            int fakeId = 1;

            movieServiceMock.Setup(m => m.GetById(fakeId)).Returns(Task.FromResult(fakeMovie));

            var apiResult = await movieController.GetById(fakeId);

            apiResult.Should().BeOfType <OkObjectResult>().Which.Value.Should().Be(fakeMovie);

            movieServiceMock.Verify(m => m.GetById(fakeId), Times.Once);
            movieServiceMock.VerifyNoOtherCalls();
        }
Beispiel #2
0
        public async Task Movie_Found_For_Movie_Id()
        {
            var dateToReturn = new DateTime(2011, 10, 10);

            var myMovie = Movie.Instanciate("It", "Bad clown", dateToReturn, 123, 12345, "tt123123", "posterPath",
                                            "backdropPath", DateTime.Now);

            var mockRepo = new Mock <IMovieRepository>();

            mockRepo.Setup(r => r.GetById(It.Is <long>(c => c == 2))).Returns(Task.FromResult(myMovie));

            var movieController = new MovieController(mockRepo.Object, mockStringLocaliser.Object, mockMemoryCache.Object);

            var result = await movieController.GetById(2);

            ContentResult contentResult = result as ContentResult;

            Assert.NotNull(contentResult);
            Assert.Equal((int)HttpStatusCode.OK, contentResult.StatusCode);

            var resultContent = JObject.Parse(contentResult.Content);

            Assert.Equal(myMovie.Name, "" + resultContent["name"]);
            Assert.Equal(myMovie.Overview, "" + resultContent["overview"]);
            Assert.Equal(dateToReturn, DateTime.Parse(resultContent["release_date"] + ""));

            mockRepo.Verify(x => x.GetById(2), Times.Once);
        }
        public async Task GetById_ReturnsAObjectResult_WithAMovieDetailViewModel()
        {
            var mapper = CreateAutomapper();

            var movie = new Movie
            {
                Id       = 2,
                Title    = "Movie title",
                Synopsis = "Short description for the movie",
                Tags     = new List <Tag>
                {
                    new Tag {
                        Id = 1, Name = "Tag 1"
                    },
                    new Tag {
                        Id = 2, Name = "Tag 2"
                    }
                }
            };

            Mock <IMovieService> movieServiceMock = new Mock <IMovieService>();

            movieServiceMock.Setup(s => s.GetByIdAsync(It.IsAny <long>())).Returns(Task.FromResult(movie));

            var controller = new MovieController(mapper, movieServiceMock.Object);

            var result = await controller.GetById(2);

            var objectResult = Assert.IsType <OkObjectResult>(result);
            var model        = Assert.IsAssignableFrom <MovieDetailViewModel>(objectResult.Value);

            Assert.Equal(2, model.Id);
            Assert.Equal(2, model.Tags.Count);
        }
        public async Task GetById_ReturnsNotFound_WhenMovieIsNull()
        {
            var mapper = CreateAutomapper();

            Mock <IMovieService> movieServiceMock = new Mock <IMovieService>();

            movieServiceMock.Setup(s => s.GetByIdAsync(It.IsAny <long>())).Returns(Task.FromResult((Movie)null));

            var controller = new MovieController(mapper, movieServiceMock.Object);

            var result = await controller.GetById(2);

            var notFoundResult = Assert.IsType <NotFoundResult>(result);
        }