public void Filter_ForVehicleColorNumber_returns_Empty() { var vehicle1 = new Vehicle() { VehicleNumber = "KA-03-8986", VehicleColor = ColorEnums.Black }; var vehicle2 = new Vehicle() { VehicleNumber = "KA-03-8981", VehicleColor = ColorEnums.Black }; var vehicle3 = new Vehicle() { VehicleNumber = "KA-03-8982", VehicleColor = ColorEnums.Brown }; var vehicle4 = new Vehicle() { VehicleNumber = "KA-03-8983", VehicleColor = ColorEnums.Yellow }; var vehicle5 = new Vehicle() { VehicleNumber = "KA-03-8984", VehicleColor = ColorEnums.Magenta }; IParkingManagement parkingMgmt = new ParkingManagement(5); parkingMgmt.AddVehicleToSlot(vehicle1); parkingMgmt.AddVehicleToSlot(vehicle2); parkingMgmt.AddVehicleToSlot(vehicle3); parkingMgmt.AddVehicleToSlot(vehicle4); parkingMgmt.AddVehicleToSlot(vehicle5); var slots = parkingMgmt.GetParkingSlotsInformation().AsEnumerable(); var filter = new ParkingSlotFilter(); var criteria = new VehicleColorCriteria(ColorEnums.Red); var result = filter.Filter(slots, criteria); Assert.IsTrue(result.Count() == 0); var criteria1 = new VehicleNumberCriteria("KA-03-8981"); var result1 = filter.Filter(slots, criteria1); Assert.IsTrue(result1.Count() == 1); Assert.IsTrue(result1.ElementAt(0).VehicleInSlot.VehicleNumber == "KA-03-8981"); var criteria3 = new ConjunctionCriteria <ParkingSlot>(criteria, criteria1); var result2 = filter.Filter(slots, criteria3); Assert.IsTrue(result2.Count() == 0); var criteria4 = new VehicleNumberCriteria("KA-03-8988"); var result3 = filter.Filter(slots, criteria4); Assert.IsTrue(result3.Count() == 0); var criteria5 = new ConjunctionCriteria <ParkingSlot>(criteria, criteria4); var result4 = filter.Filter(slots, criteria5); Assert.IsTrue(result4.Count() == 0); }
public void Filter_ForSlotNumber_returns_Empty() { IParkingManagement parkingMgmt = new ParkingManagement(0); var filter = new ParkingSlotFilter(); var criteria = new SlotNumberCriteria(3); var result = filter.Filter(parkingMgmt.GetParkingSlotsInformation().AsEnumerable(), criteria); Assert.IsTrue(result.Count() == 0); }
public void Filter_ForSlotNumber_returns_Matched() { var vehicle1 = new Vehicle() { VehicleNumber = "KA-03-8986" }; var vehicle2 = new Vehicle() { VehicleNumber = "KA-03-8981" }; var vehicle3 = new Vehicle() { VehicleNumber = "KA-03-8982" }; var vehicle4 = new Vehicle() { VehicleNumber = "KA-03-8983" }; var vehicle5 = new Vehicle() { VehicleNumber = "KA-03-8984" }; IParkingManagement parkingMgmt = new ParkingManagement(5); parkingMgmt.AddVehicleToSlot(vehicle1); parkingMgmt.AddVehicleToSlot(vehicle2); parkingMgmt.AddVehicleToSlot(vehicle3); parkingMgmt.AddVehicleToSlot(vehicle4); parkingMgmt.AddVehicleToSlot(vehicle5); var filter = new ParkingSlotFilter(); var criteria = new SlotNumberCriteria(3); var result = filter.Filter(parkingMgmt.GetParkingSlotsInformation().AsEnumerable(), criteria); Assert.IsTrue(result.Count() == 1); Assert.IsTrue(result.ElementAt(0).VehicleInSlot.VehicleNumber == "KA-03-8982"); }
private static void ProcessCommands(IParkingManagement parkingManagement, string[] commands) { switch (commands[0]) { case Commands.CreateParkingLot: { if (commands.Length == 2) { int slots; if (int.TryParse(commands[1], out slots)) { parkingManagement.MaxParkingSlots = slots; Console.WriteLine("Created a parking lot with {0} slots", slots); } else { Console.WriteLine("please Provide numeric value for command {0}", Commands.CreateParkingLot); } } else { Console.WriteLine("please Provide numeric parameter value for command {0}", Commands.CreateParkingLot); } } break; case Commands.Park: { if (parkingManagement.MaxParkingSlots <= 0) { Console.WriteLine("Please allocate parking slots"); return; } if (commands.Length == 3) { ColorEnums color; if (ColorEnums.TryParse(commands[2], true, out color)) { var slotNumber = parkingManagement.AddVehicleToSlot(new Vehicle() { VehicleNumber = commands[1], VehicleColor = color }); if (slotNumber == -1) { Console.WriteLine("Sorry, parking lot is full"); return; } Console.WriteLine("Allocated slot number:{0}", slotNumber); } else { Console.WriteLine("Please provide appropriate Color."); } } else { Console.Write("Please provide exact 2 parameters. format- park [vehicleNumber] [color]"); } } break; case Commands.Leave: { if (parkingManagement.MaxParkingSlots <= 0) { Console.WriteLine("Please allocate parking slots"); return; } if (commands.Length == 2) { int slotNumber; if (int.TryParse(commands[1], out slotNumber)) { var vehicle = parkingManagement.UnParkVehicleFromSlot(slotNumber); if (vehicle == null) { Console.WriteLine("Slot number {0} does not exist", slotNumber); return; } Console.WriteLine("Slot number {0} is free", slotNumber); } } else { Console.WriteLine("Please provide appropriate Slot Number"); } } break; case Commands.RegNumbersForCarsWithColor: { if (parkingManagement.MaxParkingSlots <= 0) { Console.WriteLine("Please allocate parking slots"); return; } if (commands.Length == 2) { ColorEnums color; if (ColorEnums.TryParse(commands[1], true, out color)) { var colorCriteria = new VehicleColorCriteria(color); var filledSlots = parkingManagement.GetParkingSlotsInformation().AsEnumerable(); var filter = new ParkingSlotFilter(); var matchedItems = filter.Filter(filledSlots, colorCriteria); if (matchedItems.Count() == 0) { Console.WriteLine("Not Found"); return; } foreach (var item in matchedItems) { Console.Write(item.VehicleInSlot.VehicleNumber + ","); } } else { Console.WriteLine("Please provide appropriate Color"); } } else { Console.Write("Please provide exact Color name as parameter."); } } break; case Commands.SlotNumberForRegistrationNumber: { if (parkingManagement.MaxParkingSlots <= 0) { Console.WriteLine("Please allocate parking slots"); return; } if (commands.Length == 2) { string number = commands[1]; if (!string.IsNullOrEmpty(number)) { var numberCriteria = new VehicleNumberCriteria(number); var filledSlots = parkingManagement.GetParkingSlotsInformation().AsEnumerable(); var filter = new ParkingSlotFilter(); var matchedItems = filter.Filter(filledSlots, numberCriteria); if (matchedItems.Count() == 0) { Console.WriteLine("Not Found"); return; } foreach (var item in matchedItems) { Console.Write(item.SlotNumber + ","); } } else { Console.WriteLine("Please provide appropriate vehicle number"); } } else { Console.Write("Please provide exact vehicle number as parameter."); } } break; case Commands.SlotNumbersForCarsWithColor: { if (parkingManagement.MaxParkingSlots <= 0) { Console.WriteLine("Please allocate parking slots"); return; } if (commands.Length == 2) { ColorEnums color; if (ColorEnums.TryParse(commands[1], true, out color)) { var colorCriteria = new VehicleColorCriteria(color); var filledSlots = parkingManagement.GetParkingSlotsInformation().AsEnumerable(); var filter = new ParkingSlotFilter(); var matchedItems = filter.Filter(filledSlots, colorCriteria); if (matchedItems.Count() == 0) { Console.WriteLine("Not Found"); return; } foreach (var item in matchedItems) { Console.Write(item.SlotNumber + ","); } } else { Console.WriteLine("Please provide appropriate Color"); } } else { Console.Write("Please provide exact Color name as parameter."); } } break; case Commands.Exit: { _interactive = false; } break; case Commands.Status: { if (parkingManagement.MaxParkingSlots <= 0) { Console.WriteLine("Please allocate parking slots"); return; } var slots = parkingManagement.GetParkingSlotsInformation().AsEnumerable(); if (slots.Count() == 0) { Console.WriteLine("Not Found"); return; } Console.WriteLine("Slot No Registration No. Colour"); Console.WriteLine(); foreach (var slot in slots) { Console.WriteLine("{0} {1} {2}", slot.SlotNumber, slot.VehicleInSlot.VehicleNumber, slot.VehicleInSlot.VehicleColor.ToString()); } } break; default: { Console.WriteLine("Please check your command"); } break; } Console.WriteLine(); }