Esempio n. 1
0
        private void AddEmpButton_Click(object sender, RoutedEventArgs e)
        {
            Employee emp = new Employee();

            emp.FirstName = FirstNameIn.Text;
            emp.LastName  = LastNameIn.Text;
            emp.JobTitle  = JobTitleIn.Text;

            EmployeeValidator validator = new EmployeeValidator();

            var results = validator.Validate(emp);

            if (results.IsValid == false)
            {
                string messageBox = "";
                foreach (ValidationFailure failure in results.Errors)
                {
                    messageBox += $"{failure.ErrorMessage}\n";
                }
                MessageBox.Show($"{messageBox}");
            }
            if (results.IsValid == true)
            {
                SqliteDataAccess.NewEmployee(emp);
                MessageBox.Show($"{emp.FullName} has been added\nto your directory!");
                Close();
                Owner.Activate();
            }
        }
Esempio n. 2
0
 private void InstantiateValidators()
 {
     for (int i = 0; i < 1000; i++)
     {
         _ = new EmployeeValidator();
     }
 }
Esempio n. 3
0
        public void Add_Valid_EmployeeModel_Returns_Success()
        {
            //Arrange
            var options = TestFactory.CreateDbContextOptions("EmployeeAddDb");

            using var context = new AppDbContext(options);

            var validator = new EmployeeValidator(context);


            //add a department
            var department = new Department {
                DepartmentName = "Tech"
            };

            context.Departments.Add(department);
            context.SaveChanges();

            //Act
            var employee = new Employee
            {
                FirstName     = "John",
                LastName      = "Doe",
                ContactNumber = "1234567",
                DepartmentId  = department.DepartmentId
            };
            var result = validator.Validate(employee);

            //Assert
            Assert.Empty(result.Errors);
        }
Esempio n. 4
0
        public void EmployeeValidateName()
        {
            //inicialización
            EmployeeValidatioResult employeeValidatioResult;

            Employee infoEmployee = new Employee
            {
                IDEmployee       = 1,
                IDDocumentType   = -1,
                NameDocumentType = "Cédula de ciudadanía\r\n",
                CodeDocumentType = "CC",
                DocumentNumber   = "123",
                FullName         = "123",
                Name             = "",
                SecondName       = "David",
                Surname          = "",
                SecondSurname    = "Zapata",
                IDSubArea        = 7,
                NameSubArea      = "Control",
                IDArea           = 2,
                NameArea         = "Administración",
                Active           = false,
                URLImage         = null,
                IDUserCreation   = 1,
                DateCreation     = Convert.ToDateTime("2020-04-27T00:00:00")
            };

            //Obtener datos
            employeeValidatioResult = EmployeeValidator.Validate(infoEmployee);

            //Resultado esperado
            Assert.IsFalse(employeeValidatioResult.ISValid);
        }
        public void employeeValidator_returnsFalse_whenEmployeeStartDateAndEndDateDoNotShareSameMonth()
        {
            EmployeeValidator validator = new EmployeeValidator();
            Employee          employee  = new Employee("John Smith", 60000, 4, "January 1", "March 31");

            Assert.False(validator.EmployeeIsValid(employee));
        }
        public void employeeValidator_returnsTrue_whenEmployeeIsValid()
        {
            EmployeeValidator validator = new EmployeeValidator();
            Employee          employee  = new Employee("John Smith", 60000, 4, "March 1", "March 31");

            Assert.True(validator.EmployeeIsValid(employee));
        }
        public void employeeValidator_returnsFalse_whenEmployeeHasOutOfRangeSuperRate(decimal superRate)
        {
            EmployeeValidator validator = new EmployeeValidator();
            Employee          employee  = new Employee("John Smith", 60000, superRate, "March 1", "March 31");

            Assert.False(validator.EmployeeIsValid(employee));
        }
        public void employeeValidator_returnsFalse_whenEmployeeHasEndDateThatIsNotTheLastOfMonth()
        {
            EmployeeValidator validator = new EmployeeValidator();
            Employee          employee  = new Employee("John Smith", 60000, 4, "March 1", "March 30");

            Assert.False(validator.EmployeeIsValid(employee));
        }
        public void employeeValidator_returnsTrue_whenEmployeeHasValidSuperRate_InclusiveRange(decimal superRate)
        {
            EmployeeValidator validator = new EmployeeValidator();
            Employee          employee  = new Employee("John Smith", 60000, 4, "March 1", "March 31");

            Assert.True(validator.EmployeeIsValid(employee));
        }
        public void employeeValidator_returnsFalse_whenEmployeeHasNegativeSalary()
        {
            EmployeeValidator validator = new EmployeeValidator();
            Employee          employee  = new Employee("John Smith", -60000, 4, "March 1", "March 31");

            Assert.False(validator.EmployeeIsValid(employee));
        }
