public void add_movie_view()
        {
            //Arrange
            var controller = new MovieController(new MovieBLL(new MovieRepositoryStub()));
            //Act
            var result = (ViewResult)controller.AddMovie();

            //Assert
            Assert.AreEqual(result.ViewName, "");
        }
예제 #2
0
        public void AddMovie()
        {
            Movie movieDetails = new Movie();

            movieDetails.Name = "KGF";
            MockDALLayer dllLayer   = new MockDALLayer();
            var          controller = new MovieController(dllLayer);

            controller.AddMovie(movieDetails);
            DataTable result = controller.GetMovieDetails(movieDetails.Name);

            Assert.IsTrue(result.Rows.Count == 1);
        }
        public void add_movie_POST_Fail()
        {
            //Arrange
            var controller = new MovieController(new MovieBLL(new MovieRepositoryStub()));
            var newMovie   = new Movie();

            newMovie.Title = "";

            //Act
            var result = (ViewResult)controller.AddMovie(newMovie);

            //Assert
            Assert.AreEqual(result.ViewName, "");
        }
        public void add_movie_Validation_Fail()
        {
            //Arrange
            var controller = new MovieController(new MovieBLL(new MovieRepositoryStub()));
            var newMovie   = new Movie();

            controller.ViewData.ModelState.AddModelError("Title", "Title field is empty");

            //Act
            var result = (ViewResult)controller.AddMovie(newMovie);

            //Assert
            Assert.IsTrue(result.ViewData.ModelState.Count == 1);
            Assert.AreEqual(result.ViewName, "");
        }
예제 #5
0
        public async void AddsMovie()
        {
            var context    = InMemoryDbContextFactory.GetDbContext();
            var controller = new MovieController(context);

            var movie = new Movie {
                Title = "Testing Movie1"
            };

            var response = await controller.AddMovie(movie);

            Assert.IsType <OkObjectResult>(response.Result);
            var okRes = (OkObjectResult)response.Result;

            Assert.Equal("Testing Movie1", ((Movie)okRes.Value).Title);
        }
예제 #6
0
        public void AddMovieShouldThrow_WhenCalledWithInvalidParameters()
        {
            // Arrange
            var mockMovieService = new Mock <IMovieService>();
            var mockRoleService  = new Mock <IRoleService>();
            var mockMapper       = new Mock <IMapper>();
            var mockFactory      = new Mock <IMovieModelFactory>();

            var controller = new MovieController(mockMovieService.Object,
                                                 mockRoleService.Object, mockMapper.Object, mockFactory.Object);

            mockMovieService.Setup(x => x.AddMovie(It.IsAny <MovieModel>()))
            .Verifiable();

            //Act & Assert
            Assert.ThrowsException <ArgumentException>(() => controller.AddMovie("", "nice movie", 1992, 120));
        }
예제 #7
0
        public void AddMovieSuccessfullyInvokeService_WhenCalledWithValidData()
        {
            // Arrange
            var mockMovieService = new Mock <IMovieService>();
            var mockRoleService  = new Mock <IRoleService>();
            var mockMapper       = new Mock <IMapper>();
            var mockFactory      = new Mock <IMovieModelFactory>();

            var controller = new MovieController(mockMovieService.Object,
                                                 mockRoleService.Object, mockMapper.Object, mockFactory.Object);

            // Act
            controller.AddMovie("TestTitle", "nice movie", 1992, 120);

            //Assert
            mockMovieService.Verify(x => x.AddMovie(It.IsAny <MovieModel>()), Times.Once);
        }
        protected void createbtn_Click(object sender, EventArgs e)
        {
            idtxt.Enabled = false;
            Movie addmovie = new Movie();


            addmovie.Name        = nametxt.Text;
            addmovie.Description = descptxt.Text;
            addmovie.Rating      = ratingtxt.Text;
            addmovie.ContentURL  = urltxt.Text;
            addmovie.Duration    = Convert.ToInt32(durationtxt.Text);
            addmovie.Price       = Convert.ToDouble(pricetxt.Text);

            movie_controller.AddMovie(addmovie);

            statuslbl.Text = "New record created successfully";
            idtxt.Enabled  = true;
        }
