コード例 #1
0
        public PurchaseModule(OrmLiteConnectionFactory db)
            : base("/purchases")
        {
            // Ew. Wouldn't have been necessary if we'd named all of our primary keys Id and used an interface for them -_-
            SetID = (purchase, i) => purchase.PurchaseId = i;

            CreateView = _ =>
            {
                var showings = (new ShowingsController(db)).ListAll();

                ViewBag["Showings"] = showings.Select(showing => new SelectListItem(showing.Time.ToString(), showing.ShowingId.ToString(), false));
                return(View["New" + type, new Purchase()]);
            };

            CreateAction = item =>
            {
                item.PurchaseTime = DateTime.Now;
                var showings = new ShowingsController(db);
                var showing  = showings.Get(item.ShowingId);
                showing.AvailableSeats--;
                showings.Update(showing);
            };

            EditView = item =>
            {
                var showings = (new ShowingsController(db)).ListAll();

                ViewBag["Showings"] = showings.Select(showing => new SelectListItem(showing.Time.ToString(), showing.ShowingId.ToString(), false));
            };
        }
コード例 #2
0
        public void Should_GetShowings()
        {
            // mock UoW and repository data
            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Showings.Get()).Returns(new List <Showing>
            {
                new Showing {
                    Id = 1, RoomId = 1, EventId = 1, PricingStrategyId = 1, StartTime = DateTime.Parse("01-01-2020 12:00"), EndTime = DateTime.Parse("01-01-2020 13:00"), Bookings = new List <Booking>()
                },
                new Showing {
                    Id = 2, RoomId = 2, EventId = 2, PricingStrategyId = 1, StartTime = DateTime.Parse("01-01-2020 14:00"), EndTime = DateTime.Parse("01-01-2020 15:00"), Bookings = new List <Booking>()
                },
                new Showing {
                    Id = 3, RoomId = 2, EventId = 2, PricingStrategyId = 1, StartTime = DateTime.Parse("01-01-2020 15:30"), EndTime = DateTime.Parse("01-01-2020 16:00"), Bookings = new List <Booking>()
                },
                new Showing {
                    Id = 4, RoomId = 3, EventId = 3, PricingStrategyId = 1, StartTime = DateTime.Parse("01-01-2020 17:00"), EndTime = DateTime.Parse("01-01-2020 18:00"), Bookings = new List <Booking>()
                },
                new Showing {
                    Id = 5, RoomId = 3, EventId = 4, PricingStrategyId = 1, StartTime = DateTime.Parse("01-01-2020 19:00"), EndTime = DateTime.Parse("01-01-2020 20:10"), Bookings = new List <Booking>()
                },
            }
                                                      .AsQueryable());

            ShowingsController controller = new ShowingsController(mock.Object);
            var showings = controller.GetShowings();

            Assert.True(showings.Count() == 5);
        }
コード例 #3
0
        public void Should_GetShowing()
        {
            Showing testShowing = new Showing {
                Id = 1, RoomId = 1, EventId = 1, PricingStrategyId = 1, StartTime = DateTime.Parse("01-01-2020 12:00"), EndTime = DateTime.Parse("01-01-2020 13:00"), Bookings = new List <Booking>()
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Showings.GetById(1)).Returns(testShowing);

            ShowingsController controller = new ShowingsController(mock.Object);
            var showing = controller.GetShowing(1);

            Assert.IsType <OkObjectResult>(showing);
        }
コード例 #4
0
        public void ShouldNot_DeleteShowing_NotFound()
        {
            Showing testShowing = new Showing {
                Id = 10
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Showings.GetById(10)).Returns((Showing)null);

            ShowingsController controller = new ShowingsController(mock.Object);
            var result = controller.DeleteShowing(10);

            Assert.IsType <NotFoundResult>(result);
        }
