Example #1
0
 public bool Create(MovieModelDAL movie)
 {
     try
     {
         using (var DBConnection = new DB())
         {
             DBConnection.Movies.Add(movie);
             DBConnection.SaveChanges();
             Loggings.GeneralLog("Created Movie with ID: " + movie.ID);
             return(true);
         }
     }
     catch (Exception ex)
     {
         var logg = new LoggTypeDAL()
         {
             EventType    = "Exception",
             Created_By   = "System",
             LogMessage   = ex.ToString(),
             Created_date = DateTime.Now
         };
         Loggings.LogToBoth(logg);
         return(false);
     }
 }
Example #2
0
        public async Task Delete_WhenOneMovieExists_ExpectedResultCount0()
        {
            //Arrange
            var input = new MovieModelDAL
            {
                ID         = 1,
                Title      = "MOVIE: the Movie",
                Genre      = "Comedy",
                Director   = "MySelf",
                ImdbRating = 9000,
                Plot       = "This is a movie",
                Rated      = "Insert age here...",
                Year       = 2018
            };
            var initialMovies = new List <MovieModelDAL> {
                input
            };

            var DALStub = new MovieDALStub(initialMovies);

            //Act
            bool test1  = DALStub.Delete(1);
            var  result = await DALStub.GetAll(false);

            //Assert
            Assert.IsTrue(test1);
            Assert.IsTrue(result.Count == 0);
        }
Example #3
0
        public async Task Create_WhenOtherMoviesExist_ExpectedResultTrueAreEqual()
        {
            //Arrange
            var DALStub = new MovieDALStub(_Seed);
            var input   = new MovieModelDAL
            {
                ID         = 4,
                Title      = "MOVIE: the Movie",
                Genre      = "Comedy",
                Director   = "MySelf",
                ImdbRating = 9000,
                Plot       = "This is a movie",
                Rated      = "Insert age here...",
                Year       = 2018
            };

            var expectedResult = new List <MovieModelDAL>(_Seed);

            expectedResult.Add(input);

            //Act
            bool test1  = DALStub.Create(input);
            var  result = await DALStub.GetAll(false);

            //Assert
            Assert.IsTrue(test1);
            Assert.IsTrue(expectedResult.Count == result.Count);
            for (int i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(expectedResult[i].ID, result[i].ID);
                Assert.AreEqual(expectedResult[i].Title, result[i].Title);
            }
        }
        public void GetAllMoviesWithTitleMatchingSearchTextTest()
        {
            //Arrange
            var seedDB = new List <MovieModelDAL>();
            var seed   = new MovieModelDAL
            {
                ID         = 5050,
                Title      = "Movie",
                Year       = 2018,
                Rated      = "10",
                Runtime    = "20 min",
                Genre      = "Commedy",
                Director   = "Director",
                Plot       = "Some Plot",
                Poster     = "www.poster.com",
                ImdbRating = 10f,
                ScreenShot = "www.screenshot.com"
            };

            seedDB.Add(seed);
            var controller = new MoviesLogic(new MovieDALStub(seedDB));
            var rightInput = "Movie";
            var wrongInput = "Not";
            //Act
            var result1 = controller.GetAllMoviesWithTitleMatchingSearchText(rightInput);
            var result2 = controller.GetAllMoviesWithTitleMatchingSearchText(wrongInput);

            //Assert
            Assert.IsTrue(result1.Count == 1);
            Assert.IsFalse(result2.Count > 0);
        }
        public void GetMoviesTest()
        {
            //Arrange
            var seedDB = new List <MovieModelDAL>();
            var seed   = new MovieModelDAL
            {
                ID         = 5050,
                Title      = "Movie",
                Year       = 2018,
                Rated      = "10",
                Runtime    = "20 min",
                Genre      = "Commedy",
                Director   = "Director",
                Plot       = "Some Plot",
                Poster     = "www.poster.com",
                ImdbRating = 10f,
                ScreenShot = "www.screenshot.com"
            };

            seedDB.Add(seed);
            var controller = new MoviesLogic(new MovieDALStub(seedDB));

            //Act
            var result1 = controller.GetMovies(true);

            //Assert
            Assert.IsTrue(result1.Result.Count == 1);
        }
        public void GetMovieTest()
        {
            //Arrange
            var seedDB = new List <MovieModelDAL>();
            var seed   = new MovieModelDAL
            {
                ID         = 5050,
                Title      = "Movie",
                Year       = 2018,
                Rated      = "10",
                Runtime    = "20 min",
                Genre      = "Commedy",
                Director   = "Director",
                Plot       = "Some Plot",
                Poster     = "www.poster.com",
                ImdbRating = 10f,
                ScreenShot = "www.screenshot.com"
            };

            seedDB.Add(seed);
            var controller = new MoviesLogic(new MovieDALStub(seedDB));
            var rightInput = 5050;
            var wrongInput = -10;

            //Act
            var result1 = controller.GetMovie(rightInput);
            var result2 = controller.GetMovie(wrongInput);

            //Assert
            Assert.IsNotNull(result1);
            Assert.IsNull(result2);
        }
