public void Should_Return_Movies() { _mock.Setup(item => item.GetMovies("popular")).Returns(It.IsAny <IEnumerable <Movie> >()); var actual = _movieController.Get("popular"); _mock.Verify(item => item.GetMovies("popular"), Times.Once); Assert.IsAssignableFrom <IActionResult>(actual); Assert.NotNull(actual); }
public async Task GetMovies() { movieRepositoryMock.Setup(mr => mr.GetMovies()).ReturnsAsync(listOfMovies); var response = await movieController.Get() as OkObjectResult; var movies = response.Value as IEnumerable <MovieViewModel>; Assert.Equal(200, response.StatusCode); var listItems = Assert.IsType <List <MovieViewModel> >(movies); Assert.Equal(2, listItems.Count); }
public void GetAllTest() { var controller = new MovieController(); var result = controller.Get(); Assert.Equal(3, result.Count()); }
public void TestGet() { var controller = new MovieController(new TestMovieModelContext()); var result = controller.Get(); Assert.AreEqual(1, 1); }
public void TestGetAllMoviesOk() { List <Movie> moviesToReturn = new List <Movie>() { new Movie() { Id = 1, Name = "Iron man 3", Description = "I'm Iron man", AgeAllowed = 16, Duration = 1.5 }, new Movie() { Id = 2, Name = "Iron man 2", Description = "I'm Iron man", AgeAllowed = 16, Duration = 1.5 } }; var mock = new Mock <IMovieLogic>(MockBehavior.Strict); mock.Setup(m => m.GetAll()).Returns(moviesToReturn); var controller = new MovieController(mock.Object); var result = controller.Get(); var okResult = result as OkObjectResult; var movies = okResult.Value as IEnumerable <MovieBasicInfoModel>; mock.VerifyAll(); Assert.IsTrue(moviesToReturn.Select(m => new MovieBasicInfoModel(m)).SequenceEqual(movies)); }
public void GetTest() { MovieController movie = new MovieController(); var lstMovies = movie.Get(); Assert.IsNotNull(lstMovies); Assert.IsTrue(lstMovies.Count > 0); }
public void Get_ShouldNotReturnAllRecommendationmoviesForInvalid() { // Arrange var controller = new MovieController(mockService.Object); // Act var badResponse = controller.Get(); //Assert Assert.IsType <NotFoundResult>(badResponse); }
public static Movie GetMovieById(int id) { try { return(MovieController.Get(id)); } catch (Exception e) { return(new Movie()); } }
public void _2_GetSharedView() { var loginController = new LoginController(); var httpResponseMessage = loginController.Post(new Models.MyString(LoginControllerTest.UserTest)); var token = (JObject)JsonConvert.DeserializeObject(httpResponseMessage.Content.ReadAsStringAsync().Result); var httpResponseMessage2 = loginController.Get(token["token"].ToString()); var userInfo = (JObject)JsonConvert.DeserializeObject(httpResponseMessage2.Content.ReadAsStringAsync().Result); var movieController = new MovieController(); var httpResponseMessage3 = movieController.Get(userInfo["Id"].ToString()); Assert.AreNotEqual("good-bye", httpResponseMessage3.Content.ReadAsStringAsync().Result); }
public void Get_ShouldReturnAllRecommendationmoviesAsExpected() { // Arrange this.mockService.Setup(x => x.GetRecommendedMovies()).Returns(this.GetTestMovies); var controller = new MovieController(mockService.Object); // Act var result = controller.Get(); var actualResult = result as OkObjectResult; //Assert Assert.NotNull(actualResult.Value); }
public async Task ReturnNotFoundIfRequestIsNotfound() { var handlerMock = MockGenerator.HttpMessageHandlerMock(HttpStatusCode.NotFound); var httpClient = new HttpClient(handlerMock.Object); var movieController = new MovieController(httpClient); var resultado = await movieController.Get(); Assert.IsType <NotFoundResult>(resultado); }
public void Test_Controller_Get_NotFound(string title) { mockRepo.Setup(x => x.Get(It.IsAny <string>())) .Returns(seed.FirstOrDefault(x => x.Title == title)); var controller = new MovieController(mockRepo.Object); //Act var response = controller.Get(title); //Assert mockRepo.Verify(x => x.Get(title), Times.Once); Assert.IsType <NotFoundObjectResult>(response.Result); }
public void GetMethodWithoutParameter_ShouldReturnBadRequest() { var mockService = new Mock <IMovieService>(); mockService.Setup(x => x.GetAllMovies()).Returns(new List <Movie>()); var controller = new MovieController(mockService.Object); var result = controller.Get(1, 5); //Assert var actionResult = Assert.IsType <OkObjectResult>(result); Assert.Equal(200, actionResult.StatusCode); }
[Fact]//negative public void GetMethodWithParam_ShouldReturnNotFoundStatusOnInvalidId() { //arrange var testMovieId = 10006; var mockRepo = new Mock <IMovieService>(); mockRepo.Setup(x => x.GetMovieById(testMovieId)).Returns(() => throw new System.ArgumentException()); var controller = new MovieController(mockRepo.Object); //act var actual = controller.Get(testMovieId); //assert var result = Assert.IsType <NotFoundObjectResult>(actual); }
public void GetMethodWithoutParameter_ShouldReturnListOfMovie() { //Arrange var mockService = new Mock <IMovieService>(); mockService.Setup(service => service.GetAllMovies()).Returns(this.GetMovies()); var controller = new MovieController(mockService.Object); //Act var result = controller.Get(); //Assert var actionresult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <IEnumerable <Movie> >(actionresult.Value); }
public void GetMethodWithoutParam_ShouldReturnListofMovie() { //arrange var mockRepo = new Mock <IMovieService>(); mockRepo.Setup(x => x.GetAllMovies()).Returns(this.GetMovies()); var controller = new MovieController(mockRepo.Object); //act var actual = controller.Get(); //assert var result = Assert.IsType <OkObjectResult>(actual); Assert.IsAssignableFrom <IEnumerable <Movie> >(result.Value); }
public void GetMethodWithoutParameter_ShouldReturnListOfMovie() { var mockService = new Mock <IMovieService>(); mockService.Setup(x => x.GetAllMovies()).Returns(GetAllMovies()); var controller = new MovieController(mockService.Object); var result = controller.Get(1, 5); //Assert var actionResult = Assert.IsType <OkObjectResult>(result); var response = Assert.IsAssignableFrom <IEnumerable <Movie> >(actionResult.Value); Assert.NotNull(response); Assert.Equal(200, actionResult.StatusCode); }
public void MovieController_Get_Should_Return_200_And_Data_Not_Null_Test() { //Arrange var movieSearch = GetSearch(); var movie = GetMovie(); _movieRepository.Setup(p => p.Get(movieSearch)).Returns(movie); var controller = new MovieController(_memoryCache, _movieRepository.Object, dataSourceOptions, cachingOptions); //Act var result = controller.Get(movieSearch); //Assert Assert.IsInstanceOf <OkObjectResult>(result); Assert.IsNotNull(result); }
public void MovieTests() { config3.Setup(p => p.GetMovies()).Returns(new List <Movie> { new Movie() { Id = 1, Movie_Name = "", Movie_Description = "DFD", DateAndTime = "DF", MoviePicture = "DD" } }); var result = TokenObj3.Get(); Assert.That(result, Is.InstanceOf <OkObjectResult>()); // Assert.That(result, Is.TypeOf<List<User>>()); }
public void GetMethodWithParam_ShouldReturnAMovieOnValidId() { //arrange var testMovieId = 10001; var mockRepo = new Mock <IMovieService>(); mockRepo.Setup(x => x.GetMovieById(testMovieId)).Returns(this.GetMovies().FirstOrDefault(x => x.Id == testMovieId)); var controller = new MovieController(mockRepo.Object); //act var actual = controller.Get(testMovieId); //assert var result = Assert.IsType <OkObjectResult>(actual); Assert.IsAssignableFrom <Movie>(result.Value); }
public void Get_Returns_Null() { //Arrange var mockrepo = new Mock <IMovieRepository>(); mockrepo.Setup(repo => repo.GetMovies()).Throws <MovieNotFoundException>(); var controller = new MovieController(mockrepo.Object); //Act var result = controller.Get(); //Assert var actionresult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <ApiResponse>(actionresult.Value); Assert.False(model.Success); Assert.Null(model.Data); }
public void Get_Returns_AListOfMovies() { //Arrange var mockrepo = new Mock <IMovieRepository>(); mockrepo.Setup(repo => repo.GetMovies()).Returns(GetMovies()); var controller = new MovieController(mockrepo.Object); //Act var result = controller.Get(); //Assert var actionresult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <ApiResponse>(actionresult.Value); Assert.True(model.Success); Assert.IsAssignableFrom <IEnumerable <Movie> >(model.Data); }
public void ShouldReturnListOfMovies() { //arrange var movies = new List <Movie>() { new Movie(), new Movie() }; var movieRepository = new Mock <IRepository <Movie> >(); //act movieRepository.Setup(x => x.GetAll()).Returns(movies); var movieService = new MovieService(movieRepository.Object); var movieController = new MovieController(movieService); var result = movieController.Get(); //assert Assert.Equal(movies, result); }
public void GetById_Returns_Success() { //Arrange var mockrepo = new Mock <IMovieRepository>(); var _movie = new Movie { id = 354440, name = "Superman", posterPath = "superman.jpg", releaseDate = "12-10-2012", comments = string.Empty, voteAverage = 7.8, voteCount = 980 }; mockrepo.Setup(repo => repo.GetMovieById(354440)).Returns(_movie); var controller = new MovieController(mockrepo.Object); //Act var result = controller.Get(354440); //Assert var actionresult = Assert.IsType <OkObjectResult>(result); var model = Assert.IsAssignableFrom <ApiResponse>(actionresult.Value); Assert.True(model.Success); Assert.IsAssignableFrom <Movie>(model.Data); }
public void Test_Controller_Get() { // Arrange string title = "Avenger"; mockRepo.Setup(x => x.Get(It.IsAny <string>())) .Returns(seed.FirstOrDefault(x => x.Title == title)); var controller = new MovieController(mockRepo.Object); //Act var response = controller.Get(title); //Assert mockRepo.Verify(x => x.Get(title), Times.Once); var result = (Assert.IsType <OkObjectResult>(response.Result)) as OkObjectResult; var movie = Assert.IsType <Movie>(result.Value); Assert.Equal(title, movie.Title); }
public async Task Get_ReturnsAMovieListVieWModel() { var mapper = CreateAutomapper(); Mock <IMovieService> movieServiceMock = new Mock <IMovieService>(); movieServiceMock.Setup(s => s.ListAsync(It.IsAny <int>(), It.IsAny <int>())) .Returns(Task.FromResult(GetTestMovies())); var controller = new MovieController(mapper, movieServiceMock.Object); var result = await controller.Get(1, 3); Assert.IsType <MovieListViewModel>(result); Assert.Equal(3, result.Items.Count()); Assert.Equal(2, result.Paging.TotalPages); Assert.Equal(1, result.Paging.PageIndex); Assert.Equal(3, result.Paging.PageSize); Assert.Equal(6, result.Paging.TotalItems); }
public void _3_Vote() { try { var loginController = new LoginController(); var httpResponseMessage = loginController.Post(new Models.MyString(LoginControllerTest.UserTest)); var token = (JObject)JsonConvert.DeserializeObject(httpResponseMessage.Content.ReadAsStringAsync().Result); var httpResponseMessage2 = loginController.Get(token["token"].ToString()); var userInfo = (JObject)JsonConvert.DeserializeObject(httpResponseMessage2.Content.ReadAsStringAsync().Result); var movieController = new MovieController(); var httpResponseMessage3 = movieController.Get(userInfo["Id"].ToString()); var sharedList = JsonConvert.DeserializeObject <SharedView[]>(httpResponseMessage3.Content.ReadAsStringAsync().Result); foreach (var s in sharedList) { if (s.Url == TestUrl) { var voteController = new VoteController(); voteController.Post(new Vote() { MovieId = s.MovieId, UserId = Int64.Parse(userInfo["Id"].ToString()), IsUpVote = true }); //success QueryHelper.ClearUnitTestData(Int64.Parse(userInfo["Id"].ToString()), s.MovieId); Assert.IsTrue(true); return; } } //failed } catch (Exception) { //failed } Assert.Fail(); }
public void WhenRequestIsValidThenSuccess() { var result = _movieController.Get(1); Assert.NotNull(result); }