コード例 #5
0
        public void ShouldNot_PutShowing_IdMismatch()
        {
            Showing testShowing = new Showing {
                Id = 1, RoomId = 1, EventId = 1, PricingStrategyId = 1, StartTime = DateTime.Parse("01-01-2020 12:00"), EndTime = DateTime.Parse("01-01-2020 13:00"), Bookings = new List <Booking>()
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Showings.Update(testShowing)).Returns(true);

            ShowingsController controller = new ShowingsController(mock.Object);
            var showings = controller.PutShowing(2, testShowing);

            Assert.IsType <BadRequestResult>(showings);
        }
コード例 #6
0
        public void Should_DeleteShowing()
        {
            Showing testShowing = new Showing {
                Id = 1
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Showings.GetById(1)).Returns(testShowing);
            mock.Setup(f => f.Showings.Delete(testShowing)).Returns(true);

            ShowingsController controller = new ShowingsController(mock.Object);
            var result = controller.DeleteShowing(1);

            Assert.IsType <OkObjectResult>(result);
        }
コード例 #7
0
        public void ShouldNot_DeleteShowing_ModelStateError()
        {
            Showing testShowing = new Showing {
                Id = 1
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Showings.Delete(testShowing)).Returns(true);

            ShowingsController controller = new ShowingsController(mock.Object);

            controller.ModelState.AddModelError("TestError", "Error");
            var result = controller.DeleteShowing(1);

            Assert.IsType <BadRequestObjectResult>(result);
        }
コード例 #8
0
        public void SeatsAvailableGetsSet()
        {
            var showingsController = new ShowingsController(b);
            var theshowing         = new Showing
            {
                Movie        = null,
                Price        = 10,
                ScreenNumber = 10,
                Time         = new DateTime(),
                TotalSeats   = 100
            };

            var showing   = showingsController.Add(theshowing);
            var retrieved = showingsController.Get(showing);

            retrieved.AvailableSeats.ShouldEqual(theshowing.TotalSeats);
        }
コード例 #9
0
        public void SeatsAvailableGetsSet()
        {
            var showingsController = new ShowingsController(b);
            var theshowing = new Showing
            {
                Movie = null,
                Price = 10,
                ScreenNumber = 10,
                Time = new DateTime(),
                TotalSeats = 100
            };

            var showing = showingsController.Add(theshowing);
            var retrieved = showingsController.Get(showing);

            retrieved.AvailableSeats.ShouldEqual(theshowing.TotalSeats);
        }
コード例 #10
0
        public void ShouldNot_PostShowing_ModelStateError()
        {
            Showing testShowing = new Showing {
                Id = 1, RoomId = 1, EventId = 1, PricingStrategyId = 1, StartTime = DateTime.Parse("01-01-2020 12:00"), EndTime = DateTime.Parse("01-01-2020 13:00"), Bookings = new List <Booking>()
            };

            Mock <IUnitOfWork> mock = new Mock <IUnitOfWork>();

            mock.Setup(f => f.Showings.Create(testShowing)).Returns(true);
            mock.Setup(f => f.Showings.GetById(1)).Returns(testShowing);

            ShowingsController controller = new ShowingsController(mock.Object);

            controller.ModelState.AddModelError("TestError", "Error");
            var showings = controller.PostShowing(testShowing);

            Assert.IsType <BadRequestObjectResult>(showings);
        }
コード例 #11
0
        public void ShowingCanBeLookedUp()
        {
            var showingsController = new ShowingsController(b);
            var theshowing         = new Showing
            {
                Movie        = null,
                Price        = 10,
                ScreenNumber = 10,
                Time         = new DateTime(),
                TotalSeats   = 100
            };

            int showing   = showingsController.Add(theshowing);
            var retrieved = showingsController.Get(showing);

            retrieved.MovieId.ShouldEqual(theshowing.MovieId);
            retrieved.Price.ShouldEqual(theshowing.Price);
            retrieved.ScreenNumber.ShouldEqual(theshowing.ScreenNumber);
            retrieved.Time.ShouldEqual(theshowing.Time);
            retrieved.TotalSeats.ShouldEqual(theshowing.TotalSeats);
        }
