示例#1
0
        public TicketServiceTest()
        {
            var optionsBuilder = new DbContextOptionsBuilder <ApplicationDbContext>();

            optionsBuilder.UseInMemoryDatabase("TestDb" + Guid.NewGuid());
            applicationDbContext = new ApplicationDbContext(optionsBuilder.Options);

            seatRepository  = new SeatRepository(applicationDbContext);
            orderRepository = new OrderRepository(applicationDbContext);
            movieRepository = new MovieRepository(applicationDbContext);
            snackRepository = new SnackRepository(applicationDbContext);

            seatRepository.Insert(new Seat {
                Status = SeatStatus.Free
            });
            seatRepository.Insert(new Seat {
                Status = SeatStatus.Free
            });
            movieRepository.Insert(new Movie {
                Title = "Test", ScreeningTimes = new List <ScreeningTime> {
                    screeningTime
                }
            });
            snackRepository.Insert(new Snack {
                Name = "SnackTest1"
            });
            snackRepository.Insert(new Snack {
                Name = "SnackTest2"
            });

            applicationDbContext.SaveChanges();

            ticketService = new TicketService(seatRepository, movieRepository, orderRepository, snackRepository);
        }
        public ActionResult Create(SnackCreateVm snackVm)
        {
            if (!ModelState.IsValid)
            {
                return(View(snackVm));
            }

            var snackDb = Mapper.Map <Snack>(snackVm);

            _snackRepo.Insert(snackDb);
            _snackRepo.SaveAll();

            return(RedirectToAction("Index"));
        }
示例#3
0
        public void SnackRepository_Should_Create_Snack()
        {
            // Arrange
            Snack snack = new Snack
            {
                Name = "Bounty",
                GewichtProEinheit = 12.34,
                SnackArtId        = (int)SnackArtEnum.Schokolade
            };

            // Act
            _snackRepo.Insert(snack);
            bool result = _snackRepo.SaveAll();

            // Assert
            Assert.IsTrue(result);
        }