Пример #1
0
        public void AddSeasonalEmployeeTest_Success()
        {
            bool success = false;

            success = Employees.AddSeasonalEmployee("Carl", "Wilson", "123456789", DateTime.Parse("2004-08-17"), "Winter", 16);
            Assert.IsTrue(success);
        }
Пример #2
0
        /// <summary>
        /// Make sure the Seasonal employee succesfully fails if bad data is inputed
        /// </summary>
        /// <returns> success: This bool determines if the Seasonal Employee test failed </returns>
        public static bool testSEmployeeFail()
        {
            bool success           = false;
            bool addSeasonalEmp    = false;
            bool removeSeasonalEmp = false;

            try
            {
                Employees company = new Employees();

                if (!Employees.AddSeasonalEmployee("Sean", "Clarke", "789123456", Convert.ToDateTime("1960/12/24"), "w3inter", 12.00))
                {
                    addSeasonalEmp = true;
                }
                if (!Employees.RemoveSeasonalEmployee("78912f3456"))
                {
                    removeSeasonalEmp = true;
                }

                if (addSeasonalEmp == true ||
                    removeSeasonalEmp == true)
                {
                    success = true;
                }
            }
            catch (Exception)
            {
                success = false;
            }
            return(success);
        }
        /// <summary>
        /// This method takes a pipe delimited string with all details of an employee, parses it, and adds the Employee to the container
        /// </summary>
        /// <param name="fullDetails">The entire details string of the Employee.</param>
        /// <returns>Whether the employee was added to the container or not.</returns>
        public static bool AddAnEmployee(string fullDetails)
        {
            bool added = false;

            try
            {
                //Parse the details
                string[] parsedDetails = fullDetails.Split('|');
                string   empType       = parsedDetails[0];
                string   empFname      = parsedDetails[1];
                string   empLname      = parsedDetails[2];
                string   empSIN        = parsedDetails[3];
                string   empBday       = parsedDetails[4];
                switch (empType)
                {
                case "CT":     //Add a Contract Employee
                    string empStartDate   = parsedDetails[5];
                    string empStopDate    = parsedDetails[6];
                    string empFixedAmount = parsedDetails[7];
                    added = Employees.AddContractEmployee(empFname, empLname, empSIN, Convert.ToDateTime(empBday), Convert.ToDateTime(empStartDate), Convert.ToDateTime(empStartDate), Convert.ToDouble(empFixedAmount));
                    break;

                case "PT":     //Add a Part Time Employee
                    string pempHireDate  = parsedDetails[5];
                    string pempTermDate  = parsedDetails[6];
                    string empHourlyRate = parsedDetails[7];
                    added = Employees.AddParttimeEmployee(empFname, empLname, empSIN, Convert.ToDateTime(empBday), Convert.ToDateTime(pempHireDate), Convert.ToDateTime(pempTermDate), Convert.ToDouble(empHourlyRate));
                    break;

                case "FT":     //Add a Full Time Employee
                    string fempHireDate = parsedDetails[5];
                    string fempTermDate = parsedDetails[6];
                    string empSalary    = parsedDetails[7];
                    added = Employees.AddFulltimeEmployee(empFname, empLname, empSIN, Convert.ToDateTime(empBday), Convert.ToDateTime(fempHireDate), Convert.ToDateTime(fempTermDate), Convert.ToDouble(empSalary));
                    break;

                case "SN":     //Add a Seasonal Employee
                    string empPiecePay = parsedDetails[5];
                    string empSeason   = parsedDetails[6];
                    added = Employees.AddSeasonalEmployee(empFname, empLname, empSIN, Convert.ToDateTime(empBday), empSeason, Convert.ToDouble(empPiecePay));
                    break;
                }
            }
            catch (Exception)
            {
                added = false;
            }
            return(added);
        }
