public void Run(MovieOriginal currentMovie, MovieCopy currentMovieCopy) { _leasingView.CurrentMovie = currentMovie; _leasingView.CurrentMovieCopy = currentMovieCopy; _leasingView.RedrawCustomers(_context.Customers); _leasingView.Show(); }
public void AddMovie(MovieOriginal movie) { if (!_movieView.ConfirmNewMovie()) { return; } _context.MoviesOriginal.Add(movie); _context.SaveChanges(); _movieView.Close(); }
public void UpdateMovie(int movieId, MovieOriginal updatedMovie) { var movie = _context.MoviesOriginal.Single(m => m.Id == movieId); movie.Description = updatedMovie.Description; movie.Title = updatedMovie.Title; movie.YearReleased = updatedMovie.YearReleased; _context.SaveChanges(); _mainView.RedrawMovies(_context.MoviesOriginal); }
public void ExtractMoviesFromFile(string path) { MoviesList.Clear(); var abort = false; if (path.Trim() == "") { return; } using var reader = new StreamReader(path); while (!reader.EndOfStream && !abort) { var line = reader.ReadLine(); if (line == null) { continue; } var movies = line.Split(';'); foreach (var movie in movies) { if (movie == "") { continue; } var movieValues = movie.Split(",,"); try { var title = movieValues[0]; var description = movieValues[1]; var yearReleased = Convert.ToInt32(movieValues[2]); var newMovie = new MovieOriginal(title, description, yearReleased); MoviesList.Add(newMovie); } catch { if (_importMoviesView.SkipWronglyDeclaredMovie(movieValues)) { continue; } abort = true; break; } } } if (abort) { MoviesList.Clear(); } }
public MovieForm() { InitializeComponent(); movieButton.Click += (sender, args) => { var title = movieTitleTextBox.Text.Trim(); var description = movieDescriptionTextBox.Text.Trim(); var yearReleased = Convert.ToInt32(yearReleasedNumericUpDown.Value); var movie = new MovieOriginal(title, description, yearReleased); OnAddMovie?.Invoke(movie); }; }
public void MovieAdd_NotConfirmed() { //arrange _view.ConfirmNewMovie().Returns(false); // юзер отказывается "Добавить новый фильм" var testMovie = new MovieOriginal("TEST", "TEST", 9999); //act _presenter.AddMovie(testMovie); //assert Assert.AreEqual(false, _context.MoviesOriginal.Any()); _view.DidNotReceive().Close(); }
public void Run() { //arrange var testMovie = new MovieOriginal("TEST", "TEST", 9999); //act _presenter.Run(testMovie); //asert Assert.AreEqual(testMovie.Title, _view.CurrentMovie.Title); Assert.AreEqual(testMovie.Description, _view.CurrentMovie.Description); Assert.AreEqual(testMovie.YearReleased, _view.CurrentMovie.YearReleased); _view.Received().Show(); }
public void UploadMovies_NotConfirmed() { //arrange _view.ConfirmUploadMovies().Returns(false); // юзер отказывается добавлять новые фильмы var testMovie = new MovieOriginal("TEST TITLE", "TEST DESCR", 9999); _presenter.MoviesList.Add(testMovie); //act _presenter.UploadMovies(); //assert Assert.AreEqual(false, _context.MoviesOriginal.Any()); _view.DidNotReceive().Close(); }
public void UploadMovies_Confirmed() { //arrange _view.ConfirmUploadMovies().Returns(true); // юзер соглашается добавлять новые фильмы var expectedMovie = new MovieOriginal("TEST TITLE", "TEST DESCR", 9999); _presenter.MoviesList.Add(expectedMovie); // добавляю фильм чтобы был хотя бы один в MoviesList (для цикла foreach) //act _presenter.UploadMovies(); //assert Assert.AreSame(expectedMovie, _context.MoviesOriginal.Single()); _view.Received().Close(); }
public void OpenMovieCopy() { //arrange var testMovie = new MovieOriginal("TEST", "TEST", 9999); _context.MoviesOriginal.Add(testMovie); _context.MoviesCopies.Add(new MovieCopy(9999, "TEST", 9999)); _context.SaveChanges(); //act _presenter.OpenMovieCopy(testMovie.Id); //assert _movieCopyPresenter.Received().Run(Arg.Any <MovieOriginal>()); _view.Received().RedrawCopies(Arg.Any <IQueryable <MovieCopy> >()); }
public void UpdateMovie() { //arrange var initialMovie = new MovieOriginal("Старое имя :(", "Старое описание :(", 8888); _context.MoviesOriginal.Add(initialMovie); _context.SaveChanges(); var updatedMovie = new MovieOriginal("НОВОЕ ИМЯ", "НОВОЕ ОПИСАНИЕ!!!", 9999); //act _presenter.UpdateMovie(initialMovie.Id, updatedMovie); //assert Assert.AreEqual(updatedMovie.Title, initialMovie.Title); Assert.AreEqual(updatedMovie.Description, initialMovie.Description); Assert.AreEqual(updatedMovie.YearReleased, initialMovie.YearReleased); _view.Received().RedrawMovies(Arg.Any <IQueryable <MovieOriginal> >()); }
public void Run() { //arrange // добавляем и сразу же сохраняем по цепочке чтобы последующие элементы получили актуальное значение необходимого Id var testMovie = new MovieOriginal("TEST TITLE", "TEST DESCR", 9999); _context.MoviesOriginal.Add(testMovie); _context.SaveChanges(); var testMovieCopy = new MovieCopy(testMovie.Id, "TEST COMMENT", 9999); _context.MoviesCopies.Add(testMovieCopy); _context.SaveChanges(); var testCustomer = new Customer("TEST NAME"); _context.Customers.Add(testCustomer); _context.SaveChanges(); var testLeasing = new Leasing(DateTime.Now, DateTime.Now, testCustomer.Id, testMovieCopy.Id, 9999); _context.LeasedCopies.Add(testLeasing); _context.SaveChanges(); //act _presenter.Run(testLeasing.Id); //assert Assert.AreEqual(testLeasing.StartDate, _view.CurrentLeasing.StartDate); Assert.AreEqual(testLeasing.ExpectedEndDate, _view.CurrentLeasing.ExpectedEndDate); Assert.AreEqual(testLeasing.CustomerId, _view.CurrentLeasing.CustomerId); Assert.AreEqual(testLeasing.MovieCopyId, _view.CurrentLeasing.MovieCopyId); Assert.AreEqual(testLeasing.TotalPrice, _view.CurrentLeasing.TotalPrice); Assert.AreEqual(testMovieCopy.MovieId, _view.CurrentMovieCopy.MovieId); Assert.AreEqual(testMovieCopy.Commentary, _view.CurrentMovieCopy.Commentary); Assert.AreEqual(testMovieCopy.PricePerDay, _view.CurrentMovieCopy.PricePerDay); Assert.AreEqual(testMovie.Title, _view.CurrentMovie.Title); Assert.AreEqual(testMovie.Description, _view.CurrentMovie.Description); Assert.AreEqual(testMovie.YearReleased, _view.CurrentMovie.YearReleased); Assert.AreEqual(testCustomer.Name, _view.CurrentCustomer.Name); _view.Received().Show(); }
public MainForm() { InitializeComponent(); Load += (sender, args) => OnLoad?.Invoke(); newMovieButton.Click += (sender, args) => OnOpenMovie?.Invoke(); // Добавить новый фильм newMovieCopyButton.Click += (sender, args) => OnOpenMovieCopy?.Invoke(CurrentMovieId); // Добавить новую копию фильма mainMenu.Items[1].Click += (sender, args) => OnOpenCustomers?.Invoke(); // "Клиенты" mainMenu.Items[2].Click += (sender, args) => OnOpenImportMovies?.Invoke(); // "Импорт фильмов" copiesContextMenu.Items[0].Click += (sender, args) => OnOpenLeasing?.Invoke(Convert.ToInt32(copiesDgv.CurrentRow.Cells["Id"].Value)); // "Прокат" leasingContextMenu.Items[0].Click += (sender, args) => OnOpenReturn?.Invoke(Convert.ToInt32(leasingsDgv.CurrentRow.Cells["Id"].Value)); // "Вернуть" mainMenu.Items[0].TextChanged += (sender, args) => OnFilterMovies?.Invoke(mainMenu.Items[0].Text.Trim()); // Поиск фильма moviesDgv.CellEndEdit += (sender, args) => { var movieId = CurrentMovieId; var title = moviesDgv.CurrentRow.Cells["Title"].Value.ToString(); var description = moviesDgv.CurrentRow.Cells["Description"].Value.ToString(); var yearReleased = Convert.ToInt32(moviesDgv.CurrentRow.Cells["YearReleased"].Value); var updatedMovie = new MovieOriginal(title, description, yearReleased); OnUpdateMovie?.Invoke(movieId, updatedMovie); }; copiesDgv.CellEndEdit += (sender, args) => { var movieCopyId = Convert.ToInt32(copiesDgv.CurrentRow.Cells["Id"].Value); var commentary = copiesDgv.CurrentRow.Cells["Commentary"].Value.ToString(); var pricePerDay = Convert.ToInt32(copiesDgv.CurrentRow.Cells["PricePerDay"].Value); var updatedMovieCopy = new MovieCopy(Convert.ToInt32(moviesDgv.CurrentRow.Cells["Id"].Value), commentary, pricePerDay); OnUpdateMovieCopy?.Invoke(movieCopyId, updatedMovieCopy); }; moviesDgv.DataError += (sender, args) => ShowDataError(); copiesDgv.DataError += (sender, args) => ShowDataError(); moviesDgv.SelectionChanged += (sender, args) => OnMovieSelectionChanged?.Invoke(CurrentMovieId); copiesDgv.SelectionChanged += (sender, args) => OnMovieCopySelectionChanged?.Invoke(Convert.ToInt32(copiesDgv.CurrentRow.Cells["Id"].Value)); }
public void OpenLeasing() { //arrange var testMovie = new MovieOriginal("TEST", "TEST", 9999); _context.MoviesOriginal.Add(testMovie); _context.SaveChanges(); // нужно чтобы testMovieCopy получил актуальный testMovie.Id после добавления в контекст. Иначе testMovie.Id будет 0 var testMovieCopy = new MovieCopy(testMovie.Id, "TEST", 9999); _context.MoviesCopies.Add(testMovieCopy); _context.SaveChanges(); //act _presenter.OpenLeasing(testMovieCopy.Id); //assert _leasingPresenter.Received().Run(Arg.Any <MovieOriginal>(), Arg.Any <MovieCopy>()); _view.Received().RedrawCopies(Arg.Any <IQueryable <MovieCopy> >()); _view.Received().RedrawLeasings(Arg.Any <IQueryable <Leasing> >(), Arg.Any <IQueryable <Customer> >()); }
public void Run() { //arrange var movieTest = new MovieOriginal("TEST MOVIE", "TEST MOVIE DESCR", 9999); var movieCopyTest = new MovieCopy(1111, "TEST COMMENT", 1111); //act _presenter.Run(movieTest, movieCopyTest); //assert Assert.AreEqual(movieTest.Title, _view.CurrentMovie.Title); Assert.AreEqual(movieTest.Description, _view.CurrentMovie.Description); Assert.AreEqual(movieTest.YearReleased, _view.CurrentMovie.YearReleased); Assert.AreEqual(movieCopyTest.MovieId, _view.CurrentMovieCopy.MovieId); Assert.AreEqual(movieCopyTest.Commentary, _view.CurrentMovieCopy.Commentary); Assert.AreEqual(movieCopyTest.PricePerDay, _view.CurrentMovieCopy.PricePerDay); _view.Received().RedrawCustomers(Arg.Any <IQueryable <Customer> >()); _view.Received().Show(); }
public void Run(MovieOriginal movie) { _movieCopyView.CurrentMovie = movie; _movieCopyView.Show(); }