public void TestInsertCarInTheSameCarShouldReturnErrorMessage()
 {
     var car = new Car("CA1234AA", "memeem", 5);
     this.vehiclePark.InsertCar(car, 1, 1, DateTime.Now);
     var message = this.vehiclePark.InsertCar(car, 1, 2, DateTime.Now);
     Assert.AreEqual(string.Format(Message.DuplicateLicense, "CA1234AA"), message);
 }
        public void Insert_With_ValidSectorNumber_OutOfRangePlaceInSector()
        {
            var car = new Car("C1114CH", "Owner1", 1);
            var expected = this.vehiclePark.InsertCar(car, 5, 2000, DateTime.Now);

            Assert.AreEqual(expected, "There is no place 2000 in sector 5");
        }
Beispiel #3
0
 public void TestExitWhenNoSuchCarInsideShouldReturnErrorStatus()
 {
     var car = new Car("CA1234AA", "memeem", 5);
     this.vehiclePark.InsertCar(car, 1, 1, DateTime.Now);
     var message = this.vehiclePark.ExitVehicle("CA1235BB", DateTime.Now, 100);
     Assert.AreEqual(string.Format(Message.NoSuchVehicle, "CA1235BB"), message);
 }
        public void Insert_With_ZeroSectorNumber_ValidPlaceInSectorNumber_ValidDate()
        {
            var car = new Car("C1112CH", "Owner1", 1);
            var expected = this.vehiclePark.InsertCar(car, 0, 2, DateTime.Now);

            Assert.AreEqual(expected, "There is no sector 0 in the park");
        }
 public void InsertWhenPlaceIsOccupiered()
 {
     var car = new Car("C1234CH", "Owner2", 1);
     this.vehiclePark.InsertCar(new Car("A1234AB", "Owner123", 2), 1, 1, DateTime.Now);
     var expected = this.vehiclePark.InsertCar(car, 1, 1, DateTime.Now);
     Assert.AreEqual(expected, "The place (1,1) is occupied");
 }
        public void InitExit()
        {
            var mockedData = new Mock<IVehicleParkData>();
            mockedData.Setup(m => m.GetVehiclesByOwner("pesho")).Returns(new List<IVehicle>());

            var car1 = new Car("SA1234BB", "ivan", 10);
            var car2 = new Car("SA1234BC", "ivan", 5);
            var car3 = new Car("SA1234BD", "ivan", 3);
            mockedData.Setup(m => m.GetVehiclesByOwner("ivan"))
                .Returns(new List<IVehicle>()
                {
                    car1, car2, car3
                });
            mockedData.Setup(m => m.GetVehicle("SA1234BB"))
                .Returns(car1);
            mockedData.Setup(m => m.GetParkedSpot(car1)).Returns("(1,1)");
            mockedData.Setup(m => m.GetVehicle("SA1234BC"))
                .Returns(car2);
            mockedData.Setup(m => m.GetParkedSpot(car2)).Returns("(1,2)");
            mockedData.Setup(m => m.GetVehicle("SA1234BD"))
                .Returns(car3);
            mockedData.Setup(m => m.GetParkedSpot(car3)).Returns("(1,3)");

            this.vehiclePark = new VehiclePark(10, 10, mockedData.Object);
        }
 public void TestInsertCarInTheSameParkingSlotShouldReturnErrorMessage()
 {
     var car = new Car("CA1234AA", "memeem", 5);
     this.vehiclePark.InsertCar(car, 1, 1, DateTime.Now);
     var message = this.vehiclePark.InsertCar(car, 1, 1, DateTime.Now);
     Assert.AreEqual(string.Format(Message.PlaceOccupied, 1, 1), message);
 }
 public void InsertWhenAnotherCarIsInseredWithTheSameLicensePlate()
 {
     var car = new Car("C5842CH", "Owner1", 1);
     this.vehiclePark.InsertCar(car, 2, 2, DateTime.Now);
     var expected = this.vehiclePark.InsertCar(car, 3, 3, DateTime.Now);
     Assert.AreEqual(expected, "There is already a vehicle with license plate C5842CH in the park");
 }
        public void Insert_With_OutOfRangeSectorNumber_ValidPlaceInSector()
        {
            var car = new Car("C1113CH", "Owner1", 1);
            var expected = this.vehiclePark.InsertCar(car, 20, 4, DateTime.Now);

            Assert.AreEqual(expected, "There is no sector 20 in the park");
        }
        public void Insert_With_ValidSector_ValidPlaceInSector()
        {
            var car = new Car("C5842CH", "Owner1", 1);

            var expected = this.vehiclePark.InsertCar(car, 1, 1, DateTime.Now);

            Assert.AreEqual(expected, string.Format("Car parked successfully at place (1,1)"));
        }
