public void When_execute_is_called_return_Option_Set() { var context = new XrmFakedContext(); var optionSet = new Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata { Name = "test" }; context.OptionSetValuesMetadata.Add("test", optionSet); var executor = new RetrieveOptionSetRequestExecutor(); var req = new RetrieveOptionSetRequest { Name = "test" }; var response = ((RetrieveOptionSetResponse)executor.Execute(req, context)); Assert.True(optionSet.Name.Equals(((Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata)response.OptionSetMetadata).Name)); }
/// <summary> /// Hemper method to get the list of Customized attrbiutes metadata /// </summary> /// <param name="attributeMetadatas"></param> /// <returns></returns> public List <AttributeMetadata> GetCustomizedAttributes(List <Microsoft.Xrm.Sdk.Metadata.AttributeMetadata> attributeMetadatas) { var attrCutomizedList = attributeMetadatas.Where(x => x.IsCustomizable.Value == true && x.IsDataSourceSecret == false && x.IsPrimaryId == false && x.IsValidForUpdate == true && x.DisplayName.UserLocalizedLabel != null) .OrderBy(x => x.DisplayName.UserLocalizedLabel.Label).ToList(); var attrListMetadata = new List <AttributeMetadata>(); foreach (var attrMetadata in attrCutomizedList) { var attrType = attrMetadata.AttributeType.Value.ToString(); var attrLogicalName = attrMetadata.LogicalName; var attrDisplayName = attrMetadata.DisplayName.UserLocalizedLabel.Label; Microsoft.Xrm.Sdk.Metadata.OptionSetMetadata optionSetMetadata = null; List <string> entiRefForLookUp = null; var allowedRefTypes = (Enum.GetValues(typeof(AllowedRefAttrType))).OfType <object>().Select(o => o.ToString()).ToArray(); if (attrType == AttributeType.Picklist.ToString()) { var pickListMetaData = (Microsoft.Xrm.Sdk.Metadata.PicklistAttributeMetadata)attrMetadata; optionSetMetadata = pickListMetaData.OptionSet; } if (Array.Exists(allowedRefTypes, element => element.ToLower() == attrType.ToLower())) { var lookupMetadata = (Microsoft.Xrm.Sdk.Metadata.LookupAttributeMetadata)attrMetadata; if (lookupMetadata.Targets.Count() > 0) { entiRefForLookUp = lookupMetadata.Targets.ToList(); } } attrListMetadata.Add(new AttributeMetadata { DisplayName = attrDisplayName, LogicalName = attrLogicalName, AttributeType = attrType, TargetSchemaName = entiRefForLookUp, OptionSetMetadata = optionSetMetadata }); } return(attrListMetadata); }