コード例 #12
0
        public void ShowingCanBeLookedUp()
        {
            var showingsController = new ShowingsController(b);
            var theshowing = new Showing
            {
                Movie = null,
                Price = 10,
                ScreenNumber = 10,
                Time = new DateTime(),
                TotalSeats = 100
            };

            int showing = showingsController.Add(theshowing);
            var retrieved = showingsController.Get(showing);

            retrieved.MovieId.ShouldEqual(theshowing.MovieId);
            retrieved.Price.ShouldEqual(theshowing.Price);
            retrieved.ScreenNumber.ShouldEqual(theshowing.ScreenNumber);
            retrieved.Time.ShouldEqual(theshowing.Time);
            retrieved.TotalSeats.ShouldEqual(theshowing.TotalSeats);
        }
コード例 #13
0
        public ShowingsModule(OrmLiteConnectionFactory db)
            : base("/showings")
        {
            Get["/"] = _ =>
            {
                var showings = new ShowingsController(db);
                return View["ShowingList", showings.ListAll()];
            };

            Get["/{showing}"] = req =>
            {
                var showings = new ShowingsController(db);
                var showing = showings.Get(req.showing);
                if (showing == null)
                    return 404;
                return View["ShowingDetail", showing];
            };

            Get["/create"] = _ =>
            {
                var movieController = new MovieController(db);
                var movies = movieController.ListAll().Movies;
                var selectlist = movies.Select(movie => new SelectListItem(movie.Title, movie.MovieId.ToString(), false)).ToList();
                return View["NewShowing", selectlist];
            };

            Post["/create"] = _ =>
            {
                var showing = this.Bind<Showing>();
                LogTo.Debug("Adding showing: {0}", showing);
                var showingsController = new ShowingsController(db);
                var showingId = showingsController.Add(showing);
                return Response.AsRedirect(ModulePath + "/" + showingId);
            };

            Post["/update/{id}"] = _ => { return 500; };
        }
コード例 #14
0
 public void CreateMockedController()
 {
     _showingContext     = new MockShowingContext();
     _filmContext        = new MockFilmContext();
     _showingsController = new ShowingsController(new ShowingService(_showingContext, _filmContext));
 }
コード例 #15
0
        public ShowingModule(OrmLiteConnectionFactory db)
            : base("/showings")
        {
            Get["/"] = _ =>
            {
                var showings = new ShowingsController(db);
                return View["ShowingList", showings.ListAll()];
            };

            Get["/{showing}"] = req =>
            {
                var showings = new ShowingsController(db);
                var showing = showings.Get(req.showing);
                if (showing == null)
                    return 404;
                return View["ShowingDetail", showing];
            };

            Get["/create"] = _ =>
            {
                var movieController = new MovieController(db);
                ViewBag["Movies"] = movieController.ListAll().GetSelectList();
                return View["NewShowing", new Showing()];
            };

            Post["/create"] = _ =>
            {
                var showing = this.Bind<Showing>();
                LogTo.Debug("Adding showing: {0}", showing);
                var showingsController = new ShowingsController(db);
                var showingId = showingsController.Add(showing);
                return Response.AsRedirect(ModulePath + "/" + showingId);
            };

            Get["{showing}/edit"] = req =>
            {
                // Look up the showing with given ID
                var showings = new ShowingsController(db);
                var showing = showings.Get(req.showing);
                if (showing == null)
                    return 404;

                // Tell the view where to POST to
                ViewBag["action"] = ModulePath + $"/{req.showing}/edit";

                // Do usual showing view stuff (see the create view) - it would be great if we could consolodate the the two into one function
                var movieController = new MovieController(db);
                ViewBag["Movies"] = movieController.ListAll().GetSelectList();
                return View["NewShowing", showing];
            };

            Post["{showing}/edit"] = req =>
            {
                int showingID;
                if (!int.TryParse(req.showing, out showingID))
                    return 404; // User tried to edit a showing with an invalid (non-numeric) ID

                var editedShowing = this.Bind<Showing>();
                var showings = new ShowingsController(db);
                var oldshowing = showings.Get(showingID);
                if(oldshowing == null)
                    return 404; // User tried to edit a nonexistent showing

                var filledSeats = oldshowing.TotalSeats - oldshowing.AvailableSeats;
                editedShowing.AvailableSeats = editedShowing.TotalSeats - filledSeats;

                //if(editedShowing.AvailableSeats < 0)
                //  return "Error: negative seats available"; // is this really an error condition? Maybe they're okay with making an overbooked show..

                editedShowing.ShowingId = showingID;
                showings.Update(editedShowing);
                return Response.AsRedirect(ModulePath + "/" + showingID);
            };

            Post["{showing}/delete"] = req =>
            {
                // Again, this code duplication is pretty nasty
                int showingID;
                if (!int.TryParse(req.showing, out showingID))
                    return 500; // User tried to edit a showing with an invalid (non-numeric) ID

                var showings = new ShowingsController(db);
                if (showings.Get(showingID) == null)
                    return 404; // User tried to edit a nonexistent showing

                showings.Delete(showingID);
                return Response.AsRedirect(ModulePath + "/");
            };
        }
