//method to register user public UserRegistration AddUser(UserRegistration user) { try { //validating UserType bool inputUserType = Enum.TryParse <UserTypes.User>(user.UserType, true, out UserTypes.User type); if (inputUserType != true) { throw new Exception("Invalid User Category"); } //variable declared string Email = user.Email; //validation of email registration var Validation = dbContext.UserDetails.Where(v => v.Email == Email).FirstOrDefault(); if (Validation != null) { throw new Exception("User Already Exist"); } UserDetails details = new UserDetails() { FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, UserType = user.UserType, Password = user.Password }; //Adding new user data in the database var Result = dbContext.UserDetails.Add(details); //save changes in database dbContext.SaveChanges(); //return valid user data if (Result != null) { return(user); } else { throw new Exception("User Not Registered"); } } catch (Exception exception) { throw new Exception(exception.Message); } }
public async Task Should_not_create_order_when_parkingLot_is_full_via_service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>(); context.ParkingLots.RemoveRange(context.ParkingLots); context.Orders.RemoveRange(context.Orders); context.Cars.RemoveRange(context.Cars); context.SaveChanges(); ParkingLotService parkingLotService = new ParkingLotService(context); OrderService orderService = new OrderService(context); CarService carService = new CarService(context); var name = await parkingLotService.AddParkingLot(parkingLotDto1); var orderNumber1 = await orderService.AddOrder(orderDto1); await carService.AddCar(name, carDto1); Assert.Equal(1, context.Orders.Count()); var orderNumber2 = await orderService.AddOrder(orderDto2); Assert.Equal(1, context.Orders.Count()); }
public async Task Should_add_parkingLot_successfully_via_service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>(); context.ParkingLots.RemoveRange(context.ParkingLots); context.SaveChanges(); ParkingLotService parkingLotService = new ParkingLotService(context); await parkingLotService.AddParkingLot(parkingLotDto1); Assert.Equal(1, context.ParkingLots.Count()); }
public async Task Should_delete_parkigLot_successfully_when_can_find_by_name_via_service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>(); ParkingLotService parkingLotService = new ParkingLotService(context); context.ParkingLots.RemoveRange(context.ParkingLots); context.SaveChanges(); var addReturn = await parkingLotService.AddParkingLot(parkingLotDto1); await parkingLotService.DeleteParkingLot(addReturn); Assert.Equal(0, context.ParkingLots.Count()); }
public async Task Should_not_add_parkingLot_when_name_already_exist_via_service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>(); context.ParkingLots.RemoveRange(context.ParkingLots); context.SaveChanges(); ParkingLotService parkingLotService = new ParkingLotService(context); await parkingLotService.DeleteAllParkingLot(); await parkingLotService.AddParkingLot(parkingLotDto1); //await parkingLotService.AddParkingLot(parkingLotDto1); Assert.Equal(1, context.ParkingLots.Count()); }
public async Task Should_update_parkingLot_Successfully_Via_Service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>(); ParkingLotService parkingLotService = new ParkingLotService(context); context.ParkingLots.RemoveRange(context.ParkingLots); context.SaveChanges(); var update = new UpdateParkingLotDto(50); var addReturn = await parkingLotService.AddParkingLot(parkingLotDto1); var updateReturn = await parkingLotService.UpdateParkingLot(addReturn, update); Assert.Equal(50, updateReturn.Capacity); }
public async Task Should_get_x_parkingLots_for_page_y_Via_Service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>(); ParkingLotService parkingLotService = new ParkingLotService(context); context.ParkingLots.RemoveRange(context.ParkingLots); context.SaveChanges(); var addReturn1 = await parkingLotService.AddParkingLot(parkingLotDto1); var addReturn2 = await parkingLotService.AddParkingLot(parkingLotDto2); var getAllReturn = await parkingLotService.GetByPageSizeAndIndex(1, 1); Assert.Equal(1, getAllReturn.Count); }
public async Task Should_add_car_successfully_when_position_available_via_service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>(); context.ParkingLots.RemoveRange(context.ParkingLots); context.Orders.RemoveRange(context.Orders); context.Cars.RemoveRange(context.Cars); context.SaveChanges(); ParkingLotService parkingLotService = new ParkingLotService(context); CarService carService = new CarService(context); var addParkingLotReturn = await parkingLotService.AddParkingLot(parkingLotDto1); await carService.AddCar(addParkingLotReturn, carDto1); Assert.Equal(1, context.Cars.Count()); }
public async Task Should_get_parkingLot_Successfully_by_name_Via_Service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>(); context.ParkingLots.RemoveRange(context.ParkingLots); context.SaveChanges(); ParkingLotService parkingLotService = new ParkingLotService(context); await parkingLotService.AddParkingLot(parkingLotDto1); var getByName = await parkingLotService.GetByName("IBM"); var parkingLotDto1String = JsonConvert.SerializeObject(parkingLotDto1); var getByNameString = JsonConvert.SerializeObject(getByName); Assert.Equal(parkingLotDto1String, getByNameString); }
public async Task Should_update_order_status_to_close_when_car_left_via_service() { var scope = Factory.Services.CreateScope(); var scopedServices = scope.ServiceProvider; ParkingLotDbContext context = scopedServices.GetRequiredService <ParkingLotDbContext>(); context.Orders.RemoveRange(context.Orders); context.SaveChanges(); ParkingLotService parkingLotService = new ParkingLotService(context); OrderService orderService = new OrderService(context); parkingLotService.AddParkingLot(parkingLotDto1); UpdateOrderDto updateOrderDto = new UpdateOrderDto("closed"); var addOrderNumber = await orderService.AddOrder(orderDto1); var orderDto = await orderService.UpdateOrder(addOrderNumber, updateOrderDto); Assert.Equal("closed", orderDto.OrderStatus); }
static void SeedData(ParkingLotDbContext context) { context.Database.EnsureDeleted(); context.Database.Migrate(); var owner1 = new Owner { Name = "Adam", Phone = "0994750925" }; var owner2 = new Owner { Name = "Erick", Phone = "0501448285" }; var owner3 = new Owner { Name = "Rob", Phone = "0678452522" }; var owner4 = new Owner { Name = "Alice", Phone = "0637870244" }; var car1 = new Car { Name = "Ferrari", LicensePlate = "XA1232", Owner = owner1 }; var car2 = new Car { Name = "Audi", LicensePlate = "AA7575", Owner = owner2 }; var car3 = new Car { Name = "BMW", LicensePlate = "AI8585", Owner = owner3 }; var car4 = new Car { Name = "Toyota", LicensePlate = "AX7777", Owner = owner4 }; context.Cars.AddRange(car1, car2, car3, car4); context.SaveChanges(); var parkingLot1 = new ParkingLot { Name = "Greenway Self-Park", Address = "Molochnaya 3" }; var parkingSpot1 = new ParkingSpot { Number = "1", IsBusy = false, Cost = 60, ParkingLot = parkingLot1 }; var parkingSpot2 = new ParkingSpot { Number = "2", IsBusy = false, Cost = 50, ParkingLot = parkingLot1 }; var garage1 = new Garage { Number = "1", IsBusy = false, Cost = 100, ParkingLot = parkingLot1 }; var garage2 = new Garage { Number = "2", IsBusy = false, Cost = 100, ParkingLot = parkingLot1 }; context.ParkingSpots.AddRange(parkingSpot1, parkingSpot2, garage1, garage2); context.SaveChanges(); var visit1 = new Visit { Car = car1, ParkingSpot = parkingSpot1, Entered = new DateTime(2021, 2, 10, 12, 20, 45), Left = new DateTime(2021, 2, 11, 15, 25, 30) }; var visit2 = new Visit { Car = car2, ParkingSpot = garage1, Entered = new DateTime(2021, 2, 11), Left = DateTime.Now, }; var visit3 = new Visit { Car = car3, ParkingSpot = parkingSpot2, Entered = DateTime.Now, Left = null, }; var visit4 = new Visit { Car = car4, ParkingSpot = garage2, Entered = DateTime.Now, Left = null, }; context.Visits.AddRange(visit1, visit2, visit3, visit4); context.SaveChanges(); }
//Method to Add parking details public ParkingLotDetails ParkingCarInLot(ParkingInformation Details) { var condition = dataBase.ParkingLotDetails.Where(parkingDetails => parkingDetails.Status == "Park").Count(); //check if parking lot is full or empty if (!condition.Equals(Limit.TotalParkingLimit)) { try { ParkingLotDetails details = new ParkingLotDetails(); details.VehicleOwnerName = Details.VehicleOwnerName; details.VehicleNumber = Details.VehicleNumber; details.VehicalBrand = Details.VehicalBrand; details.VehicalColor = Details.VehicalColor; details.DriverName = Details.DriverName; details.ParkingUserCategory = Details.ParkingUserCategory; // Conditions bool condition1 = dataBase.ParkingLotDetails.Any(parkingDetails => parkingDetails.VehicleNumber == details.VehicleNumber); //bool condition2 = dataBase.ParkingLotDetails.Any (parkingDetails => parkingDetails.VehicleNumber == details.VehicleNumber && parkingDetails.Status == "UnPark"); var condition2 = (from parkingDetails in dataBase.ParkingLotDetails where parkingDetails.VehicleNumber == details.VehicleNumber select parkingDetails.Status == "UnPark").LastOrDefault(); // Check Same Data Available Or Not By Vehicale Number if (!condition1) { details.ParkingDate = DateTime.Now; details.Status = "Park"; details.ParkingSlot = checkValidParkingSlot(details.ParkingSlot); details.ParkingUserCategory = ParkingCategory(details.ParkingUserCategory); if (details.ParkingUserCategory == "Handicap") { details.ParkingSlot = checkPakingSlotForHandicap(details.ParkingSlot); } dataBase.Add(details); dataBase.SaveChanges(); // Return Data return(details); } else if (condition2) // Check Second Condition The Data Avaliable With UnPark And Last Data Of That Vehical Number { // Current Date And Time details.ParkingDate = DateTime.Now; details.Status = "Park"; dataBase.Add(details); dataBase.SaveChanges(); // Return Data return(details); } else { // If Data Avaliable With Park Status Return This Message throw new Exception(details.VehicleNumber + " Vehical Number already parked in the Lot "); } } catch (Exception exception) { throw new Exception(exception.Message); } } else { throw new Exception("ParkingLot Is Full"); } }