Exemple #1
0
        public void UPDATE_ShouldReturnNewLastName()
        {
            //Arrange
            var x        = 1;
            var employee = new Employee {
                EmployeeId = x, FirstName = "Pablo", LastName = "Almonte", Age = 18
            };

            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "UPDATE_ShouldReturnNewName")
                          .Options;

            var context = new CinemaDbContext(options);

            SeedEmployees(context);

            var service = new EmployeeService(context);

            //Act
            var result = service.Update(x, employee);


            //Assert
            Assert.Equal(result.LastName, employee.LastName);
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CinemaDbContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseSwagger();
                app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "CinemaApi v1"));
            }

            app.UseStaticFiles();

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();

            app.UseAuthorization();
            //dbContext.Database.EnsureCreated();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Exemple #3
0
        private static void CancelReservationsTime()
        {
            DateTime now         = DateTime.UtcNow.AddMinutes(ActionConstants.MinutesToProjection);
            var      logFileName = "CanceledReservationsLog.txt";
            string   destPath    = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, logFileName);

            using (CinemaDbContext db = new CinemaDbContext())
            {
                var activeReservations = db.Reservations.Where(t => t.Canceled == false).ToArray();
                foreach (var reservation in activeReservations)
                {
                    var startDate = db.Projections.FirstOrDefault(s => s.Id == reservation.ProjectionId);

                    if (startDate.StartDate <= now)
                    {
                        reservation.Canceled = true;
                        string cancelledReservation =
                            $"Cancellation Time: {now.AddMinutes(-10)} Projection Id: {reservation.ProjectionId} Reservation Id: {reservation.Id}" + Environment.NewLine;
                        File.AppendAllText(destPath, cancelledReservation);
                        startDate.AvailableSeatsCount++;
                        db.Projections.AddOrUpdate(startDate);
                        db.SaveChanges();
                    }
                }

                db.Reservations.AddOrUpdate(activeReservations);
                db.SaveChanges();
            }
        }
Exemple #4
0
        private void SeedSnacks(CinemaDbContext context)
        {
            var snacks = new[]
            {
                new Snack {
                    SnackId = 1, Name = "Pop Corn", Size = "Small", Cost = 5.99
                },
                new Snack {
                    SnackId = 2, Name = "Coke", Size = "Large", Cost = 6.20
                },
                new Snack {
                    SnackId = 3, Name = "Snickers", Size = "Small", Cost = 2.50
                },
                new Snack {
                    SnackId = 4, Name = "Pizza", Size = "Regular", Cost = 8.99
                },
                new Snack {
                    SnackId = 5, Name = "Nachos + Coke", Size = "Large", Cost = 12.50
                },
                new Snack {
                    SnackId = 6, Name = "Nachos", Size = "Small", Cost = 8.99
                }
            };

            context.Snack.AddRange(snacks);
            context.SaveChanges();
        }
Exemple #5
0
        public void ADD_ShouldReturnSnackAdded()
        {
            //Arrange
            int x     = 7;
            var snack = new Snack()
            {
                SnackId = x, Name = "M&M", Size = "Small", Cost = 3.50
            };
            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "ADD_ShouldReturnSnackAdded")
                          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                          .Options;

            var context = new CinemaDbContext(options);

            SeedSnacks(context);

            var service = new SnackService(context);

            //Act
            var result = service.Add(snack);


            //Assert
            Assert.True(result);
        }
Exemple #6
0
        public ActionResult DoUpload(IFormFile file)
        {
            using (var stream = file.OpenReadStream())
            {
                var xs     = new XmlSerializer(typeof(Cinema));
                var cinema = (Cinema)xs.Deserialize(stream);


                using (var db = new CinemaDbContext())
                {
                    var dbs = new DbCinema()
                    {
                        Name   = cinema.Name,
                        Adress = cinema.Adress,
                    };
                    dbs.Films = new Collection <DbFilm>();
                    foreach (var film in cinema.Films)
                    {
                        dbs.Films.Add(new DbFilm()
                        {
                            Name  = film.Name,
                            Seats = film.Seats,
                            Time  = film.Time,
                        });
                    }

                    db.Cinemas.Add(dbs);
                    db.SaveChanges();
                }

                return(View(cinema));
            }
        }
