Example #1
0
        //Main Method who calls the AssignParking
        static void Main(string[] args)
        {
            IParkingLotService myTestParkingLot = new ParkingLot(GetFakeParkingLot(), new SpotSearchService());

            ParkingSpot spot;

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);


            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Truck));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Truck));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Truck));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Truck));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Truck));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Hatchback));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Hatchback));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Hatchback));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Hatchback));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Hatchback));
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);

            Console.Read();
        }
Example #2
0
        public static bool UnparkVehicle(this ParkingLot parkingLot, Vehicle vehicle)
        {
            if (parkingLot == null)
            {
                throw new ArgumentNullException(nameof(parkingLot));
            }

            if (vehicle == null)
            {
                throw new ArgumentNullException(nameof(vehicle));
            }

            if (parkingLot.ParkedVehicles.Contains(vehicle))
            {
                parkingLot.ParkedVehicles.Remove(vehicle);
                return(true);
            }

            return(false);
        }
Example #3
0
        public static bool ParkVehicle(this ParkingLot parkingLot, Vehicle vehicle)
        {
            if (parkingLot == null)
            {
                throw new ArgumentNullException(nameof(parkingLot));
            }

            if (vehicle == null)
            {
                throw new ArgumentNullException(nameof(vehicle));
            }

            if (parkingLot.NumberOfSlots > parkingLot.ParkedVehicles.Count)
            {
                parkingLot.ParkedVehicles.Add(vehicle);
                return(true);
            }

            return(false);
        }
Example #4
0
        public static IDictionary <string, decimal> GetTotalMoneyCollectedByVehicleType(this ParkingLot parkingLot)
        {
            if (parkingLot == null)
            {
                throw new ArgumentNullException(nameof(parkingLot));
            }

            return(new ReadOnlyDictionary <string, decimal>(
                       (parkingLot.ParkedVehicles.GroupBy(x => x.GetType().Name).Select(x => new
            {
                x.Key,
                TotalCost = Enumerable.Sum(from y in x
                                           select y.CalculateCost())
            })).ToDictionary(x => x.Key, x => x.TotalCost)));
        }
        static void Main(string[] args)
        {
            ParkingLot myTestParkingLot = new ParkingLot();

            myTestParkingLot.NumOfHatchbacks = 5;
            myTestParkingLot.NumOfSedans     = 5;
            myTestParkingLot.NumOfTrucks     = 5;

            myTestParkingLot.InitializeParkingLot();

            ParkingSpot spot;

            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Sedan
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Sedan
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Sedan
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Sedan
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Sedan
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Sedan
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Sedan
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);


            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Truck
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Truck
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Truck
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Truck
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Truck
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);

            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Hatchback
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Hatchback
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Hatchback
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Hatchback
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);
            spot = myTestParkingLot.AssignParkingSpot(new Vehicle()
            {
                VehicleSize = Size.Hatchback
            });
            Console.WriteLine(spot == null ? "No spot available" : "Assigned spot with size: " + spot.SpotSize);

            Console.Read();
        }
        public void CompleteParkingTest()
        {
            IParkingLotService myTestParkingLot = new ParkingLotManager.ParkingLot(GetFakeParkingLot(), new SpotSearchService());

            ParkingSpot spot;

            //Sedan Getting Sedan
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Assert.That(spot.OccupiedVehicle.VehicleSize == Size.Sedan);
            Assert.AreEqual(spot.SpotSize, Size.Sedan);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Assert.That(spot.OccupiedVehicle.VehicleSize == Size.Sedan);
            Assert.AreEqual(spot.SpotSize, Size.Sedan);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Assert.That(spot.OccupiedVehicle.VehicleSize == Size.Sedan);
            Assert.AreEqual(spot.SpotSize, Size.Sedan);


            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Assert.That(spot.OccupiedVehicle.VehicleSize == Size.Sedan);
            Assert.AreEqual(spot.SpotSize, Size.Sedan);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Assert.That(spot.OccupiedVehicle.VehicleSize == Size.Sedan);
            Assert.AreEqual(spot.SpotSize, Size.Sedan);

            //Sedan getting Trucks spots

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Assert.AreEqual(spot.OccupiedVehicle.VehicleSize, Size.Sedan);
            Assert.AreEqual(spot.SpotSize, Size.Truck);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Sedan));
            Assert.AreEqual(spot.OccupiedVehicle.VehicleSize, Size.Sedan);
            Assert.AreEqual(spot.SpotSize, Size.Truck);

            ////Truck getting truck spots

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Truck));
            Assert.AreEqual(spot.OccupiedVehicle.VehicleSize, Size.Truck);
            Assert.AreEqual(spot.SpotSize, Size.Truck);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Truck));
            Assert.AreEqual(spot.OccupiedVehicle.VehicleSize, Size.Truck);
            Assert.AreEqual(spot.SpotSize, Size.Truck);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Truck));
            Assert.AreEqual(spot.OccupiedVehicle.VehicleSize, Size.Truck);
            Assert.AreEqual(spot.SpotSize, Size.Truck);

            //No parking slots avialable
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Truck));
            Assert.IsNull(spot);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Truck));
            Assert.IsNull(spot);

            //Confirm hatchback slots.
            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Hatchback));
            Assert.AreEqual(spot.OccupiedVehicle.VehicleSize, Size.Hatchback);
            Assert.AreEqual(spot.SpotSize, Size.Hatchback);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Hatchback));
            Assert.AreEqual(spot.OccupiedVehicle.VehicleSize, Size.Hatchback);
            Assert.AreEqual(spot.SpotSize, Size.Hatchback);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Hatchback));
            Assert.AreEqual(spot.OccupiedVehicle.VehicleSize, Size.Hatchback);
            Assert.AreEqual(spot.SpotSize, Size.Hatchback);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Hatchback));
            Assert.AreEqual(spot.OccupiedVehicle.VehicleSize, Size.Hatchback);
            Assert.AreEqual(spot.SpotSize, Size.Hatchback);

            spot = myTestParkingLot.AssignParkingSpot(GetFakeVehicle(Size.Hatchback));
            Assert.AreEqual(spot.OccupiedVehicle.VehicleSize, Size.Hatchback);
            Assert.AreEqual(spot.SpotSize, Size.Hatchback);
        }