Beispiel #11
0
 public void TestExitWhenCarInsideShouldReturnTicketStatus()
 {
     var car = new Car("CA1234AA", "memeem", 5);
     this.vehiclePark.InsertCar(car, 1, 1, new DateTime(2000,1,1,1,0,0));
     var message = this.vehiclePark.ExitVehicle("CA1234AA", new DateTime(2000,1,1,2,0,0), 1000);
     var ticket = new Ticket(car, 1000, "(1,1)", 1);
     Assert.AreEqual(ticket.ToString(), message);
 }
        public void TestGetStatusWhenFilledShouldReturnFilledStatus()
        {
            var car = new Car("CA1234AA", "memeem", 5);
            var car1 = new Car("CA1234AB", "memeem", 5);
            this.vehiclePark.InsertCar(car, 1, 1, DateTime.Now);
            this.vehiclePark.InsertCar(car1, 1, 2, DateTime.Now);

            var message = this.vehiclePark.GetStatus();
            var status = @"Sector 1: 2 / 2 (100% full)
            Sector 2: 0 / 2 (0% full)";

            Assert.AreEqual(status, message);
        }
        public void TestFindVehcleWhenPresentShouldReturnVehicleStatus()
        {
            var mockedData = new Mock<IVehicleParkData>();
            var car1 = new Car("SA1234BB", "ivan", 10);
            var car2 = new Car("SA1234BC", "ivan", 5);
            var car3 = new Car("SA1234BD", "ivan", 3);

            mockedData
                .Setup(m => m.GetVehicle(car1.LicensePlate))
                .Returns(car1);
            mockedData.Setup(m => m.GetParkedSpot(car1)).Returns("(1,1)");
            mockedData
                .Setup(m => m.GetVehicle(car2.LicensePlate))
                .Returns(car2);
            mockedData.Setup(m => m.GetParkedSpot(car2)).Returns("(1,2)");
            mockedData
                .Setup(m => m.GetVehicle(car3.LicensePlate))
                .Returns(car3);
            mockedData.Setup(m => m.GetParkedSpot(car3)).Returns("(1,3)");

            this.vehiclePark = new VehiclePark(10, 10, mockedData.Object);

            var message1 = this.vehiclePark.FindVehicle(car1.LicensePlate);
            var expected1 =
            @"Car [SA1234BB], owned by ivan
            Parked at (1,1)";
            Assert.AreEqual(expected1, message1);

            var message2 = this.vehiclePark.FindVehicle(car2.LicensePlate);
            var expected2 =
            @"Car [SA1234BC], owned by ivan
            Parked at (1,2)";
            Assert.AreEqual(expected2, message2);

            var message3 = this.vehiclePark.FindVehicle(car3.LicensePlate);
            var expected3 =
            @"Car [SA1234BD], owned by ivan
            Parked at (1,3)";
            Assert.AreEqual(expected3, message3);
        }
 public void TestInsertCarInInvalidSectorhouldReturnErrorMessage()
 {
     var car = new Car("CA1234AA", "memeem", 5);
     var message = this.vehiclePark.InsertCar(car, 11, 1, DateTime.Now);
     Assert.AreEqual(string.Format(Message.NoSector, 11), message);
 }
        public string InsertCar(Car car, int sector, int place, DateTime time)
        {
            if (sector > this.layout.Sectors)
            {
                return string.Format("There is no sector {0} in the park", sector);
            }

            if (place > this.layout.PlacesPerSector)
            {
                return string.Format("There is no place {0} in sector {1}", place, sector);
            }

            if (this.data.VehiclesBySectorAndPlace.ContainsKey(
                string.Format("({0},{1})", sector, place)))
            {
                return string.Format("The place ({0},{1}) is occupied", sector, place);
            }

            if (this.data.VehiclesByLicensePlate.ContainsKey(car.LicensePlate))
            {
                return string.Format(
                    "There is already a vehicle with license plate {0} in the park",
                    car.LicensePlate);
            }

            this.data.SectorAndPlaceByVehicle[car] = string.Format("({0},{1})", sector, place);
            this.data.VehiclesBySectorAndPlace[string.Format("({0},{1})", sector, place)] = car;
            this.data.VehiclesByLicensePlate[car.LicensePlate] = car;
            this.data.TimesByVehicles[car] = time;
            this.data.VehiclesByOwner[car.Owner].Add(car);
            this.data.PlacesTakenInSectors[sector - 1]++;

            return string.Format("{0} parked successfully at place ({1},{2})", car.GetType().Name, sector, place);
        }
 public void TestInsertCarWhenNoOtherCarsInTheParkShouldReturnSuccessMessage()
 {
     var car = new Car("CA1234AA", "memeem", 5);
     var message = this.vehiclePark.InsertCar(car, 1, 1, DateTime.Now);
     Assert.AreEqual(string.Format(Message.ParkedSucessfully, "Car", 1, 1), message);
 }