Exemple #7
0
        public void UPDATE_ShouldReturnNewName()
        {
            //Arrange
            var x     = 2;
            var actor = new Actor {
                ActorId = x, FirstName = "Sarah Jessica", LastName = "Parker", Age = 54, Gender = 'F', Rating = "6.5/10"
            };

            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "UPDATE_ShouldReturnNewName")
                          .Options;

            var context = new CinemaDbContext(options);

            SeedActors(context);

            var service = new ActorService(context);

            //Act
            var result = service.Update(x, actor);


            //Assert
            Assert.Equal(result.FirstName, actor.FirstName);
        }
        public void UPDATE_ShouldReturnNewName()
        {
            //Arrange
            var x    = 1;
            var Film = new Film {
                FilmId = x, Title = "The Wolf of Wall Street", Description = "Jordan Befolrt is the best broker of Wall Street", Year = 2012, Duration = "2h 54min", Genre = "Drama", Rating = "9.2/10"
            };

            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "UPDATE_ShouldReturnNewName")
                          .Options;

            var context = new CinemaDbContext(options);

            SeedFilms(context);

            var service = new FilmService(context);

            //Act
            var result = service.Update(x, Film);


            //Assert
            Assert.True(result);
        }
        public void ADD_ShouldReturnFilmAdded()
        {
            //Arrange
            int x    = 4;
            var film = new Film()
            {
                FilmId = x, Title = "Pain and Gain", Description = "Three bodybuilder will do anything to become rich", Year = 2014, Duration = "2h 10min", Genre = "Action/Drama", Rating = "8.1/10"
            };
            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "ADD_ShouldReturnFilmAdded")
                          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                          .Options;

            var context = new CinemaDbContext(options);

            SeedFilms(context);

            var service = new FilmService(context);

            //Act
            var result = service.Add(film);


            //Assert
            Assert.Equal(result.Title, film.Title);
        }
Exemple #10
0
        public async Task SeedAsync(CinemaDbContext context)
        {
            if (context.FilmProjections.Any())
            {
                return;
            }

            var projection = new FilmProjection
            {
                CinemaId       = context.Cinemas.First().Id,
                Date           = DateTime.UtcNow.AddDays(10),
                FilmId         = context.Films.First().Id,
                ProjectionType = ProjectionType._3D,
                TotalTickets   = 100,
                TicketPrices   = new TicketPrices
                {
                    AdultPrice    = 15,
                    StudentPrice  = 10,
                    ChildrenPrice = 5,
                },
            };

            await context.FilmProjections.AddAsync(projection);

            await context.SaveChangesAsync();
        }
Exemple #11
0
 public TicketRepository(IProjectionRepository projectionRepository, IReservationRepository reservationRepository,
                         CinemaDbContext cinemaDbContext)
 {
     this.projectionRepository  = projectionRepository;
     this.reservationRepository = reservationRepository;
     this.dbContext             = cinemaDbContext;
 }
Exemple #12
0
        public void ADD_ShouldReturnEmployeeAdded()
        {
            //Arrange
            int x        = 6;
            var employee = new Employee()
            {
                EmployeeId = x, FirstName = "Miguel", LastName = "Cruz", Age = 26
            };
            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "ADD_ShouldReturnEmployeeAdded")
                          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                          .Options;

            var context = new CinemaDbContext(options);

            SeedEmployees(context);

            var service = new EmployeeService(context);

            //Act
            var result = service.Add(employee);


            //Assert
            Assert.True(result);
        }
Exemple #13
0
        public void ADD_ShouldReturnDirectorAdded()
        {
            //Arrange
            int x        = 4;
            var director = new Director()
            {
                DirectorId = x, FirstName = "James", LastName = "Cameron", Age = 58, Rating = "9.6/10"
            };
            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "ADD_ShouldReturnDirectorAdded")
                          .Options;

            var context = new CinemaDbContext(options);

            SeedDirectors(context);

            var service = new DirectorService(context);

            //Act
            var result = service.Add(director);


            //Assert
            Assert.True(result);
        }
