Example #1
0
        public void SearchVehiclesForExistingOwner()
        {
            park.InsertCar(new Car("ЕН7697ВН", "Dinko Todorov", 10), 3, 3, DateTime.Parse(
                               "2015-05-04T10:30:00.0000000",
                               null,
                               System.Globalization.DateTimeStyles.RoundtripKind));

            string expectedResult = "Car [ЕН7697ВН], owned by Dinko Todorov\r\nParked at (3,3)";
            string result         = park.FindVehiclesByOwner("Dinko Todorov");

            Assert.AreEqual(expectedResult, result);
        }
        public void Test_FindVehiclesByOwner_SomeVehiclesMatch_ShouldSortCorrectly()
        {
            var park  = new VehiclePark(3, 3);
            var first = new Car("CA1011AH", "John Smith", 1);

            park.InsertCar(first, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            var second = new Truck("CA2022AH", "John Smith", 1);

            park.InsertTruck(second, 1, 2, new DateTime(2015, 5, 10, 11, 30, 0));
            var third = new Truck("CA9999AH", "John Smith", 1);

            park.InsertTruck(third, 2, 1, new DateTime(2015, 5, 8, 11, 30, 0));
            var fourth = new Motorbike("CA1111AH", "John Smith", 1);

            park.InsertMotorbike(fourth, 2, 2, new DateTime(2015, 5, 8, 11, 30, 0));

            string message = park.FindVehiclesByOwner("John Smith");

            Assert.AreEqual(
                "Motorbike [CA1111AH], owned by John Smith\r\n" +
                "Parked at (2,2)\r\n" +
                "Truck [CA9999AH], owned by John Smith\r\n" +
                "Parked at (2,1)\r\n" +
                "Car [CA1011AH], owned by John Smith\r\n" +
                "Parked at (1,1)\r\n" +
                "Truck [CA2022AH], owned by John Smith\r\n" +
                "Parked at (1,2)",
                message);
        }
        public void Test_FindVehiclesByOwner_EmptyPark_ShouldReturnErrorMessage()
        {
            var    park    = new VehiclePark(2, 2);
            string message = park.FindVehiclesByOwner("Jane Austen");

            Assert.AreEqual("No vehicles by Jane Austen", message);
        }
Example #4
0
        public void TestFindVehicleWithNonExistingOwnerShouldReturnErrorMessage()
        {
            var vehiclePark = new VehiclePark(2, 3);
            var vehicle     = new Car("CA1001HH", "Jay Margareta", 1);

            vehiclePark.InsertCar(vehicle, 1, 2, new DateTime(2015, 05, 04, 10, 30, 00));
            string message = vehiclePark.FindVehiclesByOwner("Margarata");

            Assert.AreEqual("No vehicles by Margarata", message);
        }
        public void Test_FindVehiclesByOwner_NoVehiclesMatch_ShouldReturnErrorMessage()
        {
            var park = new VehiclePark(2, 2);
            var car = new Car("CA1011AH", "John Smith", 1);
            park.InsertCar(car, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            car = new Car("CA3035AH", "Jane Smith", 1);
            park.InsertCar(car, 2, 1, new DateTime(2015, 5, 10, 10, 30, 0));

            string message = park.FindVehiclesByOwner("Jane Austen");
            Assert.AreEqual("No vehicles by Jane Austen", message);
        }
Example #6
0
        public void GetVehicleByOwner_WhenOwnerDoesHaveVehicles_InMockedPark_ShouldWarning()
        {
            var vehicleParkDataMock = new VehicleParkDataMock(DefaultParkSectors);

            var vehicleParkMocked = new VehiclePark(DefaultParkSectors, DefaultParkPlacesPerSector, vehicleParkDataMock);

            string actualResut = vehicleParkMocked.FindVehiclesByOwner("Gosho");

            string expectedResult = $"No vehicles by Stamat";

            Assert.AreEqual(expectedResult, actualResut, "There should not be any vehicle by passed owner!");
        }
        public void Test_FindVehiclesByOwner_SingleVehicle_ShouldReturnTheVehicle()
        {
            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.FindVehiclesByOwner("John Smith");
            Assert.AreEqual(
                "Car [CA1011AH], owned by John Smith\r\n" +
                "Parked at (1,1)",
                message);
        }
Example #8
0
        public void TestFindVehicleByOwnerFail()
        {
            // Arrange
            IVehiclePark vehiclePark     = new VehiclePark(this.CreateMockLayout());
            string       expectedMessage = "No vehicles by Doesn't Exist";

            // Act
            string message = vehiclePark.FindVehiclesByOwner("Doesn't Exist");

            // Assert
            Assert.AreEqual(expectedMessage, message);
        }
        public void Test_FindVehiclesByOwner_NoVehiclesMatch_ShouldReturnErrorMessage()
        {
            var park = new VehiclePark(2, 2);
            var car  = new Car("CA1011AH", "John Smith", 1);

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

            string message = park.FindVehiclesByOwner("Jane Austen");

            Assert.AreEqual("No vehicles by Jane Austen", message);
        }
        public void Test_FindVehiclesByOwner_SingleVehicle_ShouldReturnTheVehicle()
        {
            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.FindVehiclesByOwner("John Smith");

            Assert.AreEqual(
                "Car [CA1011AH], owned by John Smith\r\n" +
                "Parked at (1,1)",
                message);
        }
Example #11
0
        public void TestFindOneVehicleShouldReturnTheVehicleWithTheOwnerAndTheParkingPlace()
        {
            var vehiclePark = new VehiclePark(2, 3);
            var vehicle     = new Car("CA1001HH", "Jay Margareta", 1);

            vehiclePark.InsertCar(vehicle, 1, 2, new DateTime(2015, 05, 04, 10, 30, 00));
            string message = vehiclePark.FindVehiclesByOwner("Jay Margareta");

            var result = new StringBuilder();

            result.AppendLine("Car [CA1001HH], owned by Jay Margareta").Append("Parked at (1,2)");

            Assert.AreEqual(result.ToString(), message);
        }
Example #12
0
        public void TestFindVehicleByOwnerSuccess()
        {
            // Arrange
            IVehiclePark  vehiclePark = new VehiclePark(this.CreateMockLayout());
            StringBuilder sb          = new StringBuilder();

            sb.Append("Car [FF00021AC], owned by Endi");
            sb.Append(Environment.NewLine);
            sb.Append("Parked at (1, 1)");
            sb.Append(Environment.NewLine);
            string expectedMessage = sb.ToString();

            // Act
            string message = vehiclePark.FindVehiclesByOwner("Endi");

            // Assert
            Assert.AreEqual(expectedMessage, message);
        }
 public void Test_FindVehiclesByOwner_EmptyPark_ShouldReturnErrorMessage()
 {
     var park = new VehiclePark(2, 2);
     string message = park.FindVehiclesByOwner("Jane Austen");
     Assert.AreEqual("No vehicles by Jane Austen", message);
 }
Example #14
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);
        }
