public void AddAndChangeVehicle_Test() { //arrange Vehicle.RegisterationNumberFormat expectedRegisterationNumber = new Vehicle.RegisterationNumberFormat("Lhr", 1107, 19); string expectedModel = "Toyota-Corolla"; int expectedEngineCC = (int)Vehicle.Engines.CC1800; bool expectedIsAc = true; Vehicle.Colors expectedColor = Vehicle.Colors.White; VehicleType expectedType = new VehicleType(1); //act Vehicle actual = new Driver(48).AddOrChangeVehicle(expectedRegisterationNumber, expectedModel, expectedEngineCC, expectedIsAc, expectedColor, expectedType); //assert Assert.Equal(expectedRegisterationNumber.Alphabets, actual.RegisterationNumber.Alphabets); Assert.Equal(expectedRegisterationNumber.Number, actual.RegisterationNumber.Number); Assert.Equal(expectedRegisterationNumber.Year, actual.RegisterationNumber.Year); Assert.Equal(expectedModel, actual.Model); Assert.Equal(expectedEngineCC, (int)actual.EngineCC); Assert.Equal(expectedColor, actual.VehicleColor); Assert.True(expectedIsAc); }
/// <summary> /// Method use to add a new or change if already had a vehicle. Changing a vehicle will delete the previous one. /// </summary> /// <param name="registerationNumber">Registeration Number of the vehicle provided by the government</param> /// <param name="model">model or make of the vehicle</param> /// <param name="engineCC">Engine of the vehicle</param> /// <param name="isAc">Whether if the vehicle is air conditioned</param> /// <param name="color">Color of the card</param> /// <param name="type">Type of the vehicle</param> /// <returns></returns> public Vehicle AddOrChangeVehicle(Vehicle.RegisterationNumberFormat registerationNumber, string model, int engineCC, bool isAc, Vehicle.Colors color, VehicleType type) { //this code will delete previous vehicle information if exists dbCommand = new SqlCommand("SetVehicleDriver", dbConnection); dbCommand.CommandType = System.Data.CommandType.StoredProcedure; dbCommand.Parameters.Add(new SqlParameter("@uId", System.Data.SqlDbType.BigInt)).Value = id; dbConnection.Open(); try { dbCommand.ExecuteNonQuery(); } catch (SqlException ex) { dbConnection.Close(); throw new DbQueryProcessingFailedException("Driver->AddOrChangeVehicle", ex); } dbConnection.Close(); //this code will create a new vehicle for the driver return(new Vehicle(registerationNumber, model, engineCC, isAc, color, type, this)); }