Example #7
0
        static void Main(string[] args)
        {
            var        fullSizeVehicle = new FullSizeVehicle();
            ParkingLot parkingLot      = null;

            try
            {
                parkingLot.ParkVehicle(fullSizeVehicle);
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Exceptioin thrown because we are passing in null.");
            }

            try
            {
                parkingLot.UnparkVehicle(fullSizeVehicle);
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Exceptioin thrown because we are passing in null.");
            }

            try
            {
                parkingLot.GetTotalMoneyCollectedByVehicleType();
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Exceptioin thrown because we are passing in null.");
            }

            parkingLot = GetparkingLot();

            try
            {
                parkingLot.ParkVehicle(null);
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Exceptioin thrown because we are passing in null.");
            }

            try
            {
                parkingLot.ParkVehicle(fullSizeVehicle);
                parkingLot.ParkVehicle(new CompactVehicle());
                parkingLot.ParkVehicle(new FullSizeVehicle());
                parkingLot.ParkVehicle(new PickupTruck());
                parkingLot.ParkVehicle(new Motorcycle());
                parkingLot.ParkVehicle(new ElectricVehicle());
                parkingLot.ParkVehicle(new CompactVehicle());
                parkingLot.ParkVehicle(new FullSizeVehicle());
                parkingLot.ParkVehicle(new PickupTruck());
                parkingLot.ParkVehicle(new PickupTruck());
                parkingLot.ParkVehicle(new Motorcycle());

                DisplayAllDetails(parkingLot);

                parkingLot.UnparkVehicle(new PickupTruck());
                DisplayAllDetails(parkingLot);

                parkingLot.UnparkVehicle(fullSizeVehicle);
                DisplayAllDetails(parkingLot);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"Unexpected exception occurred\r\n{ex}");
            }
        }