コード例 #16
0
        public ShowingModule(OrmLiteConnectionFactory db)
            : base("/showings")
        {
            Get["/"] = _ =>
            {
                var showings = new ShowingsController(db);
                return(View["ShowingList", showings.ListAll()]);
            };

            Get["/{showing}"] = req =>
            {
                var showings = new ShowingsController(db);
                var showing  = showings.Get(req.showing);
                if (showing == null)
                {
                    return(404);
                }
                return(View["ShowingDetail", showing]);
            };

            Get["/create"] = _ =>
            {
                var movieController = new MovieController(db);
                ViewBag["Movies"] = movieController.ListAll().GetSelectList();
                return(View["NewShowing", new Showing()]);
            };

            Post["/create"] = _ =>
            {
                var showing = this.Bind <Showing>();
                LogTo.Debug("Adding showing: {0}", showing);
                var showingsController = new ShowingsController(db);
                var showingId          = showingsController.Add(showing);
                return(Response.AsRedirect(ModulePath + "/" + showingId));
            };

            Get["{showing}/edit"] = req =>
            {
                // Look up the showing with given ID
                var showings = new ShowingsController(db);
                var showing  = showings.Get(req.showing);
                if (showing == null)
                {
                    return(404);
                }

                // Tell the view where to POST to
                ViewBag["action"] = ModulePath + $"/{req.showing}/edit";

                // Do usual showing view stuff (see the create view) - it would be great if we could consolodate the the two into one function
                var movieController = new MovieController(db);
                ViewBag["Movies"] = movieController.ListAll().GetSelectList();
                return(View["NewShowing", showing]);
            };

            Post["{showing}/edit"] = req =>
            {
                int showingID;
                if (!int.TryParse(req.showing, out showingID))
                {
                    return(404); // User tried to edit a showing with an invalid (non-numeric) ID
                }
                var editedShowing = this.Bind <Showing>();
                var showings      = new ShowingsController(db);
                var oldshowing    = showings.Get(showingID);
                if (oldshowing == null)
                {
                    return(404); // User tried to edit a nonexistent showing
                }
                var filledSeats = oldshowing.TotalSeats - oldshowing.AvailableSeats;
                editedShowing.AvailableSeats = editedShowing.TotalSeats - filledSeats;

                //if(editedShowing.AvailableSeats < 0)
                //  return "Error: negative seats available"; // is this really an error condition? Maybe they're okay with making an overbooked show..

                editedShowing.ShowingId = showingID;
                showings.Update(editedShowing);
                return(Response.AsRedirect(ModulePath + "/" + showingID));
            };

            Post["{showing}/delete"] = req =>
            {
                // Again, this code duplication is pretty nasty
                int showingID;
                if (!int.TryParse(req.showing, out showingID))
                {
                    return(500); // User tried to edit a showing with an invalid (non-numeric) ID
                }
                var showings = new ShowingsController(db);
                if (showings.Get(showingID) == null)
                {
                    return(404); // User tried to edit a nonexistent showing
                }
                showings.Delete(showingID);
                return(Response.AsRedirect(ModulePath + "/"));
            };
        }