Exemplo n.º 1
0
        public async void Update_UserIsOk_UserIsUpdated()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                var user = await unitOfWork.UserRepository.GetByUsername("Juan");


                user.Id           = 1;
                user.Username     = "******";
                user.EmailAddress = "*****@*****.**";
                user.Role         = 0;
                user.Password     = "******";

                await unitOfWork.UserRepository.GetAndUpdate(user);

                unitOfWork.SaveChanges();
            }

            using (var context = new RentACarContext(ContextOptions))
            {
                var user = context.Set <User>().FirstOrDefault(u => u.Id == 1);

                Assert.Equal(1, user.Id);
                Assert.Equal("Martin", user.Username);
                Assert.Equal("*****@*****.**", user.EmailAddress);
                Assert.Equal(RoleType.Administrator, user.Role);
                Assert.Equal("secret", user.Password);
                Assert.Equal(DateTime.Today.Date, user.ModifiedAt?.Date);
            }
        }
Exemplo n.º 2
0
        public async void CheckAndUpdate_carAndCardWithChangesAreOk_SaveChanges()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                Car carWithChanges = new Car {
                    Id = 3, Model = "Focus", Year = 2020, Gearbox = "Automatic", AirConditioner = true, Available = true, BodyTypeId = 1, BrandId = 6, Image = "img4.jpg", Doors = 4, Seats = 5, CreatedAt = DateTime.Parse("2021-05-05")
                };
                Car existingCar = await unitOfWork.CarRepository.GetById(carWithChanges.Id);

                await unitOfWork.CarRepository.CheckAndUpdate(existingCar, carWithChanges);

                await unitOfWork.SaveChangesAsync();
            }

            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);
                var car        = await unitOfWork.CarRepository.GetById(3);

                Assert.Equal(3, car.Id);
                Assert.Equal("Focus", car.Model);
                Assert.Equal("Automatic", car.Gearbox);
                Assert.Equal("img4.jpg", car.Image);
                Assert.Equal(5, (int)car.Seats);
            }
        }
Exemplo n.º 3
0
        private void Seed()
        {
            var user1 = new User()
            {
                Username = "******", Role = RoleType.Consumer, Password = "******", EmailAddress = "*****@*****.**", CreatedAt = DateTime.Parse("2021-04-27")
            };
            var user2 = new User()
            {
                Username = "******", Role = RoleType.Consumer, Password = "******", EmailAddress = "*****@*****.**", CreatedAt = DateTime.Parse("2021-04-29")
            };
            var user3 = new User()
            {
                Username = "******", Role = RoleType.Consumer, Password = "******", EmailAddress = "*****@*****.**", CreatedAt = DateTime.Parse("2021-04-30")
            };

            using (var context = new RentACarContext(ContextOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                var unitOfWork = new UnitOfWork(context);

                unitOfWork.UserRepository.Add(user1);
                unitOfWork.UserRepository.Add(user2);
                unitOfWork.UserRepository.Add(user3);

                unitOfWork.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public async void Add_UserObjectIsOk_UserIsRegistered()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                User user = new User()
                {
                    Username     = "******",
                    EmailAddress = "*****@*****.**",
                    Role         = 0,
                    Password     = "******"
                };

                await unitOfWork.UserRepository.Add(user);

                unitOfWork.SaveChanges();


                Assert.Equal(4, user.Id); // After the insert the entity must have id > 0
            }

            using (var context = new RentACarContext(ContextOptions))
            {
                var user = context.Set <User>().FirstOrDefault(u => u.Username == "Test1");

                Assert.Equal(4, user.Id);
                Assert.Equal("Test1", user.Username);
                Assert.Equal("*****@*****.**", user.EmailAddress);
                Assert.Equal(RoleType.Administrator, user.Role);
                Assert.Equal("secret", user.Password);
                Assert.Equal(DateTime.Today.Date, user.CreatedAt.Date);
            }
        }
Exemplo n.º 5
0
        public async void GetAndUpdate_CarIsNull_ThrowsException()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                await Assert.ThrowsAsync <ArgumentNotDefinedException>(() => unitOfWork.CarRepository.GetAndUpdate(null));
            }
        }
Exemplo n.º 6
0
        public async void Add_UserObjectIsNull_ThrowException()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                await Assert.ThrowsAsync <ArgumentNotDefinedException>(() => unitOfWork.UserRepository.Add(null));
            }
        }
Exemplo n.º 7
0
        public void GetAll_ReturnsThreeCarsStoredInDB()
        {
            using (var context = new RentACarContext(ContextOptions)) {
                var unitOfWork = new UnitOfWork(context);

                var cars = unitOfWork.CarRepository.GetAll();

                Assert.Equal(3, cars.Count());
            }
        }
