Example #1
0
 public void Login_Must_Be_3_Char_Min()
 {
     Employee emp = new Employee {FirstName = "First", LastName = "Last", BirthDate = DateTime.Today, Login = "******" };
     ValidationContext context = new ValidationContext(emp, null, null);
     ValidationException ex = Assert.Throws<ValidationException>(() => Validator.ValidateObject(emp, context, true));
     Assert.That(ex.Message, Is.EqualTo("The field Login must be a string with a minimum length of 3 and a maximum length of 10."));
 }
Example #2
0
 public void First_Name_Is_Required()
 {
     Employee emp = new Employee {LastName = "Last", BirthDate = DateTime.Today, Login = "******"};
     ValidationContext context = new ValidationContext(emp, null, null);
     ValidationException ex = Assert.Throws<ValidationException>(() => Validator.ValidateObject(emp, context, true));
     Assert.That(ex.Message, Is.EqualTo("The Fist name field is required."));
 }
        public ActionResult Create(Employee employee)
        {
            if (ModelState.IsValid)
            {
                Domain.Employee domainEmp = Mapper.Map<Employee, Domain.Employee>(employee);

                if (domainEmp.IsValid())
                {
                    try
                    {
                        _empService.Add(domainEmp);
                        return RedirectToAction("Index");
                    }
                    catch (BusinessRuleException bex)
                    {
                        ModelState.MergeWithBusinessException(bex);
                    }
                }

                ModelState.MergeWithValidatableObject(domainEmp);
            }
            return View(employee);
        }