public void Get_Call_Check_For_OK_Result() { //Act var result = _controller.Get(); //Assert Assert.IsType <OkObjectResult>(result); }
public async void Get_WhenCalled_ReturnsActionResultMovieModel() { //-- Arrange //-- Act var result = await _controller.Get(); //-- Assert Assert.IsType <ActionResult <MovieModel[]> >(result); }
public async Task GivenGetIsInvokedWhenValidationFailsThenReturnBadRequest() { _movieRequestValidator.Setup(validator => validator.Validate( It.IsAny <string>(), It.IsAny <int>(), It.IsAny <string>())).Returns(false); var result = await _controller.Get("title", 2000, "genre"); result.Should().BeOfType <BadRequestResult>(); _movieRepository.Verify(repo => repo.GetAsync(It.IsAny <MovieFilterCriteria>()), Times.Never); }
public void GetShouldReturnNotFoundIfNoMoviesFound() { //ARRANGE var searchTitle = "not found title"; //ACT var result = _controller.Get(searchTitle, DateTime.Now, new System.Collections.Generic.List <string>()); var resultStatus = result as NotFoundResult; //ASSERT resultStatus.StatusCode.ShouldBe(404); }
public void MoviesHasRating() { var movies = _movieController.Get().ToList(); movies.ForEach(movie => { var t = movie.GetType(); var rating = t.GetProperty("Rating"); var ratings = t.GetProperty("Ratings"); Assert.IsNotNull(rating, "Property Rating is missing on object Movie"); Assert.IsNotNull(ratings, "Property Ratings is missing on object Movie"); }); }
public void Get_InvalidUserId_ValidSearchText_ReturnsBadRequest() { // Arrange var expectedErrorMessage = "The userId is not valid."; var expectedStatusCode = StatusCodes.Status400BadRequest; // Act var actualResult = _moviesController.Get(It.IsAny <int>(), "Steven Spielberg").Result; // Assert Assert.IsInstanceOfType(actualResult, typeof(ObjectResult)); Assert.AreEqual(((ObjectResult)actualResult).Value, expectedErrorMessage); Assert.AreEqual(((ObjectResult)actualResult).StatusCode, expectedStatusCode); }
public void CheckForIncrement() { var originalNumber = _movieController.Get().Length; var movie = new Movie() { Title = "Incremented Movie", Description = "Incremented Movie description", Genre = "Crime|Fantasy" }; _movieController.Put(movie); var newNumber = _movieController.Get().Length; Assert.Greater(newNumber, originalNumber, "The number of movies in the database did not increase."); }
public async Task ReturnBadRequestWhenGetMoviesReturnsNull() { _getMoviesService .GetMovies() .ReturnsNull(); var response = await _moviesController.Get().ConfigureAwait(false); Assert.Multiple(() => { Assert.IsNotNull(response); var actionResult = ((NoContentResult)response.Result); Assert.AreEqual((int)HttpStatusCode.NoContent, actionResult.StatusCode); }); }
public void Test1() { // Arrange Test the API SearchRequest searchRequest = new SearchRequest { S = "Avengers" }; #region Mock Data List <MovieSearch> mockSearch = new List <MovieSearch>(); mockSearch.Add(new MovieSearch { imdbID = "2828282", Poster = "jpg", Title = "Avengers Dark Age", Type = "Movies", Year = "2015" }); mockSearch.Add(new MovieSearch { imdbID = "2828283", Poster = "jpg", Title = "Avengers [End Game]", Type = "Movies", Year = "2019" }); _moivemockSearch = mockSearch; #endregion var mockRepo = new Mock <IMoviesRepository>(); var mockDb = new Mock <ISearchRepository>(); mockRepo.Setup(repo => repo.Search <MovieSearchResult>(searchRequest)).Returns(MockData); var moviecontroller = new MoviesController(mockRepo.Object, mockDb.Object); var dd = moviecontroller.Get(searchRequest); var model = Assert.IsAssignableFrom <List <MovieSearch> >(dd); Assert.True(model.Count > 0); }
public async void GetShouldReturnOkResult() { var result = await _controller.Get(); Assert.IsType <OkObjectResult>(result); Assert.Equal(200, (result as OkObjectResult).StatusCode); }
public void TestGetPerMovie_ReturnNotFound() { string movieListString = "[{\"Title\": \"Star Wars: Episode IV - A New Hope\",\"Year\": \"1977\",\"ID\": \"cw0076759\",\"Type\": \"movie\",\"Poster\": \"http://ia.media-imdb.com/images/M/MV5BOTIyMDY2NGQtOGJjNi00OTk4LWFhMDgtYmE3M2NiYzM0YTVmXkEyXkFqcGdeQXVyNTU1NTcwOTk@._V1_SX300.jpg\"}]"; string movieListString2 = "[{\"Title\": \"Star Wars: Episode IV - A New Hope 2\",\"Year\": \"1977\",\"ID\": \"cw0076759\",\"Type\": \"movie\",\"Poster\": \"http://ia.media-imdb.com/images/M/MV5BOTIyMDY2NGQtOGJjNi00OTk4LWFhMDgtYmE3M2NiYzM0YTVmXkEyXkFqcGdeQXVyNTU1NTcwOTk@._V1_SX300.jpg\"}]"; string movie = "{\"Title\": \"Star Wars: Episode IV - A New Hope\",\"Year\": \"1977\",\"ID\": \"cw0076759\",\"Type\": \"movie\",\"Poster\": \"http://ia.media-imdb.com/images/M/MV5BOTIyMDY2NGQtOGJjNi00OTk4LWFhMDgtYmE3M2NiYzM0YTVmXkEyXkFqcGdeQXVyNTU1NTcwOTk@._V1_SX300.jpg\"}"; string movie2 = "{\"Title\": \"Star Wars: Episode IV - A New Hope2\",\"Year\": \"1977\",\"ID\": \"cw0076759\",\"Type\": \"movie\",\"Poster\": \"http://ia.media-imdb.com/images/M/MV5BOTIyMDY2NGQtOGJjNi00OTk4LWFhMDgtYmE3M2NiYzM0YTVmXkEyXkFqcGdeQXVyNTU1NTcwOTk@._V1_SX300.jpg\"}"; Mock <IMovieServicesFactory> movieServicesFactoryMock = new Mock <IMovieServicesFactory>(); Mock <IConfigurationService> configurationServiceMock = new Mock <IConfigurationService>(); IDictionary <string, IProvider> providersDictionary = new Dictionary <string, IProvider>(); configurationServiceMock.Setup(o => o.ProvidersDictionary).Returns(providersDictionary); Mock <IHttpService> webJetWrapperServiceMock = new Mock <IHttpService>(); HttpStatusCode httpStatusCode = HttpStatusCode.OK; webJetWrapperServiceMock.Setup(o => o.Get("GetPerItemAPI", out httpStatusCode)).Returns(movie); webJetWrapperServiceMock.Setup(o => o.Get("GetPerItemAPI", out httpStatusCode)).Returns(movie2); movieServicesFactoryMock.Setup(o => o.GetConfigurationService()).Returns(configurationServiceMock.Object); movieServicesFactoryMock.Setup(o => o.GetHttpService()).Returns(webJetWrapperServiceMock.Object); MoviesController movieController = new MoviesController(movieServicesFactoryMock.Object); movieController.Request = new HttpRequestMessage(); movieController.Request.Properties.Add(HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration()); HttpResponseMessage responseMessage = movieController.Get("cw0076759", "cinemaworld"); Assert.AreEqual(responseMessage.StatusCode, HttpStatusCode.NotFound); }
public void Get_with_valid_Id_returns_OkObjectResult_and_model() { // Arrange var mockService = new Mock <IMovieService>(); mockService.Setup(service => service.GetMovie(It.IsAny <int>())) .Returns(new Movie { Id = 1, Title = "Spectre", ReleaseYear = 2015, Summary = "007 against spectre" }); var sut = new MoviesController(mockService.Object); // Act var result = sut.Get(1); // Assert var okObjectResult = Assert.IsType <OkObjectResult>(result); var outputModel = Assert.IsType <MovieOutputModel>(okObjectResult.Value); Assert.Equal(expected: "Spectre", actual: outputModel.Title); Assert.Equal(expected: 2015, actual: outputModel.ReleaseYear); Assert.Equal(expected: "007 against spectre", actual: outputModel.Summary); }
public void Assert_GetById_ReturnsNotFound_IfIdDoesntExist() { //Arrange var options = new DbContextOptionsBuilder <TestDemoContext>() .UseInMemoryDatabase(databaseName: "Add_Movies_To_database") .Options; //Act using (var context = new TestDemoContext(options)) { context.Movie.Add(new Movie { Genre = "Thriller", Id = 2, ReleaseDate = DateTime.Now, Title = "Superman" }); context.SaveChanges(); } //Assert using (var context = new TestDemoContext(options)) { var repo = new EfCoreMovieRepository(context); var controller = new MoviesController(repo); var Movie = controller.Get(3); Assert.IsType <NotFoundResult>(Movie.Result.Result); } }
public void GetAllMoviesTest() { var config = new ConfigurationBuilder() .Build(); MoviesController controller = new MoviesController(new MovieRepository(config)); Assert.NotNull(controller.Get()); }
public async void MoviesController_Get_ReturnOkResult(int price, int expectedPrice, string expectedCollection) { // arrange var fakeMovie = new Movie { Id = "B1", Title = "Real Fake Title", Price = price, Year = "2222" }; var fakeMoviesList = new List <Movie> { fakeMovie }; _moqMovieRepository.Setup(repo => repo.FindAsync(CollectionEndPoint, It.IsAny <Func <Movie, bool> >())) .ReturnsAsync(_fakeMovie); _moqMovieRepository.Setup(repo => repo.GetAsync(SingleEndpoint, _fakeMovie.Id)) .ReturnsAsync(_fakeMovie); var moqMovieRepository = new Mock <IMovieRepository>(); moqMovieRepository.Setup(repo => repo.GetAllAsync(CollectionEndPoint)) .ReturnsAsync(fakeMoviesList); moqMovieRepository.Setup(repo => repo.FindAsync(CollectionEndPoint, It.IsAny <Func <Movie, bool> >())) .ReturnsAsync(fakeMovie); moqMovieRepository.Setup(repo => repo.GetAsync(SingleEndpoint, fakeMovie.Id)) .ReturnsAsync(fakeMovie); _movieRepoDictFake.Add("movieRepKey2", moqMovieRepository.Object); // act var result = await _moviesController.Get(year : "2222", title : "Real Fake Title"); var value = (TupleWrapperResponse <Movie>)((OkObjectResult)result.Result).Value; // assert Assert.IsType <OkObjectResult>(result.Result); Assert.Equal(expectedPrice, value.Member.Price); Assert.Equal(expectedCollection, value.ParentName); }
public void Get_WhenCalled_ReturnsOkResult() { // Act var okResult = _controller.Get(); // Assert Assert.IsType <ActionResult <List <Movie> > >(okResult.Result); }
public void GetMoviesTest() { MoviesController moviesController = new MoviesController(); var result = moviesController.Get("Waterworld").Result; Assert.IsNotNull(result); // Assert.IsInstanceOfType(result, typeof(MovieResponse)); Assert.AreEqual(11, result.Total); }
public void ShouldGetMoviesFromService() { var movieQuery = new MovieQuery(); var controller = new MoviesController(_mockMovieService.Object); controller.Get(movieQuery); _mockMovieService.Verify(m => m.All(movieQuery), Times.Once); }
public void GetReturns400WithNoCriteriaSet() { MoviesController sut = CreateSystemUnderTest(); var result = sut.Get(null, null, Genre.None); _mockMovieAccess.Verify(a => a.GetMovies(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <Genre>()), Times.Never); Assert.IsType <BadRequestResult>(result); }
public void ShouldGetMovieFromService() { var movieId = 20; var controller = new MoviesController(_mockMovieService.Object); controller.Get(movieId); _mockMovieService.Verify(m => m.Get(movieId), Times.Once); }
public void TestMoviesInListByGet() { // arrange // iniatialize before each test // act List <Movies> movies = new List <Movies>(controller.Get()); // assert Assert.AreEqual(6, movies.Count); }
public async Task GetMethodWithUnknownIdArgShouldReturnNotFoundException() { var movies = CreateMoviesCollection(); using (MoviesController movieController = new MoviesController(CreateMoviesRepositoryMock(movies))) { var result = await movieController.Get(Guid.NewGuid().ToString()); Assert.IsType <NotFoundResult>(result); } }
public async Task GetMethodShouldReturnAllMovies() { var movies = CreateMoviesCollection(); using (MoviesController movieController = new MoviesController(CreateMoviesRepositoryMock(movies))) { var result = await movieController.Get(); Assert.Equal(movies.Length, result.Count()); } }
public void Get() { var testMovies = GetTestMovies(); var controller = new MoviesController(testMovies); controller.Request = new HttpRequestMessage(); controller.Configuration = new HttpConfiguration(); var response = controller.Get(); Assert.IsNotNull(response); }
public async Task GetMethodWithIdArgShouldReturnMovieIdentifiedById() { var movies = CreateMoviesCollection(); using (MoviesController movieController = new MoviesController(CreateMoviesRepositoryMock(movies))) { var movie = movies[0]; var result = (await movieController.Get(movie.Id.ToString())) as OkObjectResult; Assert.NotNull(result); Assert.Equal(movie, result.Value); } }
public void GetAllMoviesTest() { var repository = MockRepository(r => r.GetAllMovies()).Object; var actorsController = new MoviesController(repository); var result = actorsController.Get() as OkObjectResult; Assert.NotNull(result); Assert.NotNull(result.StatusCode); Assert.Equal((int)HttpStatusCode.OK, result.StatusCode.Value); Assert.IsType <Movie[]>(result.Value); Assert.Equal(_movies.Length, ((Movie[])result.Value).Length); }
public void GetReturns404WhenNoMoviesFound() { _mockMovieAccess.Setup(a => a.GetMovies(It.IsAny <string>(), It.IsAny <int?>(), It.IsAny <Genre>())) .Returns(new List <Movie>()); MoviesController sut = CreateSystemUnderTest(); var result = sut.Get("test", null, Genre.None); _mockMovieAccess.Verify(a => a.GetMovies("test", null, Genre.None), Times.Once); Assert.IsType <NotFoundResult>(result); }
public void Get_ModelIsNull_BadRequestReturned() { var result = controller.Get((MovieFilterCriteriaModel)null); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(BadRequestResult)); }
public void TestMethod_Controller_Sort() { // Arrange mockMovieHelper.Setup(p => p.OrderMovies(mockMovieList, "Title")).Returns(mockMovieList); mockMovieRepo.Setup(p => p.Get()).Returns(mockMovieList); moviesController = new MoviesController(mockMovieRepo.Object, mockMovieHelper.Object); // Act var result = moviesController.Get("Title"); // Assert Assert.AreEqual(4, result.Count); }
public void TestMethod_Get() { // Arrange mockMovieRepo.Setup(p => p.Get()).Returns(mockMovieList); moviesController = new MoviesController(mockMovieRepo.Object, mockMovieHelper.Object); // Act var contentResult = moviesController.Get(); // Assert Assert.AreEqual(contentResult.Count, 4); Assert.AreEqual(contentResult[0].Title, "The Simpsons Movie"); }