Esempio n. 11
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            Employee model = (Employee)validationContext.ObjectInstance;

            if (string.IsNullOrEmpty(model.Notes))
            {
                return(ValidationResult.Success);
            }
            var res = EmployeeValidator.ValidateProfanity(model.Notes);

            if (!res.isValid)
            {
                string s = "";
                for (int i = 0; i < res.errors.Count; i++)
                {
                    s += res.errors[i];
                    if (i != res.errors.Count - 1)
                    {
                        s += ", ";
                    }
                    else
                    {
                        s += " ";
                    }
                }
                return(new ValidationResult($"Disse ord er ikke tilladt: {s}"));
            }
            return(ValidationResult.Success);
        }
Esempio n. 12
0
 public EmployeeTest()
 {
     _HoursWorked = 10;
     _HourRate    = (double)40;
     _Location    = 1;
     validator    = new EmployeeValidator();
 }
Esempio n. 13
0
        private void CreateEmployee_button_Click(object sender, EventArgs e)
        {
            var employeeInfo = new Employee
            {
                FirstName   = Name_textbox.Text,
                LastName    = Surnname_textbox.Text,
                Phone       = Phone_textbox.Text,
                Description = Details_textbox.Text
            };

            ;
            if (!EmployeeValidator.ValidateFirstOrSecondName(employeeInfo.FirstName))
            {
                NameErrorProvider.SetError(Name_textbox, "Name is not correct.");
            }
            if (!EmployeeValidator.ValidateFirstOrSecondName(employeeInfo.LastName))
            {
                SecondNameErrorProvider.SetError(Surnname_textbox, "Second name is not correct.");
            }
            if (!EmployeeValidator.ValidatePhoneNumber(employeeInfo.Phone, true))
            {
                PhoneNumberErrorProvider.SetError(Phone_textbox, $"Phone number is not correct.{Environment.NewLine}It should contain 10 digits.");
            }
            if (EmployeeValidator.IsValidClientInfo(employeeInfo))
            {
                EmployeeHelper.InsertEmployeeInfo(employeeInfo);
                ClearForm();
                MessageLabel.Show();
                MessageLabel.Text = "Client info was successfully saved!";
                //Thread.Sleep(2000);//queeck dummy way))) TODO: change!
                //MessageLabel.Text = string.Empty;
            }
        }
        public void EditEmployee(Employee employee, bool validateUsername, bool validatePassword)
        {
            IValidator validator = EmployeeValidator.CreateValidator(employee, validateUsername, validatePassword);

            validator.Validate();
            repository.EditEmployee(employee);
        }
