public void ValidateParametersAsyncReturnFalseIfParametersareNotFull() { parameters = new List <AdditionalParametersRequest>(); attr = new DocumentTypeAttributeItem(); attr.DataSourceObjects = new List <DataSourceObject>(); string documentType = "documentType"; for (int i = 0; i < 2; i++) { parameters.Add( new AdditionalParametersRequest() { Name = "Name" + i, Value = "Value" + i }); } List <DataSourceObject> dataSourceObjects = new List <DataSourceObject>(); for (int i = 0; i < 4; i++) { List <DataSourceObjectRequiredParameters> requiredParameters = new List <DataSourceObjectRequiredParameters>(); for (int j = 0; j < 4; j++) { requiredParameters.Add(new DataSourceObjectRequiredParameters() { InputParameterName = i + "InputParameterName" + j, PropertyName = i + "PropertyName" + j }); } dataSourceObjects.Add(new DataSourceObject() { Name = "Name" + i, RequiredParameters = requiredParameters }); } attr.DataSourceObjects = dataSourceObjects; List <AttributeParameter> attributeParameters = new List <AttributeParameter>(); attr.Attributes = attributeParameters; _dictionary.Setup(x => x.getDocumentTypeAttributesAsync(It.IsAny <string>())).ReturnsAsync(attr); var res = _documentManagementService.ValidateParametersAsync(documentType, parameters).Result; Assert.IsFalse(res); }
private void prepareDataSourceObjects(string documentType, DocumentTypeAttributeItem docType, List <Models.AdditionalParameters> additionalParameters) { try { foreach (var source in docType.DataSourceObjects) { if (_dataObjects == null) { _dataObjects = new Dictionary <string, object>(); } if (!_dataObjects.ContainsKey(source.Name)) { var myObj = Type.GetType("BusinessLayer.Models.DataSource." + source.Name); var handle = Activator.CreateInstance(myObj); foreach (var param in source.RequiredParameters) { if (!additionalParameters.Exists(x => x.Name == param.InputParameterName)) { throw new MissingFieldException(string.Format("Input additional property doesn't contains item with name {0}", param.InputParameterName)); } if (handle.GetType().GetProperty(param.PropertyName) != null) { handle.GetType().GetProperty(param.PropertyName).SetValue(handle, additionalParameters.First(x => x.Name == param.InputParameterName).Value, null); } else { throw new MissingFieldException(string.Format("Data source object doesn't has property {0}", param.PropertyName)); } } _dataObjects.Add(source.Name, handle); } } } catch (Exception ex) { _logger.Error(ex.Message, ex, "prepareDataSourceObjects"); } }
public async Task <List <AttachmentResponse> > FindDocuments(string documentType, List <Models.AdditionalParametersRequest> filterConditions) { var res = new List <AttachmentResponse>(); DataAccessLayer.DocumentManagement2SoapService.AttributeTypeWithAnyAttribute[] documentTypeAttributes = await getDocumentTypeAttributesAsync(documentType); DocumentTypeAttributeItem docMetadata = await GetDocumentMetadataAsync(documentType); var searchParams = docMetadata.SearchAttributes?.Select(x => x.DataSourceProperty); var filter = getFilters(filterConditions.Where(x => searchParams.Contains(x.Name)).ToList(), docMetadata.SearchAttributes.ToList()); DataAccessLayer.DocumentManagement2SoapService.document[] docs = await _service.FindDocument(filter); docs.ToList().ForEach(doc => { var attach = new AttachmentResponse(); docMetadata.DisplayParameters.ToList().ForEach(displayParameter => { var destAttribute = documentTypeAttributes.FirstOrDefault(x => x.name == displayParameter.AttributeName); var dataType = displayParameter.Type ?? destAttribute?.AnyAttr.First(z => z.Name == "propertyType")?.Value; attach.AttachmentsAttributes.Add( new AttachmentsAttribute() { Name = displayParameter.AttributeName, Value = ChangePropertyValueFormat(doc.AnyAttr.First(z => z.Name == displayParameter.AttributeName).Value, dataType, displayParameter.Format), DisplayName = displayParameter.DisplayName, DisplayOrder = displayParameter.DisplayOrder } ); }); res.Add(attach); }); return(res); }
private void InitTestData() { _dataObjects = new Dictionary <string, object>(); parameters = new List <Models.AdditionalParametersRequest>(); attr = new DocumentTypeAttributeItem(); }
private List <DataAccessLayer.DocumentManagement2SoapService.AttributeTypeAttribute> getDocumentRequestParameters(DocumentTypeAttributeItem docType, List <DataAccessLayer.DocumentManagement2SoapService.AttributeTypeWithAnyAttribute> attributes, List <Models.AdditionalParameters> additionalParameters) { List <DataAccessLayer.DocumentManagement2SoapService.AttributeTypeAttribute> _requiredAttributes = new List <DataAccessLayer.DocumentManagement2SoapService.AttributeTypeAttribute>(); try { foreach (var attribute in docType.Attributes) { var destAttribute = attributes.FirstOrDefault(x => x.name == attribute.AttributeName); var attr = new DataAccessLayer.DocumentManagement2SoapService.AttributeTypeAttribute(); attr.name = attribute.AttributeName; attr.identificationGroup = attribute.IdentificationGroup; attr.isRequired = destAttribute.isRequired; var dataType = destAttribute?.AnyAttr.First(z => z.Name == "propertyType")?.Value; switch (attribute.DataSourceObjectName) { case "additionalParameters": var propertyValue = additionalParameters.First(x => x.Name == attribute.DataSourceProperty)?.Value; attr.Value = ChangePropertyValueFormat(propertyValue, dataType, attribute.Format); break; case "static": attr.Value = attribute.DataSourceValue; break; default: var dataObject = _dataObjects[attribute.DataSourceObjectName]; var attributeValue = dataObject.GetType().GetProperty(attribute.DataSourceProperty).GetValue(dataObject); attr.Value = ChangePropertyValueFormat(attributeValue, dataType, attribute.Format); break; } _requiredAttributes.Add(attr); } return(_requiredAttributes); } catch (Exception ex) { _logger.Error(ex.Message, ex, "getDocumentAttributes"); } return(null); }