static void Main(string[] args) { PetValidator petValidator = new PetValidator(); string petsFilename = "..\\..\\..\\data\\pets.txt"; PetsRepository petsRepository = new PetsRepository(petValidator, petsFilename); CustomerValidator customerValidator = new CustomerValidator(); string customersFilename = "..\\..\\..\\data\\customers.txt"; CustomersRepository customersRepository = new CustomersRepository(customerValidator, customersFilename); ServiceValidator serviceValidator = new ServiceValidator(); string servicesFilename = "..\\..\\..\\data\\services.txt"; ServicesRepository servicesRepository = new ServicesRepository(serviceValidator, servicesFilename); VetValidator vetValidator = new VetValidator(); string vetsFilename = "..\\..\\..\\data\\vets.txt"; VetsRepository vetsRepository = new VetsRepository(vetValidator, vetsFilename); AppointmentValidator appointmentValidator = new AppointmentValidator(); string appointmentsFilename = "..\\..\\..\\data\\appointments.txt"; AppointmentsRepository appointmentsRepository = new AppointmentsRepository(appointmentValidator, appointmentsFilename); Controller controller = new Controller(petsRepository, customersRepository, servicesRepository, vetsRepository,appointmentsRepository); runApp(controller); }
private bool ValidatePet(Pet pet) { var petValidator = new PetValidator(); pet.ValidationResult = petValidator.Validate(pet); return(pet.ValidationResult.Errors.Any()); }
public Pet Insert(Pet pet) { var petValidator = new PetValidator(); pet.ValidationResult = petValidator.Validate(pet); if (pet.ValidationResult.Errors.Any()) { return(pet); } return(_petShopRepository.Insert(pet)); }
public void TestPetValidation() { IValidator <Pet> validator = new PetValidator(); Pet validPet = new Pet() { ID = 1, Name = "kiki", Age = 12, Gender = GenderEnum.FEMININ, Species = "koala" }; Pet petInvalid = new Pet() { ID = 2, Name = "", Age = -6, Gender = GenderEnum.UNKNOWN, Species = "" }; //validating a valid pet validator.Validate(validPet); //trying to validate a pet with invalid name, age and species try { validator.Validate(petInvalid); Assert.Fail(); } catch (ValidationException ve) { Assert.AreEqual(ve.Message, "Invalid name!\nInvalid age!\nInvalid species!\n"); } }
private static void Validar(Pet pet) { var validator = new PetValidator(); validator.ValidateAndThrow(pet); }