Esempio n. 15
0
        public async Task <ActionResult <EmployeeAPIModel> > UpdateCustomer(int id, EmployeeAPIModel employee)
        {
            var validator        = new EmployeeValidator(0);
            var validationResult = await validator.ValidateAsync(employee);

            if (!validationResult.IsValid)
            {
                return(BadRequest(validationResult.Errors));
            }

            var employeeToUpdate = await _employeeService.GetEmployeeById(id);

            if (employeeToUpdate == null)
            {
                return(NotFound());
            }

            var employeeModel = _mapper.Map <EmployeeAPIModel, Employees>(employee);

            await _employeeService.UpdateEmployees(employeeToUpdate, employeeModel);

            employeeModel = await _employeeService.GetEmployeeById(id);

            var employeeAPIModel = _mapper.Map <Employees, EmployeeAPIModel>(employeeModel);

            return(Ok(employeeAPIModel));
        }
        public ActionResult UpdateEmployee(EmployeeModel data)
        {
            if (data == null)
            {
                return(Jsend(JsendResult <List <ValidationFailure> > .Error("Employee data can't be null")));
            }
            var validator = new EmployeeValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    var result = RequestHelper.MakePostWebRequest <EmployeeModel, Jsend <EmployeeModel> >(
                        $"{apiDomain}/api/Employee", data, "PUT");
                    return(Jsend(result));
                }
                catch (WebException ex)
                {
                    Console.WriteLine(ex);
                    return(Jsend(JsendResult.Error("更新員工發生錯誤")));
                }
            }
            List <ValidationFailure> failures = validateResult.Errors.ToList();

            return(Jsend(JsendResult <List <ValidationFailure> > .Fail(failures)));
        }
Esempio n. 17
0
        private void Validate()
        {
            ValidationResult = new EmployeeValidator().Validate(this);


            // Validações adicionais.
        }
Esempio n. 18
0
 // DI ideally uses interfaces for the minimum sake of super easy unit test mocking
 // Pretend these are interfaces *waves magic hands*
 public EmployeeApiController(EmployeeCrud employeeCrud, EmployeeCostCalculator costCalculator,
                              EmployeeValidator employeeValidator)
 {
     _employeeCrud      = employeeCrud;
     _costCalculator    = costCalculator;
     _employeeValidator = employeeValidator;
 }
Esempio n. 19
0
        public Jsend <List <ValidationFailure> > InsertUpdateEmployee(EmployeeModel data)
        {
            if (data == null)
            {
                return(JsendResult <List <ValidationFailure> > .Error("Employee data can't be null"));
            }
            var validator = new EmployeeValidator();
            ValidationResult validateResult = validator.Validate(data);

            if (validateResult.IsValid)
            {
                try
                {
                    var result = _uow.EmployeeTRepository.FindByID(data.EmployeeID);
                    if (result == null)
                    {
                        _uow.EmployeeTRepository.Add(new EmployeeT
                        {
                            EmployeeName     = data.EmployeeName,
                            EmployeePosition = data.EmployeePosition,
                            EmployeePhone    = data.EmployeePhone,
                            Email            = data.Email,
                            BirthdayDate     = data.BirthdayDate,
                            SignInDate       = data.SignInDate,
                            ResignedDate     = data.ResignedDate,
                            IsResigned       = data.IsResigned,
                            CompanyID        = data.CompanyID
                        });
                    }
                    else
                    {
                        _uow.EmployeeTRepository.Update(new EmployeeT
                        {
                            EmployeeID       = data.EmployeeID,
                            EmployeeName     = data.EmployeeName,
                            EmployeePosition = data.EmployeePosition,
                            EmployeePhone    = data.EmployeePhone,
                            Email            = data.Email,
                            BirthdayDate     = data.BirthdayDate,
                            SignInDate       = data.SignInDate,
                            ResignedDate     = data.ResignedDate,
                            IsResigned       = data.IsResigned,
                            Salary           = data.Salary,
                        });
                    }
                    _uow.Commit();
                }
                catch (SqlException ex)
                {
                    _logger.Error(ex);
                    return(JsendResult <List <ValidationFailure> > .Error("InsertUpdateEmployee() InsertUpdate data occured error"));
                }
                return(JsendResult <List <ValidationFailure> > .Success());
            }

            List <ValidationFailure> failures = validateResult.Errors.ToList();

            return(JsendResult <List <ValidationFailure> > .Fail(failures));
        }
Esempio n. 20
0
        public void EmployeeValidator_ShouldHaveRules()
        {
            var employeeValidator = new EmployeeValidator();

            employeeValidator.ShouldHaveValidationErrorFor(v => v.FirstName, null as string);
            employeeValidator.ShouldHaveValidationErrorFor(v => v.PersonType, Domain.Enums.PersonType.Dependent);
            employeeValidator.ShouldHaveChildValidator(v => v.Dependents, typeof(DependentValidator));
        }
