コード例 #1
0
        public void ThreeCarsParkedAndGivenTheRegistrationNumber()
        {
            //Given:
            VehicleDetailsModel[] vehicleDetails = new VehicleDetailsModel[3];
            vehicleDetails[0] = new VehicleDetailsModel
            {
                RegistrationNumber = "ka-01-hh-1111",
                Color = "green"
            };
            vehicleDetails[1] = new VehicleDetailsModel
            {
                RegistrationNumber = "ka-01-hh-1112",
                Color = "green"
            };
            vehicleDetails[2] = new VehicleDetailsModel
            {
                RegistrationNumber = "ka-01-hh-1113",
                Color = "green"
            };
            string registrationNumber = "ka-01-hh-1112";
            //When: I call SlotByRegistrationNumber object
            int result = _slotByRegistrationNumber.GetSlotNumber(vehicleDetails, registrationNumber);

            //Then: I get 2
            Assert.AreEqual(2, result);
        }
コード例 #2
0
        public void SearchedRegistrationNumberNoFound()
        {
            //Given:
            VehicleDetailsModel[] vehicleDetails = new VehicleDetailsModel[3];
            vehicleDetails[0] = new VehicleDetailsModel
            {
                RegistrationNumber = "ka-01-hh-1111",
                Color = "green"
            };
            vehicleDetails[1] = new VehicleDetailsModel
            {
                RegistrationNumber = "ka-01-hh-1112",
                Color = "green"
            };
            vehicleDetails[2] = new VehicleDetailsModel
            {
                RegistrationNumber = "ka-01-hh-1113",
                Color = "green"
            };
            string registrationNumber = "ka-01-hh-1114";
            //When: I call SlotByRegistrationNumber object
            int result = _slotByRegistrationNumber.GetSlotNumber(vehicleDetails, registrationNumber);

            //Then: I get -1
            Assert.AreEqual(-1, result);
        }
コード例 #3
0
        public void Three_Cars_With_Green_And_Given_Color_as_Red()
        {
            //Given: 1st car with registration number 'ka-01-hh-1111' and color 'green'
            //And: 2nd car with registration number 'ka-01-hh-1112' and color 'green'
            //And: 3rd car with registration number 'ka-01-hh-1113' and color 'green'
            VehicleDetailsModel[] vehicleDetails = new VehicleDetailsModel[3];
            vehicleDetails[0] = new VehicleDetailsModel
            {
                Color = "green",
                RegistrationNumber = "ka-01-hh-1111"
            };
            vehicleDetails[1] = new VehicleDetailsModel
            {
                Color = "green",
                RegistrationNumber = "ka-01-hh-1112"
            };
            vehicleDetails[2] = new VehicleDetailsModel
            {
                Color = "green",
                RegistrationNumber = "ka-01-hh-1113"
            };
            string color = "red";

            //When: I call VehicleByColor object
            string[] result = _vehicleByColor.GetRegistrationNumbers(vehicleDetails, color);
            //Then: I get a string array of length 0
            Assert.AreEqual(0, result.Length);
        }
コード例 #4
0
        public void ExecuteCommand()
        {
            //Given: command as 'park KA-01-HH-1234 White'
            string command = "park KA-01-HH-1234 White";
            //When: I call Park object
            VehicleDetailsModel vehivleDetail = new VehicleDetailsModel
            {
                RegistrationNumber = "KA-01-HH-1234",
                Color = "White"
            };

            _mockParkingVehicle.Setup(x => x.GetDetail(It.IsAny <string>())).Returns(vehivleDetail);
            _mockValidateVeicleDetails.Setup(x => x.Validate(It.IsAny <VehicleDetailsModel>())).Returns(string.Empty);
            _mockParkingRepository.Setup(x => x.GetEmptySlotIndex()).Returns(0);
            _mockParkingRepository.Setup(x => x.ParkVehicle(It.IsAny <VehicleDetailsModel>(), It.IsAny <int>())).Returns(0);
            _mockParkSuccessMessage.Setup(x => x.CreateMessage(It.IsAny <int>())).Returns("Allocated slot number: 1");
            string result = _commandExecutorSelector.ExecuteCommand(command);

            //Then: Method Validate, GetDetail, GetEmptySlotIndex, ParkVehicle, CreateMessage executes once
            _mockParkingVehicle.Verify(x => x.GetDetail(It.IsAny <string>()), Times.Once());
            _mockValidateVeicleDetails.Verify(x => x.Validate(It.IsAny <VehicleDetailsModel>()), Times.Once());
            _mockParkingRepository.Verify(x => x.GetEmptySlotIndex(), Times.Once());
            _mockParkingRepository.Verify(x => x.ParkVehicle(It.IsAny <VehicleDetailsModel>(), It.IsAny <int>()), Times.Once());
            _mockParkSuccessMessage.Verify(x => x.CreateMessage(It.IsAny <int>()), Times.Once());
        }
