コード例 #1
0
        public void SetDateOfTerminationTest()
        {
            ParttimeEmployee pe = new ParttimeEmployee();
            FulltimeEmployee fe = new FulltimeEmployee();

            pe.SetDateofBirth(new DateTime(1990, 5, 13));
            fe.SetDateofBirth(new DateTime(1990, 5, 13));

            pe.SetDateOfHire(new DateTime(2008, 1, 1));
            fe.SetDateOfHire(new DateTime(2008, 1, 1));

            bool retPe = pe.SetDateOfTermination(new DateTime(2010, 6, 6));
            bool retFe = fe.SetDateOfTermination(new DateTime(2010, 6, 6));

            Assert.AreEqual(retPe, true);
            Assert.AreEqual(retFe, true);
        }
コード例 #2
0
ファイル: UIMenu.cs プロジェクト: adam-currie/SET-SQ1-EMS
        /**
         * @fn  private bool ModifyParttimeEmployee(ModifyParttimeEmployee employee, string returnMessage)
         *
         * @brief   allows user to modify this employee using the command line.
         *
         * @param   ModifyParttimeEmployee    The employee to modify.
         * @param   returnMessage       message displayed to the user as the option to return from this method.
         *
         * @return  whether the user canceled.
         */
        private bool ModifyParttimeEmployee(ParttimeEmployee employee, string returnMessage)
        {
            bool done = false;
            bool isCanceled = false;
            //loop until user goes back
            do {
                Console.Clear();
                Console.WriteLine(employee.Details());
                Console.WriteLine("1.   Change First Name(A-Z, a-z, ', -)");
                Console.WriteLine("2.   Change Last Name(A-Z, a-z, ', -)");
                Console.WriteLine("3.   Change Date of birth(yyyy-mm-dd)");
                Console.WriteLine("4.   Change Social insurance number");
                Console.WriteLine("5.   Change Date of hire(yyyy-mm-dd)");
                Console.WriteLine("6.   Change Date of termination(yyyy-mm-dd)");
                Console.WriteLine("7.   Change Hourly Rate");
                Console.WriteLine("8.   Cancel");
                Console.WriteLine("9.   " + returnMessage);

                //get user input until valid
                bool valid;
                do {
                    valid = true;
                    string input = Console.ReadLine();
                    switch (input) {
                        case "1":
                            Console.Write("Enter a new first name:");
                            while (employee.SetFirstName(Console.ReadLine()) == false) {
                                Console.Write("Invalid name, Enter a new first name:");
                            }
                            break;
                        case "2":
                            Console.Write("Enter a new last name:");
                            while (employee.SetLastName(Console.ReadLine()) == false) {
                                Console.Write("Invalid name, Enter a new last name:");
                            }
                            break;
                        case "3":
                            bool dateOfBirthDone = false;
                            while (!dateOfBirthDone) {
                                Console.Write("Enter a new date of birth:");
                                try {
                                    while (employee.SetDateofBirth(DateTime.ParseExact(Console.ReadLine(), "yyyy-MM-dd", CultureInfo.InvariantCulture)) == false) {
                                        Console.Write("Invalid date, Enter a new date of birth:");
                                    }
                                    dateOfBirthDone = true;
                                }
                                catch (FormatException ex) {
                                    Console.WriteLine("Invalid date, Format: yyyy-mm-dd");
                                    dateOfBirthDone = false;
                                }
                            }
                            break;
                        case "4":
                            Console.Write("Enter a new social insurance number:");
                            while (employee.SetSocialInsuranceNumber(Console.ReadLine()) == false){
                                Console.Write("Invalid number, Enter a new social insurance number:");
                            }
                            break;
                        case "5":
                            bool dateOfHireDone = false;
                            while (!dateOfHireDone) {
                                Console.Write("Enter a new date of hire:");
                                try {
                                    while (employee.SetDateOfHire(DateTime.ParseExact(Console.ReadLine(), "yyyy-MM-dd", CultureInfo.InvariantCulture)) == false) {
                                        Console.Write("Invalid date, Enter a new date of hire:");
                                    }
                                    dateOfHireDone = true;
                                }
                                catch (FormatException ex) {
                                    Console.WriteLine("Invalid date, Format: yyyy-mm-dd");
                                    dateOfHireDone = false;
                                }
                            }
                            break;
                        case "6":
                            bool dateOfTerminationDone = false;
                            while (!dateOfTerminationDone)  {
                                Console.Write("Enter a new date of termination:");
                                try {
                                    while (employee.SetDateOfTermination(DateTime.ParseExact(Console.ReadLine(), "yyyy-MM-dd", CultureInfo.InvariantCulture)) == false) {
                                        Console.Write("Invalid date, Enter a new date of termination:");
                                    }
                                    dateOfTerminationDone = true;
                                }
                                catch (FormatException ex) {
                                    Console.WriteLine("Invalid date, Format: yyyy-mm-dd");
                                    dateOfTerminationDone = false;
                                }
                            }
                            break;
                        case "7":
                            bool hourlyRateDone = false;
                            while (!hourlyRateDone) {
                                Console.Write("Enter a new hourly rate:");
                                try  {
                                    while (employee.SetHourlyRate(decimal.Parse(Console.ReadLine())) == false) {
                                        Console.Write("Invalid rate, Enter a new hourly rate:");
                                    }

                                    hourlyRateDone = true;
                                }
                                catch (FormatException ex){
                                    Console.WriteLine("Hourly rate must be a number");
                                    hourlyRateDone = false;
                                }
                            }
                            break;
                        case "8":
                            done = true;//end
                            isCanceled = true;
                            break;
                        case "9":
                            done = true;//end
                            isCanceled = false;
                            break;
                        default:
                            Console.WriteLine("Invalid input, please enter number corrispoding to a menu option:");
                            valid = false;
                            break;
                    }
                } while (!valid);

            } while (!done);

            return isCanceled;
        }
コード例 #3
0
        public void SetDateofBirthTest()
        {
            SeasonalEmployee se = new SeasonalEmployee();
            bool retSe = se.SetDateofBirth(new DateTime(1990, 11, 23));

            ParttimeEmployee pe = new ParttimeEmployee();
            bool retPe = pe.SetDateofBirth(new DateTime(1990, 11, 23));

            FulltimeEmployee fe = new FulltimeEmployee();
            bool retFe = fe.SetDateofBirth(new DateTime(1990, 11, 23));

            ContractEmployee ce = new ContractEmployee();
            bool retCe = ce.SetDateofBirth(new DateTime(1990, 11, 23));

            Assert.AreEqual(retSe, true);
            Assert.AreEqual(retPe, true);
            Assert.AreEqual(retFe, true);
            Assert.AreEqual(retCe, true);
        }