Esempio n. 21
0
        public void Should_have_error_when_HourWorked_is_null_or_Negative()
        {
            validator = new EmployeeValidator();

            Employee EmployeeObjTest = BuilderEmployee.Create().WorkedFor(-1).Build();

            validator.ShouldHaveValidationErrorFor(e => e.HoursWorked, EmployeeObjTest);
        }
 public EmployeeComponent(
     ICodingChallengeRepository repository,
     IMapper mapper
     )
 {
     _repository        = repository;
     _mapper            = mapper;
     _employeeValidator = new EmployeeValidator();
 }
        public void NewEmployee(Employee employee)
        {
            IValidator validator = EmployeeValidator.CreateValidator(employee, false, true);

            employee.Credentials.EncriptedPassword = employee.Credentials.EncryptPassword();
            validator.Validate();
            employee.Credentials.EncriptedPassword = employee.Credentials.EncryptPassword();
            repository.NewEmployee(employee);
        }
Esempio n. 24
0
        public ConsoleView()
        {
            IUnityContainer container = new UnityContainer();

            container.RegisterType <IEmployeeRepository, EmployeeRepository>(new ContainerControlledLifetimeManager());
            employeeValidator = container.Resolve <EmployeeValidator>();
            container.RegisterType <IProjectRepository, ProjectRepository>(new ContainerControlledLifetimeManager());
            projectValidator = container.Resolve <ProjectValidator>();
        }
        /// <summary>
        ///异步验证
        /// </summary>
        public static async Task DoValidationAsync(IEmployeeRespository employeeRespository, Employee employee, string validatorType)
        {
            var employeeValidator = new EmployeeValidator(employeeRespository);
            var validatorReresult = await employeeValidator.DoValidateAsync(employee, validatorType);

            if (!validatorReresult.IsValid)
            {
                throw new DomainException(validatorReresult);
            }
        }
Esempio n. 26
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            Employee model = (Employee)validationContext.ObjectInstance;

            if (!EmployeeValidator.EmailValidation(model.Email))
            {
                return(new ValidationResult("Ugyldig email"));
            }
            return(ValidationResult.Success);
        }
        public EmployeeController(IEmployeeService employeeService, ICompanyService companyService, IFunctionService functionService, ISubFunctionService subfunctionService, ICountryService countryService)
            : base(employeeService)
        {
            _employeeService    = employeeService;
            _companyService     = companyService;
            _functionService    = functionService;
            _subfunctionService = subfunctionService;
            _countryService     = countryService;

            _employeeValidator = new EmployeeValidator(_employeeService);
        }
Esempio n. 28
0
        public EmployeeController(IEmployeeService employeeService, ICompanyService companyService, IFunctionService functionService, ISubFunctionService subfunctionService, ICountryService countryService)
            : base(employeeService)
        {
            _employeeService    = employeeService;
            _companyService     = companyService;
            _functionService    = functionService;
            _subfunctionService = subfunctionService;
            _countryService     = countryService;

            _employeeValidator        = new EmployeeValidator(_employeeService);
            _kendoGridQueryableHelper = new KendoGridQueryableHelper(AutoMapperConfig.MapperConfiguration);
        }
        private bool IsEmployeeValid(Employee employee, string mode)
        {
            var validator = new EmployeeValidator(ServiceLocator.Current.GetInstance <IEmployeeManager>(), mode);
            var result    = validator.Validate(employee);

            if (result.IsValid)
            {
                return(true);
            }
            _errorsList = result.Errors;
            return(false);
        }
        public void EmployeeValidator_OnValidade_MustFailValidation()
        {
            // Arrange
            var validator = new EmployeeValidator();

            // Act
            var results = validator.Validate(_employeeFixture.GenerateInvalidEmployee());

            // Assert
            Assert.False(results.IsValid);
            Assert.True(results.Errors.Any());
        }
Esempio n. 31
0
 public Employee()
 {
     Attendance = new List<Attendance>();
     Validator = new EmployeeValidator();
 }