public void DetailsValidId()
        {
            // act
            var actual = (Movie)((ViewResult)controller.Details(1)).Model;

            // assert
            Assert.AreEqual(movies.ToList()[0], actual);
        }
Exemplo n.º 2
0
        public void Details_MovieFound_CorrectView()
        {
            var movie  = _db.GetMovies().FirstOrDefault();
            var result = _controller.Details(movie.Id) as ViewResult;

            Assert.IsNotNull(result);
            Assert.IsTrue(string.IsNullOrEmpty(result.ViewName) || result.ViewName.ToLower() == "details");
        }
Exemplo n.º 3
0
        public void Details_NullId_ReturnsBadRequest()
        {
            // Arrange

            // Act
            var result = _controller.Details(null) as HttpStatusCodeResult;

            // Assert
            Assert.AreEqual(result.StatusCode, HttpStatusCode.BadRequest.GetHashCode());
        }
        public void verifyMovieDetailsById()
        {
            Console.WriteLine(fixture.config);
            Console.WriteLine(fixture.config["appName"]);

            var actionTask = controller.Details(1);

            actionTask.Wait();
            //var result = actionTask.Result as ViewResult;
            //Assert.NotNull(result);
            //Assert.Equal("Details", result.ViewName);
        }
Exemplo n.º 5
0
        public void InMemoryDB_Count_Test()
        {
            // verify both movies are added
            Assert.True(controller.MovieExists(1));
            Assert.True(controller.MovieExists(2));

            // Failed test cases, movie with ID 10 not added
            Assert.False(controller.MovieExists(10));

            var result = controller.Details(1).Result;
            //Assert.Equal(movie1.GetType(), result.GetType());
        }
