private static void BindIFhirServices(IBindingRoot kernel, List <TypeInitializer> serviceTypes, Type classType) { var serviceType = FindType(serviceTypes, classType); if (serviceType != null) { if (serviceType.Name.Equals(nameof(IFhirService))) { var instance = (IFhirService)Activator.CreateInstance(classType); kernel.Bind <IFhirService>().ToConstant(instance); _amountOfInitializedIFhirServices++; } else if (serviceType.Name.Equals(nameof(IFhirMockupService))) { var instance = (IFhirMockupService)Activator.CreateInstance(classType); kernel.Bind <IFhirMockupService>().ToConstant(instance); _amountOfInitializedIFhirMockupServices++; } else if (serviceType.Name.Equals(nameof(AbstractStructureDefinitionService))) { var structureDefinitionService = (AbstractStructureDefinitionService)Activator.CreateInstance(classType); kernel.Bind <AbstractStructureDefinitionService>().ToConstant(structureDefinitionService); var validator = structureDefinitionService.GetValidator(); if (validator != null) { var profileValidator = new ProfileValidator(validator); kernel.Bind <ProfileValidator>().ToConstant(profileValidator); } _amountOfIFhirStructureDefinitionsInitialized++; } } }
private static void BindIFhirServices(IBindingRoot kernel, List <TypeInitializer> serviceTypes, Type classType) { var serviceType = FindType(serviceTypes, classType); if (serviceType != null) { if (serviceType.Name.Equals(nameof(IFhirService))) { var instance = (IFhirService)Activator.CreateInstance(classType); kernel.Bind <IFhirService>().ToConstant(instance); _amountOfInitializedIFhirServices++; } else if (serviceType.Name.Equals(nameof(IFhirMockupService))) { var instance = (IFhirMockupService)Activator.CreateInstance(classType); kernel.Bind <IFhirMockupService>().ToConstant(instance); _amountOfInitializedIFhirMockupServices++; } else if (serviceType.Name.Equals(nameof(AbstractStructureDefinitionService))) { var structureDefinitionService = (AbstractStructureDefinitionService)Activator.CreateInstance(classType); kernel.Bind <AbstractStructureDefinitionService>().ToConstant(structureDefinitionService); var validator = structureDefinitionService.GetValidator(); if (validator != null) { var addResourceToIssue = ConfigurationManager.AppSettings["AddResourceResultToIssue"]; bool.TryParse(addResourceToIssue, out var boolAddResourceToIssue); var profileValidator = new ProfileValidator(validator, boolAddResourceToIssue); kernel.Bind <ProfileValidator>().ToConstant(profileValidator); } _amountOfIFhirStructureDefinitionsInitialized++; } } }
private static void BindIFhirServices(IBindingRoot kernel, Type fhirService, Type fhidStructureDefinition, Type classType) { if (!fhirService.IsAssignableFrom(classType) && !fhidStructureDefinition.IsAssignableFrom(classType) || classType.IsInterface || classType.IsAbstract) { return; } if (fhirService.IsAssignableFrom(classType)) { var instance = (IFhirService)Activator.CreateInstance(classType); kernel.Bind <IFhirService>().ToConstant(instance); _amountOfInitializedIFhirServices++; } else { var structureDefinitionService = (AbstractStructureDefinitionService)Activator.CreateInstance(classType); kernel.Bind <AbstractStructureDefinitionService>().ToConstant(structureDefinitionService); var validator = structureDefinitionService.GetValidator(); if (validator != null) { var profileValidator = new ProfileValidator(validator); kernel.Bind <ProfileValidator>().ToConstant(profileValidator); } _amountOfIFhirStructureDefinitionsInitialized++; } }
public void Setup() { var assembly = Assembly.GetExecutingAssembly(); var location = new Uri(assembly.GetName().CodeBase); var directoryInfo = new FileInfo(location.AbsolutePath).Directory; Debug.Assert(directoryInfo != null, "directoryInfo != null"); Debug.Assert(directoryInfo.FullName != null, "directoryInfo.FullName != null"); var structureDefinitions = directoryInfo.FullName + @"\Resources\StructureDefinitions"; var includeSubDirectories = new DirectorySourceSettings { IncludeSubDirectories = true }; var directorySource = new DirectorySource(structureDefinitions, includeSubDirectories); var cachedResolver = new CachedResolver(directorySource); var coreSource = new CachedResolver(ZipSource.CreateValidationSource()); var combinedSource = new MultiResolver(cachedResolver, coreSource); var settings = new ValidationSettings { EnableXsdValidation = true, GenerateSnapshot = true, Trace = true, ResourceResolver = combinedSource, ResolveExteralReferences = true, SkipConstraintValidation = false }; var validator = new Validator(settings); _profileValidator = new ProfileValidator(validator); }
public FhirController(ICollection <IFhirService> services, ICollection <IFhirMockupService> mockupServices, ProfileValidator profileValidator, AbstractStructureDefinitionService abstractStructureDefinitionService) { _fhirServices = services; _fhirMockupServices = mockupServices; _profileValidator = profileValidator; _abstractStructureDefinitionService = abstractStructureDefinitionService; }
public void ValidateProfile(Profile profile) { ProfileValidator pv = new ProfileValidator(profile); printer.Title("Checking the profile for use in resource validation"); Report report = pv.Validate(); printer.PrintSummary(report); }
public void One_Null_Argument() { // Setup var validator = new ProfileValidator(); // Act var result = validator.Validate(new ProfileContext("", "LastName", DateTime.Now, "City")); // Assert Assert.IsFalse(result.Successed && result.Errors.Count() == 1); }
public void Correct_Data() { // Setup var validator = new ProfileValidator(); // Act var result = validator.Validate(new ProfileContext("FirstName", "LastName", DateTime.Now, "City")); // Assert Assert.IsTrue(result.Successed); }
public void Date_Greater_Than_Date_Now() { // Setup var validator = new ProfileValidator(); // Act var result = validator.Validate(new ProfileContext("", "LastName", DateTime.MaxValue, "City")); // Assert Assert.IsFalse(result.Successed && result.Errors.Count() == 2); }
public void Null_City() { // Setup var validator = new ProfileValidator(); // Act var result = validator.Validate(new ProfileContext("FirstName", "LastName", null, DateTime.Now, "gender")); // Assert Assert.IsTrue(result.Successed); }
public void Null_Data() { // Setup var validator = new ProfileValidator(); // Act var result = validator.Validate(new ProfileContext("FirstName", "LastName", "London", null, "man")); // Assert Assert.IsTrue(result.Successed); }
public void Date_Greater_Than_Date_Now() { // Setup var validator = new ProfileValidator(); // Act var result = validator.Validate(new ProfileContext("FirstName", "LastName", "London", DateTime.Now.AddDays(1), "man")); // Assert Assert.IsFalse(result.Successed && result.Errors.Count() == 1); }
public void Update(UserDataObject user) { if (user.Id < 1) { throw new CustomException("Invalid user."); } ProfileValidator validator = new ProfileValidator(); if (!validator.IsValid(user)) { throw new FormException(validator.ErrorCodes); } userData.Update(user); }
private static void BindProfileValidator(IKernel kernel) { var setting = ConfigurationManager.AppSettings["EnableValidation"]; var location = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase); var directoryInfo = new FileInfo(location.AbsolutePath).Directory; if (setting == null || !Convert.ToBoolean(setting)) { return; } if (directoryInfo != null) { var instance = new ProfileValidator(true, true, false, directoryInfo.FullName + @"\Resources\StructureDefinitions"); kernel.Bind <ProfileValidator>().ToConstant(instance); } }
// ctor public EditProfileViewModel(ProfileModel _profile) { // Property Profile = _profile; Account = new Auth(Constants.FirebaseApiKey); ValidationRules = new ProfileValidator(); EmailValidators = new NewEmailValidator(); NewEmail = new NewEmailModel(); PasswordValidator = new NewPasswordValidator(); NewPassword = new NewPasswordModel(); // Command PutCommand = new Command(Put); ChangePasswordCommand = new Command(ChangePassword); BrowsePhotoCommad = new Command(BrowsePhoto); ChangeEmailCommand = new Command(ChangeEmail); }
public static IServiceCollection AddProfileValidation(this IServiceCollection services, Action <ProfileValidator> setup) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (setup == null) { throw new ArgumentNullException(nameof(ProfileValidator)); } ProfileValidator validator = new ProfileValidator(); setup(validator); services.AddSingleton(validator); return(services); }
public ActionResult Create(UserProfile model) { var userId = User.Identity.GetUserId(); var newUserProfile = new UserProfile { UserId = userId, UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName, BirthDate = model.BirthDate, CreatedDate = DateTime.Today, Email = User.Identity.GetUserName(), GenderId = model.GenderId, }; var genders = from GenderEnum g in Enum.GetValues(typeof(GenderEnum)) select new EnumValues { ID = (int)g, Name = g.ToString() }; ViewBag.Genders = new SelectList(genders, "ID", "Name"); ProfileValidator validator = new ProfileValidator(); ValidationResult validationResults = validator.Validate(model); // Add the errors from our validation into the error messages variable and return it. if (!validationResults.IsValid) { foreach (var error in validationResults.Errors) { ModelState.AddModelError(error.PropertyName, error.ErrorMessage); } } if (ModelState.IsValid) { _profileManager.Add(newUserProfile); return(RedirectToAction("MyProfile", "UserProfile")); } return(View("Create", model)); }
//Returns if a user's profile is valid. //Validate that the user's name is unique. //Validates that the user has at least two hobbies. public JsonResult ValidateProfile(Profile profile) { var currentProfile = _profileManager.GetByUserId(User.Identity.GetUserId()); ProfileValidator validator = new ProfileValidator(); ValidationResult validationResults = validator.Validate(profile); List <string> errorMessages = new List <string>(); // Add the errors from our validation into the error messages variable and return it. if (!validationResults.IsValid) { foreach (var error in validationResults.Errors) { if (currentProfile != null && error.PropertyName == "UserName") { continue; } errorMessages.Add(error.ErrorMessage); } } return(Json(errorMessages, JsonRequestBehavior.AllowGet)); }
protected override void BeginProcessing() { _validator = new QuickCheckValidator(); }
private static void BindProfileValidator(IServiceCollection services) { var profileValidator = new ProfileValidator(GetValidator(), GetLogger()); services.Add(new ServiceDescriptor(typeof(IProfileValidator), profileValidator)); }
public void Setup() { _profileValidator = new ProfileValidator(ValidationHelper.GetValidator(), GetLogger()); }
public FhirController(ICollection <IFhirService> services, ProfileValidator profileValidator) { _fhirServices = services; _profileValidator = profileValidator; }