Example #15
0
        public void TestFindVehicleByOwner_ShouldReturnCorrectResult()
        {
            //Arrange

            var mockedPark = new VehiclePark(this.layout, this.databaseMock.Object);

            var found = this.databaseMock.Object.OwnerNames[this.testCar.Owner].ToList().OrderBy(v => this.database.VehicleArrivalTime[v]).ThenBy(v => v.LicensePlate);

            //Act
            var expectedResult = string.Join(Environment.NewLine, this.Input(found));

            var result = mockedPark.FindVehiclesByOwner(this.testCar.Owner);
            //Assert
            Assert.AreEqual(expectedResult, result);
        }
        public void Test_FindVehiclesByOwner_SomeVehiclesMatch_ShouldSortCorrectly()
        {
            var park = new VehiclePark(3, 3);
            var first = new Car("CA1011AH", "John Smith", 1);
            park.InsertCar(first, 1, 1, new DateTime(2015, 5, 10, 10, 30, 0));
            var second = new Truck("CA2022AH", "John Smith", 1);
            park.InsertTruck(second, 1, 2, new DateTime(2015, 5, 10, 11, 30, 0));
            var third = new Truck("CA9999AH", "John Smith", 1);
            park.InsertTruck(third, 2, 1, new DateTime(2015, 5, 8, 11, 30, 0));
            var fourth = new Motorbike("CA1111AH", "John Smith", 1);
            park.InsertMotorbike(fourth, 2, 2, new DateTime(2015, 5, 8, 11, 30, 0));

            string message = park.FindVehiclesByOwner("John Smith");
            Assert.AreEqual(
                "Motorbike [CA1111AH], owned by John Smith\r\n" +
                "Parked at (2,2)\r\n" +
                "Truck [CA9999AH], owned by John Smith\r\n" +
                "Parked at (2,1)\r\n" +
                "Car [CA1011AH], owned by John Smith\r\n" +
                "Parked at (1,1)\r\n" +
                "Truck [CA2022AH], owned by John Smith\r\n" +
                "Parked at (1,2)",
                message);
        }
 public string[] Execute(VehiclePark vehiclePark)
 {
     return(vehiclePark.FindVehiclesByOwner(Parameters["owner"]));
 }
        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.");

            }
        }