Exemplo n.º 6
0
        public void MovieStore_Details_Success()
        {
            // Arrange
            // Need to have "using Moq" in the header for this to work below
            Mock <IT2030_Lab13_MovieStoreDbContext> mockContext = new Mock <IT2030_Lab13_MovieStoreDbContext>();
            Mock <DbSet <Movie> > mockSet = new Mock <DbSet <Movie> >();

            var list = new List <Movie>
            {
                new Movie {
                    MovieId = 1, Title = "Jaws"
                },
                new Movie {
                    MovieId = 2, Title = "Despicable Me"
                }
            }.AsQueryable();

            mockSet.As <IQueryable <Movie> >().Setup(m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(m => m.Expression).Returns(list.Expression);
            mockSet.As <IQueryable <Movie> >().Setup(m => m.ElementType).Returns(list.ElementType);
            mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(list.First());

            mockContext.Setup(db => db.Movies).Returns(mockSet.Object);

            // Need to pass mock object for Dependency Injection
            MoviesController controller = new MoviesController(mockContext.Object);

            // Act
            ViewResult result = controller.Details(1) as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Exemplo n.º 7
0
        public void Movie_Details_IdIsNull()
        {
            // Goal: Query from our own list instead of the database.
            var list = new List <Movie>
            {
                new Movie()
                {
                    MovieId = 1, Title = "Superman 1"
                },
                new Movie()
                {
                    MovieId = 2, Title = "Superman 2"
                }
            }.AsQueryable();

            Mock <MovieStoreDbContext> mockContext = new Mock <MovieStoreDbContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(m => m.ElementType).Returns(list.ElementType);
            mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(list.First());

            mockContext.Setup(db => db.Movies).Returns(mockSet.Object);

            // Arrange
            MoviesController controller = new MoviesController(mockContext.Object);

            // Act
            HttpStatusCodeResult result = controller.Details(null) as HttpStatusCodeResult;

            // Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, (HttpStatusCode)result.StatusCode);
        }
Exemplo n.º 8
0
        public void MovieStore_MovieIsNull()
        {
            var list = new List <Movie>
            {
                new Movie()
                {
                    MovieId = 1, Title = "Superman"
                },
                new Movie()
                {
                    MovieId = 2, Title = "Batman"
                }
            }.AsQueryable();
            Mock <MovieStoreDBContext> mockContext = new Mock <MovieStoreDBContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator());
            Movie movie = null;

            mockSet.Setup(m => m.Find(It.IsAny <object>())).Returns(movie);
            mockContext.Setup(db => db.Movies).Returns(mockSet.Object);
            MoviesController     controller = new MoviesController(mockContext.Object);
            HttpStatusCodeResult result     = controller.Details(0) as HttpStatusCodeResult;

            Assert.AreEqual(HttpStatusCode.NotFound, (HttpStatusCode)result.StatusCode);
        }
        public void MovieStore_Details_Success()
        {
            //Goal is to query from our own list instead of the database
            var list = new List <Movie>
            {
                new Movie {
                    MovieId = 1, Title = "Superman 1"
                },
                new Movie {
                    MovieId = 2, Title = "Superman 2"
                }
            }.AsQueryable();

            //Step 2
            Mock <NewMovieStoreDbContext> mockContext = new Mock <NewMovieStoreDbContext>();
            Mock <DbSet <Movie> >         mockSet     = new Mock <DbSet <Movie> >();

            //Step 3
            mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(m => m.ElementType).Returns(list.ElementType);
            mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(list.First());

            //Step 4
            mockContext.Setup(db => db.Movies).Returns(mockSet.Object);

            //Arrange
            MoviesController controller = new MoviesController(mockContext.Object);

            //Act
            ViewResult result = controller.Details(1) as ViewResult;

            //Assert
            Assert.IsNotNull(result);
        }
Exemplo n.º 10
0
        public void MovieStore_Details_Success()
        {
            var list = new List <Movie>
            {
                new Movie()
                {
                    MovieId = 1, Title = "Jaws"
                },
                new Movie()
                {
                    MovieId = 2, Title = "Jurrasic Park"
                },
                new Movie()
                {
                    MovieId = 3, Title = "Titanic"
                }
            }.AsQueryable();

            Mock <MovieStoreDbContext> mockContext = new Mock <MovieStoreDbContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(m => m.ElementType).Returns(list.ElementType);
            mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(list.First());

            mockContext.Setup(db => db.Movies).Returns(mockSet.Object);

            MoviesController controller = new MoviesController(mockContext.Object);
            ViewResult       result     = controller.Details(1) as ViewResult;

            Assert.IsNotNull(result);
        }
Exemplo n.º 11
0
        public void MovieStore_Details_MovieNull()
        {
            var list = new List <Movie>
            {
                new Movie()
                {
                    MovieId = 1, Title = "Jaws"
                },
                new Movie()
                {
                    MovieId = 2, Title = "Jurrasic Park"
                },
                new Movie()
                {
                    MovieId = 3, Title = "Titanic"
                }
            }.AsQueryable();

            Mock <MovieStoreDbContext> mockContext = new Mock <MovieStoreDbContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            Movie movie = null;

            mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(m => m.ElementType).Returns(list.ElementType);
            mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(movie);

            mockContext.Setup(db => db.Movies).Returns(mockSet.Object);

            MoviesController     controller = new MoviesController(mockContext.Object);
            HttpStatusCodeResult result     = controller.Details(1) as HttpStatusCodeResult;

            Assert.AreEqual(HttpStatusCode.NotFound, (HttpStatusCode)result.StatusCode);
        }
Exemplo n.º 12
0
        public void GetMovieDetails_InvalidData()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetMovieDetails_InvalidData")
                          .Options;
            MoviesController controller = new MoviesController(new ApplicationDbContext(options));


            var tmp = new Movie
            {
                Description = "Movie Description",
                Genre       = Genre.Action,
                Rating      = 5.4,
                Title       = "Movie Title",
                Year        = 2019
            };

            using (var context = new ApplicationDbContext(options))
            {
                context.Movies.Add(tmp);
                context.SaveChanges();
            }

            ActionResult result = controller.Details(2);

            Assert.IsType <ViewResult>(result);
            if (result.GetType() == typeof(ViewResult))
            {
                var model = ((ViewResult)result).Model;
                Assert.Null(model);
            }
        }