Exemplo n.º 8
0
        public async void GetByUsername_UsernameNotExists_ReturnNull()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                var user = await unitOfWork.UserRepository.GetByUsername("Esteban");

                Assert.Null(user);
            }
        }
Exemplo n.º 9
0
 public void Add(Car car)
 {
     using (RentACarContext context = new RentACarContext())
     {
         if (car.DailyPrice > 0 && context.Brands.SingleOrDefault(b => b.BrandId == car.BrandId).BrandName.Length > 2)
         {
             _carDal.Add(car);
             Console.WriteLine("Car added database succesfully");
         }
     }
 }
Exemplo n.º 10
0
        public async void GetByEmail_EmailNotExists_ReturnNull()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                var user = await unitOfWork.UserRepository.GetByEmail("*****@*****.**");

                Assert.Null(user);
            }
        }
Exemplo n.º 11
0
        private void CreateApplicationUserAdmin(RentACarContext context)
        {
            var user = new User
            {
                Email     = "*****@*****.**",
                Firstname = "",
                Lastname  = "",
                IsAdmin   = true
            };

            context.UserInfo.Add(user);
        }
Exemplo n.º 12
0
        public async void GetByEmail_EmailIsOk_ReturnUser()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                var user = await unitOfWork.UserRepository.GetByEmail("*****@*****.**");

                Assert.True(user != null);
                Assert.Equal("Juan", user.Username);
            }
        }
Exemplo n.º 13
0
        public async void GetAndUpdate_CarDoesNotExists_ThrowsException()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                var car = new Car {
                    Id = 5, Model = "Focus", Year = 2020, Gearbox = "Automatic", AirConditioner = true, Available = true, BodyTypeId = 1, BrandId = 6, Image = "img4.jpg", Doors = 4, Seats = 5, CreatedAt = DateTime.Parse("2021-05-05")
                };

                await Assert.ThrowsAsync <NullEntityException>(() => unitOfWork.CarRepository.GetAndUpdate(car));
            }
        }
Exemplo n.º 14
0
        public async void GetByEmail_EmailIsNull_ThrowException()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                await Assert.ThrowsAsync <ArgumentNotDefinedException>(() => unitOfWork.UserRepository.GetByUsername(null));

                await Assert.ThrowsAsync <ArgumentNotDefinedException>(() => unitOfWork.UserRepository.GetByUsername(""));

                await Assert.ThrowsAsync <ArgumentNotDefinedException>(() => unitOfWork.UserRepository.GetByUsername("   "));
            }
        }
Exemplo n.º 15
0
        public async void GetByUsername_UsernameIsOk_ReturnUser()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                var user = await unitOfWork.UserRepository.GetByUsername("Juan");

                Assert.Equal("Juan", user.Username);
                Assert.Equal("test", user.Password);
                Assert.Equal("*****@*****.**", user.EmailAddress);
            }
        }
Exemplo n.º 16
0
        public async void GetByUsername_UserNameIsNull_ThrowException()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var userRepository = new UserRepository(context);

                await Assert.ThrowsAsync <ArgumentNotDefinedException>(() => userRepository.GetByUsername(null));

                await Assert.ThrowsAsync <ArgumentNotDefinedException>(() => userRepository.GetByUsername(""));

                await Assert.ThrowsAsync <ArgumentNotDefinedException>(() => userRepository.GetByUsername("   "));
            }
        }
Exemplo n.º 17
0
        private void CreateApplicationUserAmeteo(RentACarContext context)
        {
            var user = new User
            {
                Email     = "*****@*****.**",
                Firstname = "Ameteo",
                Lastname  = "Stan",
                City      = "Timisoara",
                Address   = "Strada lunga",
                IsAdmin   = false
            };

            context.UserInfo.Add(user);
        }
Exemplo n.º 18
0
        private void CreateApplicationUserDiana(RentACarContext context)
        {
            var user = new User
            {
                Email     = "*****@*****.**",
                Firstname = "Diana",
                Lastname  = "Sebo",
                City      = "Timisoara",
                Address   = "Strada aia",
                IsAdmin   = false
            };

            context.UserInfo.Add(user);
        }
