| | | 1 | | using Microsoft.Xrm.Sdk; |
| | | 2 | | using Microsoft.Xrm.Sdk.Messages; |
| | | 3 | | using System; |
| | | 4 | | using System.Linq; |
| | | 5 | | |
| | | 6 | | namespace FakeXrmEasy.FakeMessageExecutors |
| | | 7 | | { |
| | | 8 | | public class RetrieveAttributeRequestExecutor : IFakeMessageExecutor |
| | | 9 | | { |
| | | 10 | | public bool CanExecute(OrganizationRequest request) |
| | 54 | 11 | | { |
| | 54 | 12 | | return request is RetrieveAttributeRequest; |
| | 54 | 13 | | } |
| | | 14 | | |
| | | 15 | | public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx) |
| | 54 | 16 | | { |
| | 54 | 17 | | var req = request as RetrieveAttributeRequest; |
| | | 18 | | |
| | 54 | 19 | | if (string.IsNullOrWhiteSpace(req.EntityLogicalName)) |
| | 6 | 20 | | { |
| | 6 | 21 | | throw new Exception("The EntityLogicalName property must be provided in this request"); |
| | | 22 | | } |
| | | 23 | | |
| | 48 | 24 | | if (string.IsNullOrWhiteSpace(req.LogicalName)) |
| | 6 | 25 | | { |
| | 6 | 26 | | throw new Exception("The LogicalName property must be provided in this request"); |
| | | 27 | | } |
| | | 28 | | |
| | 42 | 29 | | var entityMetadata = ctx.GetEntityMetadataByName(req.EntityLogicalName); |
| | 42 | 30 | | if(entityMetadata == null) |
| | 6 | 31 | | { |
| | 6 | 32 | | throw new Exception(string.Format("The entity metadata with logical name {0} wasn't initialized. Please |
| | | 33 | | } |
| | | 34 | | |
| | 36 | 35 | | if(entityMetadata.Attributes == null) |
| | 6 | 36 | | { |
| | 6 | 37 | | throw new Exception(string.Format("The attribute {0} wasn't found in entity metadata with logical name { |
| | | 38 | | } |
| | | 39 | | |
| | 30 | 40 | | var attributeMetadata = entityMetadata.Attributes |
| | 60 | 41 | | .FirstOrDefault(a => a.LogicalName.Equals(req.LogicalName)); |
| | | 42 | | |
| | 30 | 43 | | if (attributeMetadata == null) |
| | 0 | 44 | | { |
| | 0 | 45 | | throw new Exception(string.Format("The attribute {0} wasn't found in entity metadata with logical name { |
| | | 46 | | } |
| | | 47 | | |
| | 30 | 48 | | var response = new RetrieveAttributeResponse() |
| | 30 | 49 | | { |
| | 30 | 50 | | Results = new ParameterCollection |
| | 30 | 51 | | { |
| | 30 | 52 | | { "AttributeMetadata", attributeMetadata } |
| | 30 | 53 | | } |
| | 30 | 54 | | }; |
| | | 55 | | |
| | 30 | 56 | | return response; |
| | 30 | 57 | | } |
| | | 58 | | |
| | | 59 | | public Type GetResponsibleRequestType() |
| | 4270 | 60 | | { |
| | 4270 | 61 | | return typeof(RetrieveAttributeRequest); |
| | 4270 | 62 | | } |
| | | 63 | | } |
| | | 64 | | } |