public void TestingValidateContract_Employee_Normal()
 {
     bool status = false;
     try {
         Employee testEmployee = new Employee("Jimmy", "White", "246 454 284", "1996/05/03");
         status = testEmployee.Validate();
     }
     catch(EmployeeException ee)
     {
         string errors = ee.GetError();
     }
     
     Assert.AreEqual(true, status);
 }
        public void TestingValidateContract_Employee_Exception()
        {
            Employee testEmployee = new Employee("Jimmy", "White", "36a 389 727", "1996/05/03");

            try
            {
                bool status = testEmployee.Validate();
                Assert.AreEqual(false, status);
            }
            catch (Exception e)
            {
                Assert.AreEqual(true, true);

            }
        }
示例#3
0
        /// <summary>
        /// Function Name: AddEmployee.
        /// The purpose of this function is to replicate the adding of an employee to the database.
        /// It can be expanded on in the future to use widespread but is currently only used for testing purposes.
        /// While testing this functional will ensure that the adding to list is succesfful and that validation is
        /// properly being conducted of the data being added to the database.
        /// </summary>
        /// <param name="entry">This parameter is an object passed in that can be any 1 of the 4 types of employees.</param>
        /// <returns></returns>
        public bool AddEmployee(Employee entry)
        {
            // declare local variables
            bool result;
            Employee genericClass = new Employee();

            // switch on the type of employee passed in
            // and properly cast it
            switch (entry.GetEmployeeType())
            {
                case "CT":
                    genericClass = (ContractEmployee)entry;
                    break;
                case "SN":
                    genericClass = (SeasonalEmployee)entry;
                    break;
                case "FT":
                    genericClass = (FullTimeEmployee)entry;
                    break;
                case "PT":
                    genericClass = (PartTimeEmployee)entry;
                    break;

            }

            // attempt to add the entry to the database
            // if the result is false from the validation return false
            // otherwise attempt to add it to the database if there is an
            // error return false
            try
            {
                result = genericClass.Validate();
                if (result != false)
                {
                    databaseContainer.Add(genericClass);
                    return true;
                }
            }
            catch
            {
                return false;
            }

            return false;
        }
 /**
  * @fn  public bool Add(Employee newEmployee)
  *
  * @brief   Adds a deep copy of newEmployee if it's valid.
  *
  * @param   newEmployee The new employee to add.
  *
  * @return  returns true if the specified Employee is valid and was added, false otherwise.
  */
 public bool Add(Employee newEmployee)
 {
     if(newEmployee.Validate()) {
         logger.LogEventAsync("Employee added: " + Environment.NewLine + newEmployee.Details(), this.GetType().Name);
         employees.Add(newEmployee.DeepCopy());
         return true;
     }
     else {
         return false;
     }
 }
 /**
  * @fn  public bool Modify(int index, Employee newEmployee)
  *
  * @brief   Replaces the Employee at the index with a deep copy of newEmployee if it's valid.
  *
  * @param   index   the index of the employee to modify.
  * @param   newEmployee The new employee use.
  *
  * @throws  System.ArgumentOutOfRangeException
  *              index is less than 0.-or-index is equal to or greater than Count.
  *
  * @return  returns true if the specified Employee is valid and was added, false otherwise.
  */
 public bool Modify(int index, Employee newEmployee)
 {
     if(newEmployee.Validate()) {
         logger.LogEventAsync(
             "Employee modified from: " + Environment.NewLine +
             employees[index].Details() +
             "To: " + Environment.NewLine +
             newEmployee.Details(),
             this.GetType().Name);
         employees[index] = newEmployee.DeepCopy();
         return true;
     } else {
         return false;
     }
 }