Exemplo n.º 19
0
        public async void Add_CarIsOk_CarIsRegistered()
        {
            using (var context = new RentACarContext(ContextOptions))
            {
                var unitOfWork = new UnitOfWork(context);

                Car car = new Car()
                {
                    Id             = 4,
                    BrandId        = 4,
                    AirConditioner = true,
                    Gearbox        = "Automatic",
                    Doors          = 4,
                    Year           = 2020,
                    BodyTypeId     = 2,
                    Image          = "img4.jpg",
                    Model          = "Vento",
                    Seats          = 5,
                };

                await unitOfWork.CarRepository.Add(car);

                unitOfWork.SaveChanges();


                Assert.Equal(4, car.Id); // After the insert the entity must have id > 0
            }

            using (var context = new RentACarContext(ContextOptions))
            {
                var car = context.Set <Car>().FirstOrDefault(u => u.Model == "Vento");

                Assert.Equal(4, car.Id);
                Assert.Equal(4, car.BrandId);
                Assert.True(car.AirConditioner);
                Assert.Equal("Vento", car.Model);
                Assert.Equal("Automatic", car.Gearbox);
                Assert.Equal(2020, car.Year);
                Assert.Equal("img4.jpg", car.Image);
                Assert.Equal(DateTime.Today.Date, car.CreatedAt.Date);
            }
        }
Exemplo n.º 20
0
        private void Seed()
        {
            var car1 = new Car {
                Id = 1, Model = "Uno", Year = 2000, Gearbox = "Automatic", AirConditioner = false, Available = true, BodyTypeId = 2, BrandId = 4, Image = "img.jpg", Doors = 4, Seats = 5, CreatedAt = DateTime.Parse("2021-05-04")
            };
            var car2 = new Car {
                Id = 2, Model = "Fiesta", Year = 2016, Gearbox = "Manual", AirConditioner = true, Available = true, BodyTypeId = 1, BrandId = 5, Image = "img2.jpg", Doors = 4, Seats = 5, CreatedAt = DateTime.Parse("2021-05-01")
            };
            var car3 = new Car {
                Id = 3, Model = "Focus", Year = 2019, Gearbox = "Manual", AirConditioner = true, Available = true, BodyTypeId = 1, BrandId = 6, Image = "img3.jpg", Doors = 4, Seats = 5, CreatedAt = DateTime.Parse("2021-05-05")
            };

            var brand4 = new Brand {
                Id = 4, Name = "Brand4"
            };
            var brand5 = new Brand {
                Id = 5, Name = "Brand5"
            };
            var brand6 = new Brand {
                Id = 6, Name = "Brand6"
            };

            using (var context = new RentACarContext(ContextOptions))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                var unitOfWork = new UnitOfWork(context);

                unitOfWork.CarRepository.Add(car1);
                unitOfWork.CarRepository.Add(car2);
                unitOfWork.CarRepository.Add(car3);

                unitOfWork.BrandRepository.Add(brand4);
                unitOfWork.BrandRepository.Add(brand5);
                unitOfWork.BrandRepository.Add(brand6);

                unitOfWork.SaveChanges();
            }
        }
Exemplo n.º 21
0
        static void Main(string[] args)
        {
            RentACarContext context = new RentACarContext();

            //foreach ( var car in context.Cars)
            //{
            //    Console.WriteLine(car.Description);
            //}

            // carManager.Add(new Car { Id=6, BrandId=2, ColorId=2, DailyPrice=0, ModelYear=2012, Description="Yeni araç"});

            //CarDetails(carManager);

            BrandManager brandManager = new BrandManager(new EFBrandDal());

            brandManager.Add(new Brand {
                BrandId = 6, BrandName = "papatya"
            });                                                           //-marka ekleme
            brandManager.Update(new Brand {
                BrandId = 1, BrandName = "Tofaş"
            });                                                              //- marka güncelleme
        }
Exemplo n.º 22
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, RentACarContext context)
        {
            app.Use(async(ctx, next) =>
            {
                await next();
                if (ctx.Response.StatusCode == 204)
                {
                    ctx.Response.ContentLength = 0;
                }
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseCors(builder =>
                        builder.WithOrigins(Configuration["ApplicationSettings:Client_URL"].ToString())
                        .AllowAnyHeader()
                        .AllowAnyMethod()
                        //.AllowAnyOrigin()

                        );

            //app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthentication();
            app.UseAuthorization();

            //RentACarDataInitializer.SeedCompanies(context);

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
 public BaseCRUDService(RentACarContext context, IMapper mapper) : base(context, mapper)
 {
 }
Exemplo n.º 24
0
 public ModelRepository(RentACarContext context) : base(context)
 {
 }
Exemplo n.º 25
0
 public PaymentTypeRepository(RentACarContext context) : base(context)
 {
 }
Exemplo n.º 26
0
 public CustomerRepository(RentACarContext context) : base(context)
 {
 }
Exemplo n.º 27
0
 public RefreshTokenRepository(RentACarContext context) : base(context)
 {
 }
Exemplo n.º 28
0
 public CarInfoRepository(RentACarContext context) : base(context)
 {
 }
Exemplo n.º 29
0
 public LocationRepository(RentACarContext context) : base(context)
 {
 }
Exemplo n.º 30
0
 public RegistracijeVozilaService(RentACarContext context, IMapper mapper) : base(context, mapper)
 {
 }