Пример #4
0
        /// <summary>
        /// Make sure the Container Methods succesfully fail if bad data is inputed
        /// </summary>
        /// <returns> success: This bool determines if the test container failed </returns>
        public static bool testContainerFail()
        {
            bool success           = false;
            bool addContractEmp    = false;
            bool addFullTimeEmp    = false;
            bool addPartTimeEmp    = false;
            bool addSeasonalEmp    = false;
            bool findEmployee      = false;
            bool removeContractEmp = false;
            bool removeFullTimeEmp = false;
            bool removePartTimeEmp = false;
            bool removeSeasonalEmp = false;
            bool writeEmp          = false;


            //Create the company
            // And create a failed path for all the methods in the Employees class.
            try
            {
                Employees company = new Employees();

                if (!Employees.AddContractEmployee("Name", "OmniCorp", "603456789", Convert.ToDateTime("1959/12/24"), Convert.ToDateTime("2000/03/06"), Convert.ToDateTime("2002/11/05"), 12000.00))
                {
                    addContractEmp = false;
                }
                if (Employees.AddFulltimeEmployee("Sean", "Clar33ke", "123456789", Convert.ToDateTime("1960/24"), Convert.ToDateTime("2000/03/06"), Convert.ToDateTime("2002/11/05"), 12.00))
                {
                    addFullTimeEmp = false;
                }
                if (Employees.AddParttimeEmployee("Sea11n", "Clarke", "3458912", Convert.ToDateTime("1960/12/24"), Convert.ToDateTime("2000/03/06"), Convert.ToDateTime("2002/11/05"), 12.00))
                {
                    addPartTimeEmp = false;
                }
                if (Employees.AddSeasonalEmployee("Sean", "Clarke", "789123456", Convert.ToDateTime("1960/12/24"), "season", 12.00))
                {
                    addSeasonalEmp = false;
                }

                string foundEmp = Employees.FindAnEmployee("1234567");

                if (string.IsNullOrWhiteSpace(foundEmp))
                {
                    findEmployee = false;
                }
                if (Employees.RemoveContractEmployee("333456789"))
                {
                    removeContractEmp = false;
                }
                if (Employees.RemoveFulltimeEmployee("23456664"))
                {
                    removeFullTimeEmp = false;
                }
                if (Employees.RemoveParttimeEmployee("4433222344"))
                {
                    removePartTimeEmp = false;
                }
                if (Employees.RemoveSeasonalEmployee("5454545"))
                {
                    removeSeasonalEmp = false;
                }

                if (Employees.WriteEmployeesToDatabase())
                {
                    writeEmp = false;
                }

                // If any of the tests that are supposed to fail, pass. Then the test fails.
                if (addContractEmp == true ||
                    addFullTimeEmp == true ||
                    addPartTimeEmp == true ||
                    addSeasonalEmp == true ||
                    findEmployee == true ||
                    removeContractEmp == true ||
                    removeFullTimeEmp == true ||
                    removePartTimeEmp == true ||
                    removeSeasonalEmp == true ||
                    writeEmp == true)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                success = true;
            }
            return(success);
        }
Пример #5
0
        /// <summary>
        /// Make sure the Container Methods succesfully passes if valid data is inputed
        /// </summary>
        /// <returns> success: This bool determines if the test container passed </returns>
        public static bool testContainerPass()
        {
            bool success           = true;
            bool addContractEmp    = false;
            bool addFullTimeEmp    = false;
            bool addPartTimeEmp    = false;
            bool addSeasonalEmp    = false;
            bool findEmployee      = false;
            bool removeContractEmp = false;
            bool removeFullTimeEmp = false;
            bool removePartTimeEmp = false;
            bool removeSeasonalEmp = false;
            bool writeEmp          = false;


            //Create the company
            // And create a happy path for all the methods in the Employees class.
            try
            {
                Employees company = new Employees();

                if (Employees.AddContractEmployee("", "OmniCorp", "603456789", Convert.ToDateTime("1960/12/24"), Convert.ToDateTime("2000/03/06"), Convert.ToDateTime("2002/11/05"), 12000.00))
                {
                    addContractEmp = true;
                }
                if (Employees.AddFulltimeEmployee("Sean", "Clarke", "123456789", Convert.ToDateTime("1960/12/24"), Convert.ToDateTime("2000/03/06"), Convert.ToDateTime("2002/11/05"), 12.00))
                {
                    addFullTimeEmp = true;
                }
                if (Employees.AddParttimeEmployee("Sean", "Clarke", "345678912", Convert.ToDateTime("1960/12/24"), Convert.ToDateTime("2000/03/06"), Convert.ToDateTime("2002/11/05"), 12.00))
                {
                    addPartTimeEmp = true;
                }
                if (Employees.AddSeasonalEmployee("Sean", "Clarke", "789123456", Convert.ToDateTime("1960/12/24"), "winter", 12.00))
                {
                    addSeasonalEmp = true;
                }

                string foundEmp = Employees.FindAnEmployee("123456789");
                if (!string.IsNullOrWhiteSpace(foundEmp))
                {
                    findEmployee = true;
                }
                if (Employees.RemoveContractEmployee("603456789"))
                {
                    removeContractEmp = true;
                }
                if (Employees.RemoveFulltimeEmployee("123456789"))
                {
                    removeFullTimeEmp = true;
                }
                if (Employees.RemoveParttimeEmployee("345678912"))
                {
                    removePartTimeEmp = true;
                }
                if (Employees.RemoveSeasonalEmployee("789123456"))
                {
                    removeSeasonalEmp = true;
                }

                if (Employees.WriteEmployeesToDatabase())
                {
                    writeEmp = true;
                }

                // If any of the tests failed then this Container test failed.
                if (addContractEmp == false ||
                    addFullTimeEmp == false ||
                    addPartTimeEmp == false ||
                    addSeasonalEmp == false ||
                    findEmployee == false ||
                    removeContractEmp == false ||
                    removeFullTimeEmp == false ||
                    removePartTimeEmp == false ||
                    removeSeasonalEmp == false ||
                    writeEmp == false)
                {
                    throw new Exception();
                }
            }
            catch (Exception)
            {
                success = false;
            }
            return(success);
        }