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); } }
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); } }
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(); } }
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); } }
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)); } }
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)); } }
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()); } }
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); } }
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"); } } }
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); } }
private void CreateApplicationUserAdmin(RentACarContext context) { var user = new User { Email = "*****@*****.**", Firstname = "", Lastname = "", IsAdmin = true }; context.UserInfo.Add(user); }
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); } }
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)); } }
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(" ")); } }
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); } }
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(" ")); } }
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); }
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); }
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); } }
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(); } }
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 }
// 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) { }
public ModelRepository(RentACarContext context) : base(context) { }
public PaymentTypeRepository(RentACarContext context) : base(context) { }
public CustomerRepository(RentACarContext context) : base(context) { }
public RefreshTokenRepository(RentACarContext context) : base(context) { }
public CarInfoRepository(RentACarContext context) : base(context) { }
public LocationRepository(RentACarContext context) : base(context) { }
public RegistracijeVozilaService(RentACarContext context, IMapper mapper) : base(context, mapper) { }