Exemplo n.º 13
0
        public void MovieStore_MovieIsNull()
        {
            var list = new List <Movie>
            {
                new Movie()
                {
                    MovieId = 1, Title = "Superman 1"
                },
                new Movie()
                {
                    MovieId = 2, Title = "Superman 2"
                }
            }.AsQueryable();

            Mock <MovieStoreDBContext> mockContext = new Mock <MovieStoreDBContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.ElementType).Returns(list.ElementType);

            Movie movie = null;

            mockSet.Setup(expression: m => m.Find(It.IsAny <Object>())).Returns(movie);

            mockContext.Setup(expression: db => db.Movies).Returns(mockSet.Object);

            MoviesController controller = new MoviesController(mockContext.Object);

            HttpStatusCodeResult result = controller.Details(id: 0) as HttpStatusCodeResult;


            Assert.AreEqual(expected: HttpStatusCode.NotFound, actual: (HttpStatusCode)result.StatusCode);
        }
Exemplo n.º 14
0
        public void MovieStore_Details_IdIsNull()
        {
            // Goal: Query from out own list instead of the database.

            // Set up own list
            var list = new List <Movie>
            {
                new Movie()
                {
                    MovieId = 1, Title = "Superman 1"
                },
                new Movie()
                {
                    MovieId = 2, Title = "Superman 2"
                }
            }.AsQueryable();

            // Step 2
            Mock <MovieStoreDBContext> mockContext = new Mock <MovieStoreDBContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            // Step 3
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.Setup(expression: m => m.Find(It.IsAny <Object>())).Returns(list.First());
            // Step 4
            mockContext.Setup(expression: db => db.Movies).Returns(mockSet.Object);

            // Arrange
            MoviesController controller = new MoviesController(mockContext.Object);
            // Act
            HttpStatusCodeResult result = controller.Details(id: null) as HttpStatusCodeResult;

            // Assert
            Assert.AreEqual(expected: HttpStatusCode.BadRequest, actual: (HttpStatusCode)result.StatusCode);
        }
Exemplo n.º 15
0
        public void TestDetailsView()
        {
            var controller = new MoviesController();
            var result     = controller.Details() as ViewResult;

            Assert.AreEqual("Details", result.ViewName);
        }
Exemplo n.º 16
0
        public async Task Details()
        {
            try
            {
                var result = await _moviesController.Details(2);
            }
            catch (System.Exception)
            {
                throw new Exception("Error");
            }

            //var resulta;
            //var result = 0;
            //var result = new Object();
            //Exception caughtException = null;


            //Assert.ThrowsException<DetailException>(()=>)
            //var result = false;

            //private readonly ModelContext _context;
            //var controller = new MoviesController(new ModelContext());
            //var result = movies.Details(3);
            // await Assert.ThrowsExceptionAsync( async () =>
            // {
            //   await _moviesController.Details(2);
            // });
            //Assert.ThrowsExceptionAsync(result != null);
            //Assert.IsFalse(result!=null);
        }
        public void MovieStore_Details_No_Id()
        {
            //Arrange
            Mock <MovieStoreDbContext> mockContext = new Mock <MovieStoreDbContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            var list = new List <Movie> {
                new Movie {
                    MovieId = 1, Title = "Jaws"
                },
                new Movie {
                    MovieId = 2, Title = "Despicable Me"
                }
            }.AsQueryable();

            mockSet.As <IQueryable>().Setup(m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable>().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable>().Setup(m => m.Expression).Returns(list.Expression);
            mockSet.As <IQueryable>().Setup(m => m.ElementType).Returns(list.ElementType);
            mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(list.First());

            mockContext.Setup(db => db.Movies).Returns(mockSet.Object);

            //Controller needs a mock object for Dependency Injection
            MoviesController controller = new MoviesController(mockContext.Object);
            //mocDb using Moq

            //Act
            //Id is null
            HttpStatusCodeResult result = controller.Details(null) as HttpStatusCodeResult;


            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, (HttpStatusCode)result.StatusCode);
        }