Example #7
0
        public bool Update(MovieModelDAL movie)
        {
            var movieFound = _MovieDB.FirstOrDefault(b => b.ID.Equals(movie.ID));

            if (movieFound == null)
            {
                return(false);
            }

            _MovieDB.Remove(movieFound);
            _MovieDB.Add(movie);
            return(true);
        }
Example #8
0
        public bool Update(MovieModelDAL movie)
        {
            try
            {
                using (var DBConnection = new DB())
                {
                    var movieFound = DBConnection.Movies.Find(movie.ID);

                    if (movieFound == null)
                    {
                        Loggings.GeneralLog("Could not find Movie with ID: " + movie.ID);
                        return(false);
                    }

                    movieFound.Title      = movie.Title;
                    movieFound.Year       = movie.Year;
                    movieFound.Rated      = movie.Rated;
                    movieFound.Runtime    = movie.Runtime;
                    movieFound.Genre      = movie.Genre;
                    movieFound.Director   = movie.Director;
                    movieFound.Plot       = movie.Plot;
                    movieFound.Poster     = movie.Poster;
                    movieFound.ImdbRating = movie.ImdbRating;
                    movieFound.ScreenShot = movie.ScreenShot;
                    DBConnection.SaveChanges();
                    Loggings.GeneralLog("Updated Movie with ID: " + movie.ID);
                    return(true);
                }
            }
            catch (Exception ex)
            {
                var logg = new LoggTypeDAL()
                {
                    EventType    = "Exception",
                    Created_By   = "System",
                    LogMessage   = ex.ToString(),
                    Created_date = DateTime.Now
                };
                Loggings.LogToBoth(logg);
                return(false);
            }
        }
Example #9
0
        //Summary: Create a movie
        public bool Create(MovieModelBLL movieModelBLL)
        {
            var movieModelDAL = new MovieModelDAL()
            {
                Director   = movieModelBLL.Director,
                Genre      = movieModelBLL.Genre,
                ImdbRating = movieModelBLL.ImdbRating,
                Title      = movieModelBLL.Title,
                Year       = movieModelBLL.Year,
                Rated      = movieModelBLL.Rated,
                Runtime    = movieModelBLL.Runtime,
                Plot       = movieModelBLL.Plot,
                Poster     = movieModelBLL.Poster,
                ScreenShot = movieModelBLL.ScreenShot
            };

            var result = MovieDAL.Create(movieModelDAL);

            return(result);
        }
Example #10
0
        public void Update_WhenMovieNotExists_ExpectedResultFalse()
        {
            //Arrange
            var DALStub = new MovieDALStub(_Seed);

            var input = new MovieModelDAL
            {
                ID         = 4,
                Title      = "MOVIE: the Movie",
                Genre      = "Comedy",
                Director   = "MySelf",
                ImdbRating = 9000,
                Plot       = "This is a movie",
                Rated      = "Insert age here...",
                Year       = 2018
            };

            //Act
            bool test = DALStub.Update(input);

            //Assert
            Assert.IsFalse(test);
        }
Example #11
0
        public void Create_WhenNoExistingMovies_ExpectedResultTrueAreEqual()
        {
            //Arrange
            var DALStub = new MovieDALStub();
            var input   = new MovieModelDAL
            {
                ID         = 4,
                Title      = "MOVIE: the Movie",
                Genre      = "Comedy",
                Director   = "MySelf",
                ImdbRating = 9000,
                Plot       = "This is a movie",
                Rated      = "Insert age here...",
                Year       = 2018
            };

            //Act
            bool test1  = DALStub.Create(input);
            var  result = DALStub.Get(4);

            //Assert
            Assert.IsTrue(test1);
            Assert.AreEqual(input, result);
        }
Example #12
0
 public bool Create(MovieModelDAL movie)
 {
     _MovieDB.Add(movie);
     return(true);
 }