Beispiel #17
0
 public string InsertCar(Car car, int sector, int placeNumber, DateTime startTime)
 {
     return this.InsertVehicle(car, sector, placeNumber, startTime);
 }
Beispiel #18
0
        public string Execute(ICommand c)
        {
            if (c.Name != "SetupPark" && this.vehiclePark == null)
            {
                return "The vehicle park has not been set up";
            }

            switch (c.Name)
            {
                case "SetupPark":
                    int sectors = int.Parse(c.Parameters["sectors"]);
                    int placesPerSector = int.Parse(c.Parameters["placesPerSector"]);
                    this.vehiclePark = new VehiclePark(sectors, placesPerSector);
                    return "Vehicle park created";
                case "Park":
                    switch (c.Parameters["type"])
                    {
                        case "car":
                            var car = new Car(c.Parameters["licensePlate"], c.Parameters["owner"], int.Parse(c.Parameters["hours"]));
                            return this.vehiclePark.InsertCar(
                                car,
                                int.Parse(c.Parameters["sector"]),
                                int.Parse(c.Parameters["place"]),
                                DateTime.Parse(c.Parameters["time"], null, DateTimeStyles.RoundtripKind));
                        case "motorbike":
                            return
                                this.vehiclePark.InsertMotorbike(
                                    new Motorbike(
                                        c.Parameters["licensePlate"],
                                        c.Parameters["owner"],
                                        int.Parse(c.Parameters["hours"])),
                                    int.Parse(c.Parameters["sector"]),
                                    int.Parse(c.Parameters["place"]),
                                    DateTime.Parse(c.Parameters["time"], null, DateTimeStyles.RoundtripKind));

                        case "truck":
                            return
                                this.vehiclePark.InsertTruck(
                                    new Truck(
                                        c.Parameters["licensePlate"],
                                        c.Parameters["owner"],
                                        int.Parse(c.Parameters["hours"])),
                                    int.Parse(c.Parameters["sector"]),
                                    int.Parse(c.Parameters["place"]),
                                    DateTime.Parse(c.Parameters["time"], null, DateTimeStyles.RoundtripKind));
                    }

                    break;

                case "Exit":
                    return this.vehiclePark.ExitVehicle(
                        c.Parameters["licensePlate"],
                        DateTime.Parse(c.Parameters["time"], null, DateTimeStyles.RoundtripKind),
                        decimal.Parse(c.Parameters["paid"]));
                case "Status":
                    return this.vehiclePark.GetStatus();
                case "FindVehicle":
                    return this.vehiclePark.FindVehicle(c.Parameters["licensePlate"]);
                case "VehiclesByOwner":
                    return this.vehiclePark.FindVehiclesByOwner(c.Parameters["owner"]);
                default:
                    throw new InvalidOperationException("Invalid command.");
            }

            return string.Empty;
        }