예제 #9
0
        public static async Task AddMovieAsync(Movie movie)
        {
            using (MultipartFormDataContent content = new MultipartFormDataContent("---------------" + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds))
            {
                content.Add(new StringContent(movie.Title), "Title");
                content.Add(new StringContent(movie.Description), "Description");
                content.Add(new StringContent(movie.Director), "Director");
                content.Add(new StringContent(movie.Year.ToString()), "Year");
                content.Add(new StringContent(movie.Price.ToString()), "Price");
                content.Add(new StreamContent(new MemoryStream(ImageUtility.BitmapImageToByteArray(movie.Poster.Image, movie.Poster.Format))), "Poster", movie.Poster.FileName);

                using (HttpResponseMessage response = await MovieController.AddMovie(content))
                {
                    int    status = (int)response.StatusCode;
                    string body   = await response.Content.ReadAsStringAsync();

                    if (status == 200)
                    {
                        return;
                    }
                    else if (status == 400)
                    {
                        throw new Exception(body);
                    }
                    else if (status == 401)
                    {
                        throw new UnauthenticatedException();
                    }
                    else if (status == 403)
                    {
                        throw new UnauthorizedException();
                    }
                    else if (status == 500)
                    {
                        throw new ServerException();
                    }
                    else
                    {
                        throw new Exception("An uncaught error occurred.");
                    }
                }
            }
        }
예제 #10
0
        private void AddMovie()
        {
            this.AddCmdCommand();
            Movie movie = new Movie();

            movie.Name = movieController.MovieRead();
            Console.WriteLine("Enter actors:");
            movie.Actors = movieController.ActorsRead();
            Console.WriteLine("Enter director:");
            movie.Director    = movieController.DirectorRead();
            movie.Description = movieController.DescriptionRead();
            movie.Genre       = genreController.GenreRead();
            var userName = username;
            var user     = userController.GetUser(userName);

            movie.UserId    = user.Id;
            movie.MovieTags = new List <MovieTag>();
            movieController.AddMovie(movie);
            this.ReturnToMainScreen();
        }
        public void add_movie_OK()
        {
            //Arrange
            var controller = new MovieController(new MovieBLL(new MovieRepositoryStub()));
            var newMovie   = new Movie()
            {
                Id           = 1,
                ImageAddress = "imageaddress.jpg",
                Title        = "Title",
                Description  = "Blockbaster Nr.1",
                Price        = 150,
                Genre        = "Fantasy",
            };

            //Act
            var result = (RedirectToRouteResult)controller.AddMovie(newMovie);

            //Assert
            Assert.AreEqual(result.RouteName, "");
            Assert.AreEqual(result.RouteValues.Values.First(), "ListMovies");
        }
예제 #12
0
        public void Start()
        {
            Boolean active = true;

            while (active)
            {
                Console.WriteLine("*******************************************");
                Console.WriteLine("Hello and welcome to Buutti Movie Database!");
                Console.WriteLine("Please insert your command (type \"help\" for the list of available commands)");
                string input = Console.ReadLine();

                switch (input)
                {
                case "help":
                    PrintHelp();
                    break;

                case "quit":
                    Console.WriteLine("Quitting application");
                    active = false;
                    break;

                case "search":
                    Search();
                    break;

                case "add":
                    AddDialog();
                    break;

                case "remove":
                    RemoveDialog();
                    break;

                case "print":
                    printDetails();
                    break;

                case "dummies":
                    controller.AddDummyMovies();
                    break;

                default:
                    Console.WriteLine("Unknown command, please try again\n");
                    break;
                }
            }

            void PrintHelp()
            {
                Console.WriteLine("\nHere’s a list of commands you can use!\n");
                Console.WriteLine("help\tOpen this dialog.");
                Console.WriteLine("quit\tQuit the program.\n");
                Console.WriteLine("search\tList movies by search term.");
                Console.WriteLine("add\tAdd a new movie to the database.");
                Console.WriteLine("remove\tRemove a movie from the database.");

                //extras
                Console.WriteLine("print\tPrint a list of the movies in the database");
                Console.WriteLine("dummies\tAdd a selection of 2020s best movies to the database.");
            }

            void Search()
            {
                Console.WriteLine("Enter your search term:");
                string       input        = Console.ReadLine();
                List <Movie> filteredList = controller.GetFilteredMovies(input);

                switch (filteredList.Count)
                {
                case (0):
                    Console.WriteLine($"No movies found with search term '{input}' :(");
                    break;

                case (1):
                    Console.WriteLine($"Found 1 movie with search term '{input}':");
                    break;

                default:
                    Console.WriteLine($"Found {filteredList.Count} movies with search term '{input}':");
                    break;
                }

                foreach (Movie m in filteredList)
                {
                    Console.WriteLine(m.Id + " " + m.Name + ", length: " + m.Length + "m");
                }
                Console.WriteLine();
            }

            void AddDialog()
            {
                try
                {
                    Console.WriteLine("\nAdding a movie");
                    Console.WriteLine("Please enter the details for the movie!");

                    Console.WriteLine("Name:");
                    string name = Console.ReadLine();
                    Console.WriteLine("Description:");
                    string desc = Console.ReadLine();
                    Console.WriteLine("Length:");
                    int length = Int32.Parse(Console.ReadLine());

                    controller.AddMovie(name, desc, length);
                    Console.WriteLine($"Movie {name} added!\n");
                }
                catch
                {
                    Console.WriteLine("Invalid input: Give length in minutes.");
                    Console.WriteLine("Movie not added. Please try again. \n");
                }
            }

            void printDetails()
            {
                List <Movie> allMovies = controller.GetMovies();

                if (allMovies.Count == 0)
                {
                    Console.WriteLine("No movies in the database. Please add a movie.");
                }

                foreach (Movie m in allMovies)
                {
                    Console.WriteLine(m.Id + " " + m.Name + ", length: " + m.Length + "m");
                }

                Console.WriteLine("");
            }

            void RemoveDialog()
            {
                try
                {
                    Console.WriteLine("Removing a movie.");
                    Console.WriteLine("Please enter the ID of the movie you want to remove:");
                    int id = Int32.Parse(Console.ReadLine());

                    Console.WriteLine($"Removing movie {controller.GetMovies()[id].Name}. Are you sure (y/n)?");
                    string conf = Console.ReadLine();
                    switch (conf)
                    {
                    case "y":
                        controller.RemoveMovie(id);
                        Console.WriteLine("Movie removed from the database.\n");
                        break;

                    case "n":
                        Console.WriteLine("Cancelling removal.\n");
                        break;

                    default:
                        Console.WriteLine("Unknown command. Please use \"y\" or \"n\"");
                        break;
                    }
                }
                catch (Exception e)
                {
                    switch (e.GetType().Name)
                    {
                    case "FormatException":
                        Console.WriteLine("Wrong input format. Please provide an id number. Type \"print\" for list of movies and ids\n");
                        break;

                    case "ArgumentOutOfRangeException":
                        Console.WriteLine("Invalid id number. Type \"print\" for list of movies and ids\n");
                        break;
                    }
                }
            }
        }
