public void CreateMovieWithoutSaveChangesDoesntWork()
        {
            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <MoviesDBContext>()
                          .UseInMemoryDatabase("createmoviedoesntsavechanges_test").Options;

            using (var db = new MoviesDBContext(options))
            {
                db.Genre.Add(new Genre {
                    Name = "a"
                });
                db.SaveChanges();
            }

            // act (for act, only use the repo, to test it)
            using (var db = new MoviesDBContext(options))
            {
                var   repo  = new MovieRepository(db);
                Movie movie = new Movie {
                    Name = "b"
                };
                repo.CreateMovie(movie, "a");
                // not calling repo.SaveChanges
            }

            // assert (for assert, once again use the context directly to verify.)
            using (var db = new MoviesDBContext(options))
            {
                Movie movie = db.Movie.Include(m => m.Genre).FirstOrDefault(m => m.Name == "b");
                Assert.Null(movie);
            }
        }
        public void CreateMovieWorks()
        {
            // arrange (use the context directly - we assume that works)
            var options = new DbContextOptionsBuilder <MoviesDBContext>()
                          .UseInMemoryDatabase("createmovie_test").Options;

            using (var db = new MoviesDBContext(options))
            {
                db.Genre.Add(new Genre {
                    Name = "a"
                });
                db.SaveChanges();
            }

            // act (for act, only use the repo, to test it)
            using (var db = new MoviesDBContext(options))
            {
                var   repo  = new MovieRepository(db);
                Movie movie = new Movie {
                    Name = "b"
                };
                repo.CreateMovie(movie, "a");
                repo.SaveChanges();
            }

            // assert (for assert, once again use the context directly to verify.)
            using (var db = new MoviesDBContext(options))
            {
                Movie movie = db.Movie.Include(m => m.Genre).First(m => m.Name == "b");
                Assert.Equal("b", movie.Name);
                Assert.NotNull(movie.Genre);
                Assert.Equal("a", movie.Genre.Name);
                Assert.NotEqual(0, movie.Id); // should get some generated id
            }
        }
Esempio n. 3
0
        private async Task SaveMovie()
        {
            try
            {
                var movieId = await MovieRepository.CreateMovie(movieItem);

                NavMan.NavigateTo($"movie/{movieId}/{movieItem.Title.Replace(" ", "-")}");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Exception: {ex.Message}");
            }
        }
Esempio n. 4
0
        public IActionResult CreateEvent(NewEventWithInvites NewEvent)
        {
            var newMovie        = _movieRepository.CreateMovie(NewEvent);
            var newCreatedEvent = _eventRepository.CreateEvent(NewEvent, newMovie.MovieId);

            foreach (var userId in NewEvent.InvitedUsers)
            {
                _inviteRepository.CreateInvite(userId, newCreatedEvent.EventId);
                var emailAddress = _userRepository.GetEmail(userId);
                var movieTitle   = _movieRepository.GetMovieTitle(newMovie.MovieId);
                _twilioRepository.Other(emailAddress, movieTitle);
            }
            return(Ok(newCreatedEvent));
        }
Esempio n. 5
0
        public ActionResult Create(Movie model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    _repo.CreateMovie(model);
                }
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                // log
            }

            return(View(model));
        }
        static void AccessWithRepo()
        {
            using (var db = new MoviesDBContext(options))
            {
                IMovieRepository movieRepo = new MovieRepository(db);

                movieRepo.CreateMovie(new Movie {
                    Name = "Harry Potter"
                }, "Action/Adventure");
                movieRepo.SaveChanges();

                foreach (var movie in movieRepo.GetAllMoviesWithGenres())
                {
                    Console.WriteLine(movie.Name);
                }
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> Create([FromBody] Movie entity)
        {
            var movie = await MovieRepository.CreateMovie(entity);

            return(CreatedAtRoute("GetMovie", new { controller = "Movie", id = entity.Id }, entity));
        }