Exemple #14
0
        public void UPDATE_ShouldReturnNewName()
        {
            //Arrange
            var x        = 2;
            var Director = new Director {
                DirectorId = x, FirstName = "David", LastName = "Fincher", Age = 54, Rating = "7.9/10"
            };

            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "UPDATE_ShouldReturnNewName")
                          .Options;

            var context = new CinemaDbContext(options);

            SeedDirectors(context);

            var service = new DirectorService(context);

            //Act
            var result = service.Update(x, Director);


            //Assert
            Assert.Equal(result.FirstName, Director.FirstName);
        }
        public JsonResult IsUserExists(string Email)
        {
            CinemaDbContext db = new CinemaDbContext();

            //check if any of the Email matches the Email specified in the Parameter using the ANY extension method.
            return(Json(!db.Users.Any(x => x.Email == Email), JsonRequestBehavior.AllowGet));
        }
Exemple #16
0
 public MoviesController(CinemaDbContext dbContext, IMovie movie, IActionContextAccessor accessor)
 {
     _dbContext = dbContext;
     _movieRepo = movie;
     _accessor  = accessor;
     //_movieRepo.SetDbContext(_dbContext);
 }
Exemple #17
0
        public async Task SeedAsync(CinemaDbContext context)
        {
            if (context.Roles.Any())
            {
                return;
            }

            var roles = new List <CinemaRole>()
            {
                new CinemaRole {
                    Name = "Admin", NormalizedName = "ADMIN", Role = RoleType.Admin
                },
                new CinemaRole {
                    Name = "Manager", NormalizedName = "MANAGER", Role = RoleType.Manager
                },
                new CinemaRole {
                    Name = "User", NormalizedName = "USER", Role = RoleType.User
                },
            };

            foreach (var role in roles)
            {
                await context.Roles.AddAsync(role);
            }

            await context.SaveChangesAsync();
        }
Exemple #18
0
        public void UPDATE_ShouldReturnNewName()
        {
            //Arrange
            var x     = 6;
            var Snack = new Snack {
                SnackId = 7, Name = "Pizza", Size = "Large", Cost = 14.50
            };

            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "UPDATE_ShouldReturnNewName")
                          .Options;

            var context = new CinemaDbContext(options);

            SeedSnacks(context);

            var service = new SnackService(context);

            //Act
            var result = service.Update(x, Snack);


            //Assert
            Assert.Equal(result.Name, Snack.Name);
        }
Exemple #19
0
        public void ADD_ShouldReturnActorAdded()
        {
            //Arrange
            int x     = 5;
            var actor = new Actor()
            {
                ActorId = x, FirstName = "Mark", LastName = "Walhberg", Age = 44, Gender = 'M', Rating = "8.5/10"
            };
            var options = new DbContextOptionsBuilder <CinemaDbContext>()
                          .UseInMemoryDatabase(databaseName: "ADD_ShouldReturnActorAdded")
                          .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
                          .Options;

            var context = new CinemaDbContext(options);

            SeedActors(context);

            var service = new ActorService(context);

            //Act
            var result = service.Add(actor);


            //Assert
            Assert.Equal(result.ActorId, actor.ActorId);
        }
Exemple #20
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CinemaDbContext dbContext)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            // dbContext.Database.EnsureCreated();
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller}/{action=Index}/{id?}");
            });
        }
Exemple #21
0
        public BookingRepositoryShould()
        {
            _options = new DbContextOptionsBuilder <CinemaDbContext>()
                       .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;
            _dbContext = new CinemaDbContext(_options);
            _fake      = new FakeData();

            _fake.SeedInMemoryData(_dbContext);
        }
Exemple #22
0
        public ActionResult List()
        {
            List <DbCinema> list;

            using (var db = new CinemaDbContext())
            {
                list = db.Cinemas.Include(s => s.Films).ToList();
            }
            return(View(list));
        }
Exemple #23
0
 protected new void SetUp(CinemaDbContext cinemaDbContext)
 {
     base.SetUp(cinemaDbContext);
     EncrypterMock.Setup(m => m.Compute(User.Password, It.IsAny <string>()))
     .Returns((string pass, string salt) => pass);
     EncrypterMock.Setup(m => m.Compare(User.Password, User.Password)).Returns(true);
     cinemaDbContext.Add(User);
     cinemaDbContext.SaveChanges();
     UserService = new Cinema.Services.UserService(cinemaDbContext, EncrypterMock.Object, TokenProviderMock.Object, Mapper, MemoryCache, EmailSenderMock.Object);
 }
