Beispiel #1
0
        public void GetStatusOnEmptyPark()
        {
            string result         = park.GetStatus();
            string expectedResult = "Sector 1: 0 / 2 (0% full)\r\nSector 2: 0 / 2 (0% full)";

            Assert.AreEqual(expectedResult, result);
        }
        public void Test_GetStatus_EmptyPark_SinglePlaceOnly_ShouldBeCorrect()
        {
            var park = new VehiclePark(1, 1);

            string message = park.GetStatus();
            Assert.AreEqual("Sector 1: 0 / 1 (0% full)", message);
        }
        public void Test_GetStatus_EmptyPark_SinglePlaceOnly_ShouldBeCorrect()
        {
            var park = new VehiclePark(1, 1);

            string message = park.GetStatus();

            Assert.AreEqual("Sector 1: 0 / 1 (0% full)", message);
        }
 public void Test_GetStatus_FullPark_SinglePlaceOnly_ShouldBeCorrect()
 {
     var park = new VehiclePark(1, 1);
     var car = new Car("CA1011AH", "John Smith", 1);
     park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
     string message = park.GetStatus();
     Assert.AreEqual("Sector 1: 1 / 1 (100% full)", message);
 }
        public void Test_GetStatus_FullPark_SinglePlaceOnly_ShouldBeCorrect()
        {
            var park = new VehiclePark(1, 1);
            var car  = new Car("CA1011AH", "John Smith", 1);

            park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            string message = park.GetStatus();

            Assert.AreEqual("Sector 1: 1 / 1 (100% full)", message);
        }