Exemplo n.º 18
0
        public void MovieStore_Movie_IsNull()
        {
            //Step 1
            var list = new List <Movie>
            {
                new Movie {
                    MovieID = 1, Title = "Spiderman 1"
                },
                new Movie {
                    MovieID = 1, Title = "Spiderman 2"
                }
            }.AsQueryable();

            //Step 2
            Mock <MovieStoreDBContext> mockContext = new Mock <MovieStoreDBContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            //Step 3
            mockSet.As <IQueryable <Movie> >().Setup(m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(m => m.ElementType).Returns(list.ElementType);
            Movie movie = null;

            mockSet.Setup(m => m.Find(It.IsAny <Object>())).Returns(movie);
            //Step 4
            mockContext.Setup(db => db.Movies).Returns(mockSet.Object);
            //Arrange
            MoviesController controller = new MoviesController(mockContext.Object);
            //Act
            HttpStatusCodeResult result = controller.Details(0) as HttpStatusCodeResult;

            //Assert
            Assert.AreEqual(HttpStatusCode.NotFound, (HttpStatusCode)result.StatusCode);
        }
        public void MovieStore_Details_Success()
        {
            //Goal: query from out own list instead of DB
            var list = new List <Movie>
            {
                new Movie()
                {
                    MovieID = 1, Title = "Superman 1"
                },
                new Movie()
                {
                    MovieID = 2, Title = "Superman 2"
                }
            }.AsQueryable();

            Mock <MovieStoreDBContext> mockContext = new Mock <MovieStoreDBContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();

            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.ElementType).Returns(list.ElementType);
            mockSet.Setup(expression: m => m.Find(It.IsAny <Object>())).Returns(list.First());

            mockContext.Setup(expression: db => db.Movies).Returns(mockSet.Object);

            // Arrange
            MoviesController controller = new MoviesController(mockContext.Object);

            // Act
            ViewResult result = controller.Details(id: 1) as ViewResult;


            // Assert
            Assert.IsNotNull(result);
        }
Exemplo n.º 20
0
        public void B_Details_MovieId_ReturnsMovie()
        {
            // Arrange
            var moviesController = new MoviesController(db);

            // Act
            var actionResult = moviesController.Details(2);

            // Assert
            Assert.IsType <ViewResult>(actionResult);
            var viewResult = actionResult as ViewResult;

            Assert.IsType <Movie>(viewResult.Model);
            var movie = viewResult.Model as Movie;

            // Test all properties for the movie corresponding to the actionResult.
            //COMMENTED OUT PORTION CORRESPONDS TO LOCAL MovieRepository TESTING
            //Assert.Equal(1, movie.Id);
            //Assert.Equal("Good Will Hunting", movie.Title);
            //Assert.Equal(new DateTime(2020, 10, 28), movie.DateSeen);
            //Assert.Equal("Drama", movie.Genre);
            //Assert.Equal(9, movie.Rating);
            Assert.Equal(2, movie.Id);
            Assert.Equal("Dude Where's My Car", movie.Title);
            Assert.Equal(new DateTime(2005, 4, 16), movie.DateSeen);
            Assert.Equal("Comedy", movie.Genre);
            Assert.Equal(8, movie.Rating);
        }
Exemplo n.º 21
0
        public void TestDetailsViewData()
        {
            var controller = new MoviesController();
            var result     = controller.Details() as ViewResult;
            var movie      = (Movie)result.ViewData.Model;

            Assert.AreEqual("1", movie.MovieId);
        }
Exemplo n.º 22
0
        public void MoviesControllerDetails()
        {
            var moviesController = new MoviesController(null, null);

            var result = moviesController.Details(1);

            Assert.IsNotNull(result);
        }
        public void TestDetailsViewData()
        {
            var controller = new MoviesController();
            var result     = controller.Details(1) as ViewResult;
            var movie      = (MoviesApp2.Models.Movie)result.ViewData.Model;

            Console.WriteLine(movie);
            Assert.AreEqual("Laptop", movie.Title);
        }
        public void MovieStore_Details_NoId()
        {
            MoviesController controller = new MoviesController();

            //Act
            HttpStatusCodeResult result = controller.Details(null) as HttpStatusCodeResult;

            //Assert
            Assert.AreEqual(HttpStatusCode.BadRequest, (HttpStatusCode)result.StatusCode);
        }
