Example #1
0
        public MovieModule(OrmLiteConnectionFactory db)
            : base("/movies")
        {
            Get["/"] = _ =>
            {
                var movies = new MovieController(db);
                return movies.ListAll();
            };

            Get["/{movie}"] = req =>
            {
                var movies = new MovieController(db);
                var movie = movies.Lookup(req.movie);
                if (movie == null)
                    return 404;
                return View["MovieDetail", movie];
            };

            Get["/create"] = _ => { return View["NewMovie"]; };

            Post["/create"] = _ =>
            {
                var movie = this.Bind<Movie>(); // Binds the POST result to movie variable (as a movie object)
                var movieController = new MovieController(db);
                movieController.Add(movie);
                return Response.AsRedirect(ModulePath + "/" + movie.GetPrettyTitleLink());
            };

            Post["/update/{id}"] = _ => { return 500; };
        }
Example #2
0
        public async Task Add_ValidMovie_ReturnsOk()
        {
            Movie movie = new Movie
            {
                MovieId     = 5,
                Name        = "Movie3",
                Description = "Description of film 3",
                Duration    = 120,
                CategoryId  = 1
            };

            movieRepositoryMock.Setup(mr => mr.AddMovie(movie)).ReturnsAsync(5);

            var response = await movieController.Add(movie) as OkObjectResult;

            Assert.Equal(200, response.StatusCode);
        }
Example #3
0
        public async Task Test_Add_Valid_Movie_Should_Be_Ok()
        {
            var movieMock = new Mock <Movie>();

            movieMock.Setup(m => m.Validate()).Returns(new FluentValidation.Results.ValidationResult());

            var fakeId = 1;

            movieServiceMock.Setup(m => m.Add(movieMock.Object)).Returns(Task.FromResult(fakeId));

            var apiResult = await movieController.Add(movieMock.Object);

            apiResult.Should().BeOfType <OkObjectResult>().Which.Value.Should().Be(fakeId);

            movieMock.Verify(m => m.Validate(), Times.Once);
            movieMock.VerifyNoOtherCalls();
            movieServiceMock.Verify(m => m.Add(movieMock.Object), Times.Once);
            movieServiceMock.VerifyNoOtherCalls();
        }
 public static bool MovieAddValidation(string name, double length)
 {
     try
     {
         MovieController.Add(name, length);
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Example #5
0
        public void Add_ReturnsView()
        {
            IMembershipService membershipService = new FakeMembershipService(Enumerable.Empty <MembershipUser>());

            IRepository <Movie> movieRepository = new FakeMovieRepository();
            IRepository <Genre> genreRepository = new FakeGenreRepository();

            var movieController = new MovieController(movieRepository, genreRepository, membershipService);


            var result = movieController.Add() as ViewResult;

            Assert.IsNotNull(result);
        }
Example #6
0
        public void Add_WithValidUserAndModel_CallsSaveOnMovieRepository()
        {
            var  users = new List <MembershipUser>();
            Guid guid  = Guid.NewGuid();

            users.Add(new TestMembershipUser("test", guid));

            IMembershipService membershipService = new FakeMembershipService(users);

            var       movies  = new List <Movie>();
            const int movieId = 42;

            movies.Add(new Movie {
                Id = movieId
            });

            bool   wasCalled  = false;
            Action saveAction = () => wasCalled = true;

            IRepository <Movie> movieRepository = new FakeMovieRepository(movies, saveCallback: saveAction);
            IRepository <Genre> genreRepository = new FakeGenreRepository();
            var movieController = new MovieController(movieRepository, genreRepository, membershipService)
            {
                ControllerContext = new FakeControllerContext()
            };

            var editMovieViewModel = new EditMovieViewModel
            {
                Id        = movieId,
                Directors = "Directors",
                GenreId   = 1,
                Name      = "Name",
                Rating    = 3,
                Stars     = "Stars",
                Writers   = "Writers"
            };

            movieController.Add(editMovieViewModel);

            Assert.IsTrue(wasCalled);
        }
Example #7
0
        public void Add_WithUserNotFound_ReturnsRedirectsToAccountRegister()
        {
            IMembershipService membershipService = new FakeMembershipService(Enumerable.Empty <MembershipUser>());

            var       movies  = new List <Movie>();
            const int movieId = 42;

            movies.Add(new Movie {
                Id = movieId
            });
            IRepository <Movie> movieRepository = new FakeMovieRepository(movies);
            IRepository <Genre> genreRepository = new FakeGenreRepository();
            var movieController = new MovieController(movieRepository, genreRepository, membershipService)
            {
                ControllerContext = new FakeControllerContext()
            };

            var result = (RedirectToRouteResult)movieController.Add(new EditMovieViewModel());

            Assert.IsTrue(string.Compare(result.Action(), "register", true) == 0);
            Assert.IsTrue(string.Compare(result.Controller(), "account", true) == 0);
        }
Example #8
0
        public void Add_WithInvalidModelState_ReturnsView()
        {
            IMembershipService membershipService = new FakeMembershipService(Enumerable.Empty <MembershipUser>());

            var       movies  = new List <Movie>();
            const int movieId = 42;

            movies.Add(new Movie {
                Id = movieId
            });
            IRepository <Movie> movieRepository = new FakeMovieRepository(movies);
            IRepository <Genre> genreRepository = new FakeGenreRepository();
            var movieController = new MovieController(movieRepository, genreRepository, membershipService);


            //setup model error to trigger !IsValid
            movieController.ModelState.AddModelError("key", "errormessage");

            var result = movieController.Add(new EditMovieViewModel()) as ViewResult;

            Assert.IsNotNull(result);
        }
Example #9
0
        public void Add_WithValidUserAndModel_RedirectsToIndex()
        {
            var  users = new List <MembershipUser>();
            Guid guid  = Guid.NewGuid();

            users.Add(new TestMembershipUser("test", guid));

            IMembershipService membershipService = new FakeMembershipService(users);

            var       movies  = new List <Movie>();
            const int movieId = 42;

            movies.Add(new Movie {
                Id = movieId
            });

            IRepository <Movie> movieRepository = new FakeMovieRepository(movies);
            IRepository <Genre> genreRepository = new FakeGenreRepository();
            var movieController = new MovieController(movieRepository, genreRepository, membershipService)
            {
                ControllerContext = new FakeControllerContext()
            };

            var editMovieViewModel = new EditMovieViewModel
            {
                Id        = movieId,
                Directors = "Directors",
                GenreId   = 1,
                Name      = "Name",
                Rating    = 3,
                Stars     = "Stars",
                Writers   = "Writers"
            };

            var result = (RedirectToRouteResult)movieController.Add(editMovieViewModel);

            Assert.IsTrue(string.Compare(result.Action(), "Index", true) == 0);
        }
Example #10
0
        public void Add()    //新增
        {
            var result = controller.Add() as ViewResult;

            Assert.IsNotNull(result);
        }