예제 #13
0
 private void saveButton_MouseClick(object sender, MouseEventArgs e)
 {
     if (string.IsNullOrEmpty(titleValueLabel.Text.Trim()))
     {
         SystemSounds.Beep.Play();
         CustomMessageBox.Show(@"Title is empty.");
     }
     else if (string.IsNullOrEmpty(directorValueLabel.Text.Trim()))
     {
         SystemSounds.Beep.Play();
         CustomMessageBox.Show(@"Directors is empty.");
     }
     else if (string.IsNullOrEmpty(writerValueLabel.Text.Trim()))
     {
         SystemSounds.Beep.Play();
         CustomMessageBox.Show(@"Writers is empty.");
     }
     else if (string.IsNullOrEmpty(starsValueLabel.Text.Trim()))
     {
         SystemSounds.Beep.Play();
         CustomMessageBox.Show(@"Stars is empty.");
     }
     else if (string.IsNullOrEmpty(descriptionValueLabel.Text.Trim()))
     {
         SystemSounds.Beep.Play();
         CustomMessageBox.Show(@"Description is empty.");
     }
     else if (_movie.Picture == null && _isNew)
     {
         SystemSounds.Beep.Play();
         CustomMessageBox.Show(@"Photo is empty.");
     }
     else if (_isUploaded)
     {
         if (_isNew)
         {
             MovieController.AddMovie(
                 titleValueLabel.Text,
                 descriptionValueLabel.Text,
                 directorValueLabel.Text,
                 writerValueLabel.Text,
                 starsValueLabel.Text,
                 _movie.Picture,
                 genreValue.SelectedIndex + 1,
                 dateValue.Value.ToString("yyyy-MM-dd")
                 );
         }
         else
         {
             MovieController.UpdateMovie(
                 _movie.Id,
                 titleValueLabel.Text,
                 descriptionValueLabel.Text,
                 directorValueLabel.Text,
                 writerValueLabel.Text,
                 starsValueLabel.Text,
                 _movie.Picture,
                 genreValue.SelectedIndex + 1,
                 dateValue.Value.ToString("yyyy-MM-dd")
                 );
         }
         Program.MainForm.UserControlSelector(new MainPageUserControl(), true);
     }
     else
     {
         SystemSounds.Beep.Play();
         CustomMessageBox.Show(@"Photo is still uploading...");
     }
 }