Exemple #1
0
        public void SearchShouldReturnNullWhenNoMatchingElementAvailable()
        {
            ParkingSpot result = null;

            result = _svc.Search(GetFakeParkingSpots(3, Size.Hatchback), Size.Sedan);
            Assert.AreEqual(result, null);
            result = _svc.Search(GetFakeParkingSpots(3, Size.Hatchback), Size.Truck);
            Assert.AreEqual(result, null);
        }
Exemple #2
0
        //Assumption: SpotSize Enum will be maintained in the order of the vehicle size.
        public ParkingSpot AssignParkingSpot(Vehicle vehicle)
        {
            ParkingSpot spot = null;

            //Search spot
            switch (vehicle.VehicleSize)
            {
            case Size.Hatchback:
                spot = (_spotSearchService.Search(_parkingSpots, Size.Hatchback) ?? _spotSearchService.Search(_parkingSpots, Size.Sedan)) ??
                       _spotSearchService.Search(_parkingSpots, Size.Truck);
                break;

            case Size.Sedan:
                spot = _spotSearchService.Search(_parkingSpots, Size.Sedan) ?? _spotSearchService.Search(_parkingSpots, Size.Truck);
                break;

            case Size.Truck:
                spot = _spotSearchService.Search(_parkingSpots, Size.Truck);
                break;

            default:
                throw new InvalidEnumArgumentException("Unsupported vehicle size");
            }

            //Assign spot
            if (spot != null)
            {
                spot.OccupiedVehicle = vehicle;
            }
            return(spot);
        }