コード例 #5
0
ファイル: VehicleTest.cs プロジェクト: indigos33k3r/MegaMine
        public async void VehicleServiceUpdate()
        {
            // Arrange
            this.VehicleReferrentialTables();
            this.VehicleTable();
            this.VehicleServiceTable();

            await this.SaveChangesAsync(this.FleetDbContext);

            VehicleServiceModel model = new VehicleServiceModel()
            {
                VehicleServiceId = 1, VehicleId = 1, MiscServiceCost = 200, ServiceDate = new DateTime(2016, 10, 1)
            };

            // Act
            AjaxModel <VehicleDetailsModel> ajaxModel = await this.Controller.VehicleServiceUpdate(model);

            VehicleDetailsModel vehicle = ajaxModel.Model;

            // Assert
            Assert.Equal(ajaxModel.Message, FleetMessages.VehicleServiceSaveSuccess);
            Assert.Equal(vehicle.ServiceDate, new DateTime(2016, 10, 1));
            Assert.Equal(vehicle.ServiceCost, 400M);
            Assert.Equal(vehicle.ServiceRecord.Count, 2);
        }
コード例 #6
0
ファイル: Park.cs プロジェクト: rahulchrty/ParkingLot
        public string ExecuteCommand(string command)
        {
            string message    = string.Empty;
            int    slotNumber = 0;

            try
            {
                VehicleDetailsModel vehicleDetail = _parkingVehicle.GetDetail(command);
                message = _validateVeicleDetails.Validate(vehicleDetail);
                if (string.IsNullOrEmpty(message))
                {
                    int slotIndex = _parkingRepository.GetEmptySlotIndex();
                    if (slotIndex > -1)
                    {
                        slotNumber = _parkingRepository.ParkVehicle(vehicleDetail, slotIndex);
                        message    = _parkSuccessMessage.CreateMessage(slotNumber);
                    }
                    else
                    {
                        message = "Sorry, parking lot is full";
                    }
                }
                return(message);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
コード例 #7
0
 internal string SaveVehicleDetails(VehicleDetailsModel objVehicleModel)
 {
     using (SqlConnection con = new SqlConnection(ConnectSql.GetConnectionString()))
     {
         try
         {
             con.Open();
             SqlCommand cmd = new SqlCommand("SpAddVehicle", con);
             cmd.CommandType = CommandType.StoredProcedure;
             cmd.Parameters.AddWithValue("@VehicleNo", objVehicleModel.VehicleNo);
             cmd.Parameters.AddWithValue("@DriverName", objVehicleModel.DriverName);
             cmd.Parameters.AddWithValue("@LisenceNo", objVehicleModel.LisenceNo);
             cmd.Parameters.AddWithValue("@GPSId", objVehicleModel.GPSId);
             cmd.Parameters.AddWithValue("@Hospital", objVehicleModel.Hospital);
             cmd.Parameters.AddWithValue("@Address", objVehicleModel.Address);
             cmd.Parameters.AddWithValue("@Password", objVehicleModel.Password);
             return((string)cmd.ExecuteScalar());
         }
         catch (Exception ex)
         {
             return(ex.Message);
         }
         finally
         {
             con.Close();
         }
     }
 }
コード例 #8
0
        public string Validate(VehicleDetailsModel vehivleDetail)
        {
            string message = string.Empty;

            if (vehivleDetail == null)
            {
                message = "Invalid vehicle details";
            }
            return(message);
        }
コード例 #9
0
        public void GivenVehicleDetailsGiven()
        {
            //Given: command as 'park'
            string command = "park";
            //When: I call ParkingVehicle object
            VehicleDetailsModel result = _parkingVehicle.GetDetail(command);

            //Then: I get null
            Assert.IsNull(result);
        }
コード例 #10
0
        public void GivenNoColor()
        {
            //Given: command as 'park KA-01-HH-1234'
            string command = "park KA-01-HH-1234";
            //When: I call ParkingVehicle object
            VehicleDetailsModel result = _parkingVehicle.GetDetail(command);

            //Then: I get null
            Assert.IsNull(result);
        }
コード例 #11
0
        public void GivenNoRegistrationNumber()
        {
            //Given: command as 'park White'
            string command = "park White";
            //When: I call ParkingVehicle object
            VehicleDetailsModel result = _parkingVehicle.GetDetail(command);

            //Then: I get null
            Assert.IsNull(result);
        }
コード例 #12
0
        public void GivenAParkCommandWithResigtrationNumberAndColor()
        {
            //Given: command as 'park KA-01-HH-1234 White'
            string command = "park KA-01-HH-1234 White";
            //When: I call ParkingVehicle object
            VehicleDetailsModel result = _parkingVehicle.GetDetail(command);

            //Then: I get a type of VehicleDetailsModel
            Assert.IsInstanceOfType(result, typeof(VehicleDetailsModel));
        }
コード例 #13
0
        public void GivenAParkCommandWithResigtrationNumberAndColor_Then_Get_The_Coor()
        {
            //Given: command as 'park KA-01-HH-1234 White'
            string command = "park KA-01-HH-1234 White";
            //When: I call ParkingVehicle object
            VehicleDetailsModel result = _parkingVehicle.GetDetail(command);
            //Then: I get Color as 'White'
            string expected = "White";

            Assert.AreEqual(expected, result.Color);
        }
コード例 #14
0
        public void ParkedNoCars_And_Given_Color_As_Black()
        {
            //Given:
            VehicleDetailsModel[] vehicleDetails = new VehicleDetailsModel[0];
            string color = "black";
            //When: I call SlotByColor object
            List <int> result = _slotByColor.GetSlotNumbers(vehicleDetails, color);

            //Then: I get no slot number
            Assert.AreEqual(0, result.Count);
        }
コード例 #15
0
        public void When_VihicleDetailsNotProvided_Then_Get_ErrorMessage()
        {
            //Given:
            VehicleDetailsModel vehivleDetail = null;
            //When: I call ValidateVeicleDetails object
            string result = _validateVeicleDetails.Validate(vehivleDetail);
            //Then: I get 'Invalid vehicle details'
            string expected = "Invalid vehicle details";

            Assert.AreEqual(expected, result);
        }
コード例 #16
0
        public void Geven_NoCarInParkingLot()
        {
            //Given:
            VehicleDetailsModel[] parlingDetails = new VehicleDetailsModel[3];
            //When: I call StatusOutput object
            string result = _statusOutput.Build(parlingDetails);
            //Then:
            StringBuilder expected = new StringBuilder();

            expected.AppendLine("Slot No.   Registration No   Colour");
            Assert.AreEqual(expected.ToString(), result);
        }
コード例 #17
0
        public void SlotCreatedThenGetTrue()
        {
            //Given:

            //When: I call CheckParkingLotCreated object
            VehicleDetailsModel[] storage = new VehicleDetailsModel[2];
            _mockParkingLotRepository.Setup(x => x.GetParkingDetails()).Returns(storage);
            bool result = checkParkingLotCreated.IsCreated();

            //Then: I get true
            Assert.IsTrue(result);
        }
コード例 #18
0
 public int ParkVehicle(VehicleDetailsModel vehicleDetail, int index)
 {
     try
     {
         _storage[index] = vehicleDetail;
         return(index);
     }
     catch (Exception ex)
     {
         throw;
     }
 }
コード例 #19
0
        public void GivenRegistrationNumberAndColor_Then_GetEmptyString()
        {
            //Given: RegistrationNumber as 'KA-01-HH-1234'
            //And: Color as 'Red'
            VehicleDetailsModel vehivleDetail = new VehicleDetailsModel
            {
                Color = "Red",
                RegistrationNumber = "KA-01-HH-1234"
            };
            //When: I call ValidateVeicleDetails object
            string result = _validateVeicleDetails.Validate(vehivleDetail);

            //Then: I get empty string
            Assert.AreEqual(string.Empty, result);
        }
コード例 #20
0
        /// <summary>
        /// Requests detailed information of the selected car
        /// </summary>
        public void GetCarDetails()
        {
            try
            {
                VehicleGetDetailsResult vehicleResult = new VehicleGetDetailsResult(CarId);

                vehicleResult.GetResult();
                details = new VehicleDetailsModel(vehicleResult.Data);
                Settings.TemperatureUnits = details.SettingsTempUnits;
            }
            catch (Exception ex)
            {
                CrestronConsole.PrintLine("SimplTeslaCar.Main.GetCarDetails()::Error getting car details: " + ex.ToString());
            }
        }
コード例 #21
0
        public void ACarWithColorRedParkedAtSlot1_And_Given_Color_As_Red_Then_Get_Slot_As_1()
        {
            //Given:
            VehicleDetailsModel[] vehicleDetails = new VehicleDetailsModel[1];
            vehicleDetails[0] = new VehicleDetailsModel
            {
                Color = "red",
                RegistrationNumber = "ka-01-hh-1111"
            };
            string color = "red";
            //When: I call SlotByColor object
            List <int> result = _slotByColor.GetSlotNumbers(vehicleDetails, color);

            //Then: I get slot as 1
            Assert.AreEqual(1, result[0]);
        }
コード例 #22
0
        public void GivenNoVehicleDetails()
        {
            //Given: command as 'park'
            string command = "park";
            //When: I call Park object
            VehicleDetailsModel vehivleDetail = null;

            _mockParkingVehicle.Setup(x => x.GetDetail(It.IsAny <string>())).Returns(vehivleDetail);
            _mockValidateVeicleDetails.Setup(x => x.Validate(It.IsAny <VehicleDetailsModel>())).Returns("Please provide all require details");
            string result = _commandExecutorSelector.ExecuteCommand(command);

            //Then: Method GetEmptySlotIndex, ParkVehicle, CreateMessage never executes
            _mockParkingRepository.Verify(x => x.GetEmptySlotIndex(), Times.Never());
            _mockParkingRepository.Verify(x => x.ParkVehicle(It.IsAny <VehicleDetailsModel>(), It.IsAny <int>()), Times.Never());
            _mockParkSuccessMessage.Verify(x => x.CreateMessage(It.IsAny <int>()), Times.Never());
        }
コード例 #23
0
        public void One_Car_With_Color_Green_And_Given_Color_as_Green()
        {
            //Given: 1 car with registration number 'ka-01-hh-1111' and color 'green'
            VehicleDetailsModel[] vehicleDetails = new VehicleDetailsModel[1];
            vehicleDetails[0] = new VehicleDetailsModel
            {
                Color = "green",
                RegistrationNumber = "ka-01-hh-1111"
            };
            string color = "green";

            //When: I call VehicleByColor object
            string[] result = _vehicleByColor.GetRegistrationNumbers(vehicleDetails, color);
            //Then: I get a string array of length 1
            Assert.AreEqual(1, result.Length);
        }
コード例 #24
0
        public void OneCarParkedAt1stSlotAndGivenTheRegistrationNumberThenGetSlotAs1()
        {
            //Given:
            VehicleDetailsModel[] vehicleDetails = new VehicleDetailsModel[1];
            vehicleDetails[0] = new VehicleDetailsModel
            {
                RegistrationNumber = "ka-01-hh-1111",
                Color = "green"
            };
            string registrationNumber = "ka-01-hh-1111";
            //When: I call SlotByRegistrationNumber object
            int result = _slotByRegistrationNumber.GetSlotNumber(vehicleDetails, registrationNumber);

            //Then: I get 1
            Assert.AreEqual(1, result);
        }
コード例 #25
0
        public VehicleDetailsModel GetDetail(string command)
        {
            VehicleDetailsModel vehicleDetail = null;

            if (!string.IsNullOrEmpty(command))
            {
                string[] vehicleData = command.Trim().Split(' ');
                if (vehicleData.Length == 3)
                {
                    vehicleDetail = new VehicleDetailsModel
                    {
                        RegistrationNumber = vehicleData[1],
                        Color = vehicleData[2]
                    };
                }
            }
            return(vehicleDetail);
        }
コード例 #26
0
        public void Geven_ParkingDetailsFor1Car()
        {
            //Given:
            VehicleDetailsModel[] parlingDetails = new VehicleDetailsModel[1];
            parlingDetails[0] = new VehicleDetailsModel
            {
                RegistrationNumber = "KA-01-HH-1111",
                Color = "Black"
            };
            //When: I call StatusOutput object
            string result = _statusOutput.Build(parlingDetails);
            //Then:
            StringBuilder expected = new StringBuilder();

            expected.AppendLine("Slot No.   Registration No   Colour");
            expected.AppendLine("1   KA-01-HH-1111   Black");
            Assert.AreEqual(expected.ToString(), result);
        }
コード例 #27
0
        public void One_Car_With_Color_Green_And_Given_Color_as_Green_Then_Get_RegistrationNumber()
        {
            //Given: 1 car with registration number 'ka-01-hh-1111' and color 'green'
            VehicleDetailsModel[] vehicleDetails = new VehicleDetailsModel[1];
            vehicleDetails[0] = new VehicleDetailsModel
            {
                Color = "green",
                RegistrationNumber = "ka-01-hh-1111"
            };
            string color = "green";

            //When: I call VehicleByColor object
            string[] result = _vehicleByColor.GetRegistrationNumbers(vehicleDetails, color);
            //Then: I get 'ka-01-hh-1111'
            string expected = "ka-01-hh-1111";

            Assert.AreEqual(expected, result[0]);
        }
コード例 #28
0
        public void ParkedCarColorAs_Red_And_Given_Color_As_Green()
        {
            //Given: command as "registration_numbers_for_cars_with_colour White"
            string command = "registration_numbers_for_cars_with_colour green";

            //When: I call RegistrationNumbersForCarsWithColour object
            _mockVehicleColor.Setup(x => x.GetColor(It.IsAny <string>())).Returns("green");
            VehicleDetailsModel[] cars = new VehicleDetailsModel[1];
            cars[0] = new VehicleDetailsModel {
                Color = "red", RegistrationNumber = "ka-01-hh-1111"
            };
            _mockParkingRepository.Setup(x => x.GetParkingDetails()).Returns(cars);
            string[] registrationNumber = {};
            _mockVehicleByColor.Setup(x => x.GetRegistrationNumbers(It.IsAny <VehicleDetailsModel[]>(), It.IsAny <string>())).Returns(registrationNumber);
            _commandExecutorSelector.ExecuteCommand(command);
            //Then: Method BuildMessage never executes
            _mockVehicleByColorSuccessMessage.Verify(x => x.BuildMessage(It.IsAny <string[]>()), Times.Never());
        }
コード例 #29
0
        private void btnAddDriver_Click(object sender, EventArgs e)
        {
            bool IsEmptySpace = false;

            if (string.IsNullOrWhiteSpace(combAddress.Text) ||
                string.IsNullOrWhiteSpace(txtDriverName.Text) ||
                string.IsNullOrWhiteSpace(txtGpsId.Text) ||
                string.IsNullOrWhiteSpace(combHospital.Text) ||
                string.IsNullOrWhiteSpace(txtLicenseNo.Text) ||
                string.IsNullOrWhiteSpace(txtPassword.Text))
            {
                MessageBox.Show("Mandatory fields cannot be empty");
                IsEmptySpace = true;
            }

            if (!IsEmptySpace)
            {
                VehicleDetailsModel objVehicleModel = new VehicleDetailsModel
                {
                    Address    = combAddress.SelectedText,
                    DriverName = txtDriverName.Text,
                    GPSId      = txtGpsId.Text,
                    Hospital   = combHospital.SelectedText,
                    LisenceNo  = txtLicenseNo.Text,
                    Password   = txtPassword.Text,
                    VehicleNo  = txtVehicleNo.Text
                };

                DriverBusinessLayer objDriverBusinessLayer = new DriverBusinessLayer();
                string ValidationErrors = objDriverBusinessLayer.Validate(objVehicleModel, txtCnfPassword.Text);

                if (ValidationErrors == "NIL")
                {
                    DriverDataLayer objDataLayer = new DriverDataLayer();
                    string          Response     = objDataLayer.SaveVehicleDetails(objVehicleModel);
                    MessageBox.Show(Response);
                }
                else
                {
                    MessageBox.Show(ValidationErrors);
                }
            }
        }
コード例 #30
0
        public void RegistrationNumberFound()
        {
            //Given: Command as 'slot_number_for_registration_number KA-01-HH-3141'
            string command = "slot_number_for_registration_number KA-01-HH-3141";

            //When: I call SlotNumberForRegistrationNumber object
            _mockVehicleRegistrationNumber.Setup(x => x.GetNumber(It.IsAny <string>())).Returns("KA-01-HH-3141");
            VehicleDetailsModel[] vehicleDetails = new VehicleDetailsModel[1];
            vehicleDetails[0] = new VehicleDetailsModel
            {
                Color = "green",
                RegistrationNumber = "KA-01-HH-3141"
            };
            _mockParkingRepository.Setup(x => x.GetParkingDetails()).Returns(vehicleDetails);
            _mockSlotByRegistrationNumber.Setup(x => x.GetSlotNumber(It.IsAny <VehicleDetailsModel[]>(), It.IsAny <string>())).Returns(1);
            string result = _commandExecutorSelector.ExecuteCommand(command);

            //Then: I get '1'
            Assert.AreEqual("1", result);
        }