Beispiel #6
0
        public void TestEmptyPark()
        {
            IVehiclePark vehiclePark = new VehiclePark(2, 4);
            string       message     = vehiclePark.GetStatus();

            var result = new StringBuilder();

            result.AppendLine("Sector 1: 0 / 4 (0% full)").Append("Sector 2: 0 / 4 (0% full)");

            Assert.AreEqual(result.ToString(), message);
        }
        public void Test_GetStatus_EmptyPark_Big_ShouldBeCorrect()
        {
            var park = new VehiclePark(3, 3);

            string message = park.GetStatus();
            Assert.AreEqual(
                "Sector 1: 0 / 3 (0% full)\r\n" +
                "Sector 2: 0 / 3 (0% full)\r\n" +
                "Sector 3: 0 / 3 (0% full)",
                message);
        }
        public void GetStatusEmptyParking_ShouldReturnCorrectResult()
        {
            // Arrange
            IVehiclePark park = new VehiclePark(2, 2);

            // Act
            string result = park.GetStatus();
            string expected = "Sector 1: 0 / 2 (0% full)\r\nSector 2: 0 / 2 (0% full)";

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void Test_GetStatus_EmptyPark_Big_ShouldBeCorrect()
        {
            var park = new VehiclePark(3, 3);

            string message = park.GetStatus();

            Assert.AreEqual(
                "Sector 1: 0 / 3 (0% full)\r\n" +
                "Sector 2: 0 / 3 (0% full)\r\n" +
                "Sector 3: 0 / 3 (0% full)",
                message);
        }
        public void Test_ExitVehicle_ShouldRemoveTheVehicle()
        {
            var      park       = new VehiclePark(1, 2);
            var      car        = new Car("CA1011AH", "John Smith", 1);
            DateTime insertDate = new DateTime(2015, 5, 10, 10, 30, 0);

            park.InsertCar(car, 1, 1, insertDate);
            park.ExitVehicle("CA1011AH", insertDate.AddHours(1), 10.0M);

            string message = park.GetStatus();

            Assert.AreEqual("Sector 1: 0 / 2 (0% full)", message);
        }
        public void GetStatusOneVehicle_ShouldReturnCorrectResult()
        {
            // Arrange
            int totalSectors = 2;
            IVehiclePark park = new VehiclePark(totalSectors, 2);
            IVehicle car = new Car("CA1234CA", "Pesho", 3);

            // Act
            park.InsertVehicle(car, 1, 1, new DateTime(2015, 10, 17, 10, 30, 0));
            string result = park.GetStatus();
            string expected = "Sector 1: 1 / 2 (50% full)\r\nSector 2: 0 / 2 (0% full)";

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void GetStatusFullSingleSector_ShouldReturnCorrectResult()
        {
            // Arrange
            IVehiclePark park = new VehiclePark(2, 2);
            IVehicle car3 = new Car("CA1236CA", "Pesho", 3);
            IVehicle car4 = new Car("CA1237CA", "Pesho", 3);

            // Act
            park.InsertVehicle(car3, 2, 1, new DateTime(2015, 10, 17, 10, 30, 0));
            park.InsertVehicle(car4, 2, 2, new DateTime(2015, 10, 17, 10, 30, 0));
            string result = park.GetStatus();
            string expected = "Sector 1: 0 / 2 (0% full)\r\nSector 2: 2 / 2 (100% full)";

            // Assert
            Assert.AreEqual(expected, result);
        }
        public void Test_GetStatus_PartiallyFullPark_Big_ShouldBeCorrect()
        {
            var park = new VehiclePark(3, 3);
            var car = new Car("CA1011AH", "John Smith", 1);
            park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            car = new Car("CA1012AH", "John Smith", 1);
            park.InsertCar(car, 2, 2, new DateTime(2015, 5, 10, 10, 30, 0));
            car = new Car("CA1013AH", "John Smith", 1);
            park.InsertCar(car, 2, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            string message = park.GetStatus();
            Assert.AreEqual(
                "Sector 1: 1 / 3 (33% full)\r\n" +
                "Sector 2: 2 / 3 (67% full)\r\n" +
                "Sector 3: 0 / 3 (0% full)",
                message);
        }
Beispiel #14
0
        public void TestPartialyFullPark()
        {
            IVehiclePark vehiclePark  = new VehiclePark(1, 3);
            var          firstVehicle = new Car("CA1001HH", "Jay Margareta", 1);

            vehiclePark.InsertCar(firstVehicle, 1, 1, new DateTime(2015, 05, 04, 10, 30, 00));
            var thirdVehicle = new Truck("C5842CH", "Jessie Raul", 5);

            vehiclePark.InsertTruck(thirdVehicle, 1, 3, new DateTime(2015, 05, 04, 10, 50, 00));
            string message = vehiclePark.GetStatus();

            var result = new StringBuilder();

            result.Append("Sector 1: 2 / 3 (67% full)");

            Assert.AreEqual(result.ToString(), message);
        }
Beispiel #15
0
        public void Test_GetStatus_PartiallyFullPark_Big_ShouldBeCorrect()
        {
            var park = new VehiclePark(3, 3);
            var car  = new Car("CA1011AH", "John Smith", 1);

            park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            car = new Car("CA1012AH", "John Smith", 1);
            park.InsertCar(car, 2, 2, new DateTime(2015, 5, 10, 10, 30, 0));
            car = new Car("CA1013AH", "John Smith", 1);
            park.InsertCar(car, 2, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            string message = park.GetStatus();

            Assert.AreEqual(
                "Sector 1: 1 / 3 (33% full)\r\n" +
                "Sector 2: 2 / 3 (67% full)\r\n" +
                "Sector 3: 0 / 3 (0% full)",
                message);
        }
Beispiel #16
0
        public void TestGetStatus()
        {
            // Arrage
            VehiclePark vehiclePark = new VehiclePark(new Layout(2, 6, new Database(2)));
            Car         vehicle     = new Car("CA1001HH", "Endi", 2);

            vehiclePark.InsertCar(vehicle, 1, 2, DateTime.Now);
            StringBuilder sb = new StringBuilder();

            sb.Append("Sector 1: 1 / 6 (17 % full)");
            sb.Append(Environment.NewLine);
            sb.Append("Sector 2: 0 / 6 (0 % full)");
            sb.Append(Environment.NewLine);
            string expectedStatus = sb.ToString();

            // Act
            string message = vehiclePark.GetStatus();

            // Assert
            Assert.AreEqual(expectedStatus, message);
        }
        public string Execution(ICommand command)
        {
            if (command.Name != "SetupPark" && VehiclePark == null)
            {
                return "The vehicle park has not been set up";
            }
            switch (command.Name)
            {
                //SetupPark {"sectors": 3, "placesPerSector": 5}
                case "SetupPark":
                    {
                        int iniciatedSectors = int.Parse(command.Parameters["sectors"]);
                        int initiatedPlacesPerSector = int.Parse(command.Parameters["placesPerSector"]);
                        if (iniciatedSectors <= 0)
                        {
                            return "The number of sectors must be positive";
                        }

                        if (initiatedPlacesPerSector <= 0)
                        {
                            return "The number of places per sector must be positive";
                        }

                        this.VehiclePark = new VehiclePark(iniciatedSectors, initiatedPlacesPerSector);
                        return "Vehicle park created"; break;
                    }
                case "Park":
                    {
                        switch (command.Parameters["type"])
                        {
                            case "car":
                                {
                                    return this.ExecuteParkCar(command); break;
                                }
                            case "motorbike":
                                {
                                    return ExecuteParkMotorbike(command); break;

                                }
                            case "truck":
                                {
                                    return ExecuteParkTruck(command); break;
                                }
                            default:
                                throw new IndexOutOfRangeException("Invalid command inside.");
                        }

                        break;
                    }
                case "Exit":
                    {
                        return VehiclePark.ExitVehicle(
                            command.Parameters["licensePlate"],
                           DateTime.Parse(command.Parameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind),
                            decimal.Parse(command.Parameters["paid"])); break;
                    }
                case "Status":
                    {
                        return VehiclePark.GetStatus(); break;
                    }
                case "FindVehicle":
                    {
                        return VehiclePark.FindVehicle(command.Parameters["licensePlate"]); break;
                    }
                case "VehiclesByOwner":
                    {
                        return VehiclePark.FindVehiclesByOwner(command.Parameters["owner"]); break;
                    }
                default:
                    throw new IndexOutOfRangeException("Invalid command.");

            }
        }
Beispiel #18
0
 public string[] Execute(VehiclePark vehiclePark)
 {
     return(vehiclePark.GetStatus());
 }
Beispiel #19
0
        public string Execute(ICommand command)
        {
            if (command.Name != "SetupPark" && VehiclePark == null)
            {
                return("The vehicle park has not been set up");
            }

            var parameters = command.Parameters;

            switch (command.Name)
            {
            case "SetupPark":
                if (int.Parse(parameters["sectors"]) < 0)
                {
                    return("The number of sectors must be positive");
                }

                if (int.Parse(parameters["placesPerSector"]) < 0)
                {
                    return("The number of places per sector must be positive");
                }

                this.VehiclePark = new VehiclePark(
                    int.Parse(parameters["sectors"]),
                    int.Parse(parameters["placesPerSector"]));
                return("Vehicle park created");

            case "Park":
                string   licensePlate  = parameters["licensePlate"];
                string   owner         = parameters["owner"];
                int      reservedHours = int.Parse(parameters["hours"]);
                int      sector        = int.Parse(parameters["sector"]);
                int      place         = int.Parse(parameters["place"]);
                DateTime dateTime      = DateTime.Parse(
                    parameters["time"],
                    null,
                    System.Globalization.DateTimeStyles.RoundtripKind);

                switch (command.Parameters["type"])
                {
                case "car":
                    return(VehiclePark.InsertCar(
                               new Car(licensePlate, owner, reservedHours),
                               sector,
                               place,
                               dateTime));

                case "motorbike":
                    return(VehiclePark.InsertMotorbike(
                               new Motorbike(licensePlate, owner, reservedHours),
                               sector,
                               place,
                               dateTime));

                case "truck":
                    return(VehiclePark.InsertTruck(
                               new Truck(licensePlate, owner, reservedHours),
                               sector,
                               place,
                               dateTime));
                }

                break;

            case "Exit":
                return(VehiclePark.ExitVehicle(
                           parameters["licensePlate"],
                           DateTime.Parse(parameters["time"], null, System.Globalization.DateTimeStyles.RoundtripKind),
                           decimal.Parse(parameters["paid"])));

            case "Status":
                return(VehiclePark.GetStatus());

            case "FindVehicle":
                return(VehiclePark.FindVehicle(
                           parameters["licensePlate"]));

            case "VehiclesByOwner":
                return(VehiclePark.FindVehiclesByOwner(
                           parameters["owner"]));

            default:
                throw new IndexOutOfRangeException("Invalid command.");
            }

            return(string.Empty);
        }
        public void Test_ExitVehicle_ShouldRemoveTheVehicle()
        {
            var park = new VehiclePark(1, 2);
            var car = new Car("CA1011AH", "John Smith", 1);
            DateTime insertDate = new DateTime(2015, 5, 10, 10, 30, 0);
            park.InsertCar(car, 1, 1, insertDate);
            park.ExitVehicle("CA1011AH", insertDate.AddHours(1), 10.0M);

            string message = park.GetStatus();
            Assert.AreEqual("Sector 1: 0 / 2 (0% full)", message);
        }