private static PropertyInfo GetPropertyForCondition(PackageReaderService source, string contextCondition) { return(source.GetType() .GetProperties() .FirstOrDefault(p => p.GetCustomAttributes <ContextConditionAttribute>() .FirstOrDefault(a => a.MethodToProcess.Equals(contextCondition.ToUpper())) != null)); }
//TODO: hardcoded part - I thing it's fine, because argument is predefined. In this case we don't need to define any property to get value. public static object GetContextConditionParameter(this PackageReaderService source, string contextCondition) { if (string.IsNullOrEmpty(contextCondition)) { return(null); } //if the predefined expression like DigitsNumbers(3), Len(20) if (IsPredefinedConditionExpression(contextCondition)) { int param = GetPredefinedConditionArgument(contextCondition); if (param == -1) { return(null); } return(param); } //other cases PropertyInfo pi = GetPropertyForCondition(source, contextCondition); if (pi == null) { return(null); } return(pi.GetValue(source)); }
//[Fact] //public void DataReaderReadSourceTest() //{ // DataReaderService service = this.GetDataReaderService(); // service.ReadFileData("provozovatel.csv"); // Assert.True(service.IsValid); //} #region SUPPORT FUNCTIONS AND METHODS public PackageReaderService GetPackageType(string packageNumber) { PackageReaderService service = new PackageReaderService(packageNumber); service.Ini(); return(service); }
public void DataReaderIniTest() { string folderSource = "DataSource/30030030-V-2019012108-R-01"; PackageReaderService package = this.GetPackageType(folderSource); DataReaderService service = new DataReaderService(package); Assert.False(string.IsNullOrEmpty(service.DataSourceFolder)); Assert.Equal(folderSource, service.DataSourceFolder); }
private static bool ValidationProcessInitialization(string sourceFolderPath) { try { _packageTypeInstance = new PackageReaderService(sourceFolderPath); if (!_packageTypeInstance.Ini()) { LoggerService.GetGlobalLog().Warn($"Error in ValidationProcessInitialization: {_packageTypeInstance.ErrorMessage}"); throw new ArgumentException(_packageTypeInstance.ErrorMessage); } return(_packageTypeInstance.IsValid); } catch (Exception ex) { WriteFatalErrorInfo("Exception in ValidationProcessInitialization", ex); return(false); } }
public static string GetContextValidationErrorMessageTemplate(this PackageReaderService source, string contextCondition) { if (string.IsNullOrEmpty(contextCondition)) { return(string.Empty); } PropertyInfo pi = GetPropertyForCondition(source, contextCondition); ContextConditionAttribute attribute = pi .GetCustomAttributes <ContextConditionAttribute>() .FirstOrDefault(p => p.MethodToProcess.Equals(contextCondition.ToUpper())); if (attribute == null) { return(string.Empty); } return(attribute.ConditionErrorMessageTemplate); }
private DataReaderService GetDataReaderService() { PackageReaderService package = this.GetPackageType("223454T333-V-2018123116-B-14"); return(new DataReaderService(package)); }