Exemplo n.º 25
0
        public async void movieExistsTest()
        {
            var result = await controller.Details(4);

            Console.WriteLine("inside MoviesControllerTest3 movieExistsTest, result = " + result);
            var resultObj = result as ViewResult;

            Console.WriteLine("inside MoviesControllerTest3 movieExistsTest, resultObj = " + result);
            Assert.Equal(HttpStatusCode.NotFound.ToString(), resultObj.StatusCode.ToString());
        }
Exemplo n.º 26
0
        public void MovieStore_Details_MovieIsNull()
        {
            //Goal:Query from our own list instead of database.

            //Step 1
            var list = new List <Movie>
            {
                new Movie()
                {
                    MovieID = 1,
                    Title   = "Superman 1"
                },

                new Movie()
                {
                    MovieID = 2,
                    Title   = "Superman 2"
                }
            }.AsQueryable();

            //Step 2

            Mock <MovieStoreDbContext> mockContext = new Mock <MovieStoreDbContext>();
            Mock <DbSet <Movie> >      mockSet     = new Mock <DbSet <Movie> >();



            //Step 3
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.GetEnumerator()).Returns(list.GetEnumerator());
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.Provider).Returns(list.Provider);
            mockSet.As <IQueryable <Movie> >().Setup(expression: m => m.ElementType).Returns(list.ElementType);


            Movie movie = null;

            mockSet.Setup(expression: m => m.Find(It.IsAny <Object>())).Returns(movie);


            //Step 4
            mockContext.Setup(expression: db => db.Movies).Returns(mockSet.Object);

            //Arrange

            MoviesController controller = new MoviesController(mockContext.Object);


            //Act

            HttpStatusCodeResult result = controller.Details(id: 0) as HttpStatusCodeResult;


            //Assert

            Assert.AreEqual(expected: HttpStatusCode.NotFound, actual: (HttpStatusCode)result.StatusCode);
        }
        public void MockMovieRepisotoryOnDetails()
        {
            var movie   = new Movie();
            var service = new Mock <IMovieRepository>();

            service.Setup(x => x.GetMovieById(1)).Returns(movie);
            _moviesController = new MoviesController(service.Object);

            var expected = movie;
            var result   = _moviesController.Details(1);
            var actual   = ((ViewResult)result).Model as Movie;

            Assert.AreEqual(actual, expected);
        }
        public void MockMovieIncorrectID()
        {
            var movie   = new Movie();
            var service = new Mock <IMovieRepository>();

            service.Setup(x => x.GetMovieById(1)).Returns(movie);
            _moviesController = new MoviesController(service.Object);

            var expectedErrorCode = 404;
            var result            = _moviesController.Details(1000000);
            var viewResult        = (HttpNotFoundResult)result;
            var actual            = viewResult.StatusCode;

            Assert.AreEqual(expectedErrorCode, actual);
        }
        public async Task Should_Return_NotFound_On_Details_When_MovieNotFoundException_Is_Thrown()
        {
            // Arrange
            Mock <IMoviesService> mockService = new Mock <IMoviesService>();
            int?id = 1;

            mockService.Setup(x => x.GetMovie(id)).Throws(new MovieNotFoundException());
            MoviesController systemUnderTest = new MoviesController(mockService.Object);

            // Act
            IActionResult result = await systemUnderTest.Details(id);

            // Assert
            Assert.True(result is NotFoundResult);
        }
        public async Task Should_Return_View_With_Movie_On_Details_When_Movie_Is_Found()
        {
            // Arrange
            Mock <IMoviesService> mockService = new Mock <IMoviesService>();
            Movie aMovie = new Movie();
            int?  id     = 1;

            mockService.Setup(x => x.GetMovie(id)).Returns(Task.FromResult(aMovie));
            MoviesController systemUnderTest = new MoviesController(mockService.Object);

            // Act
            IActionResult result = await systemUnderTest.Details(id);

            // Assert
            Assert.True(result is ViewResult);
            Assert.True(((ViewResult)result).Model is Movie);
        }