Exemple #24
0
        public ActionResult Edit(UserEditViewModel user)
        {
            if (!ModelState.IsValid)
            {
                return(View(user));
            }

            CinemaDbContext db = new CinemaDbContext();

            var sessionId = Session["LoggedUserID"];

            if (sessionId == null)
            {
                return(View(""));
            }
            int userId = (int)sessionId;

            var entity = db.Users.FirstOrDefault(UserViewEdit => UserViewEdit.Id == userId);

            if (entity != null)
            {
                entity.Name      = user.Name;
                entity.Surname   = user.Surname;
                entity.Password  = user.Password;
                entity.BirthDate = user.BirthDate;
                entity.Address   = user.Address;
                entity.Phone     = user.Phone;
                var city = db.Cities.FirstOrDefault(c => c.Name == user.City);
                if (city == null)
                {
                    city        = new City();
                    city.Name   = user.City;
                    entity.City = city;
                    db.Cities.Add(city);
                }

                entity.Email = user.Email;

                db.Users.Attach(entity);
                var entry = db.Entry(entity);

                entry.Property(e => e.Name).IsModified      = true;
                entry.Property(e => e.Surname).IsModified   = true;
                entry.Property(e => e.Password).IsModified  = true;
                entry.Property(e => e.BirthDate).IsModified = true;
                entry.Property(e => e.Address).IsModified   = true;
                entry.Property(e => e.Phone).IsModified     = true;
                entry.Property(e => e.Email).IsModified     = true;

                db.SaveChanges();
            }
            ViewBag.Message = "Twoje konto zostało edytowane";

            return(View(user));
        }
        //JsonResult
        public ActionResult GetReservedSpots(int id)
        {
            CinemaDbContext db = new CinemaDbContext();

            var seats = db.Reservations.Where(x => x.SeanceId == id).ToList();
            var model = Mapper.Map <List <JsonReservationInfoViewModel> >(seats);

            var json = JsonConvert.SerializeObject(model);

            return(Content(json, "application/json"));
        }
Exemple #26
0
        protected void SetUp(CinemaDbContext cinemaDbContext)
        {
            User = new User("*****@*****.**", "FirstName", "LastName", "Secret123", "user", "123123123");
            TokenProviderMock = new Mock <ITokenProvider>();
            EncrypterMock     = new Mock <IEncrypter>();
            Mapper            = AutoMapperConfig.Initialize();
            MemoryCache       = new MemoryCache(new MemoryCacheOptions());
            var configuration = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();

            EmailSenderMock = new Mock <IEmailSender>();
            UserService     = new Cinema.Services.UserService(cinemaDbContext, EncrypterMock.Object, TokenProviderMock.Object, Mapper, MemoryCache, EmailSenderMock.Object);
        }
Exemple #27
0
        private void createRoles()
        {
            CinemaDbContext storage     = new CinemaDbContext();
            var             roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(storage));
            var             userManager = new UserManager <CinemaUser>(new UserStore <CinemaUser>(storage));

            if (!roleManager.RoleExists("Admin"))
            {
                var role = new IdentityRole();
                role.Name = "Admin";
                roleManager.Create(role);
            }
        }
Exemple #28
0
        static void Main(string[] args)
        {
            var configuration    = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build();
            var connectionString = configuration["Sql:ConnectionString"];
            var dbContextOptions = new DbContextOptionsBuilder <CinemaDbContext>()
                                   .UseSqlServer(connectionString).Options;
            var cinemaDbContext = new CinemaDbContext(dbContextOptions);


            var seeder = new CinemaSeeder(cinemaDbContext);

            seeder.Seed(5, 10);
        }
Exemple #29
0
        public void Setup()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddEntityFrameworkSqlServer()
                                  .BuildServiceProvider();

            var builder = new DbContextOptionsBuilder <CinemaDbContext>();

            builder.UseSqlServer(@"Server=localhost\SQLEXPRESS;Database=test_1;Trusted_Connection=Yes;MultipleActiveResultSets=True;")
            .UseInternalServiceProvider(serviceProvider);

            _context = new CinemaDbContext(builder.Options);
            _context.Database.Migrate();
        }
        public static void CancelReservations(long projectionId)
        {
            using (var db = new CinemaDbContext())
            {
                var projection   = db.Projections.First(p => p.Id == projectionId);
                var reservations = db.Reservations.Where(r => r.ProjectionId == projectionId);

                foreach (var reservation in reservations)
                {
                    reservation.IsCanceled          = true;
                    projection.AvailableSeatsCount += 1;
                }

                db.SaveChanges();
            }
        }