| | 1 | | using Microsoft.Xrm.Sdk; |
| | 2 | | using Microsoft.Xrm.Sdk.Messages; |
| | 3 | | using System; |
| | 4 | |
|
| | 5 | | namespace FakeXrmEasy.FakeMessageExecutors |
| | 6 | | { |
| | 7 | | public class RetrieveOptionSetRequestExecutor : IFakeMessageExecutor |
| | 8 | | { |
| | 9 | | public bool CanExecute(OrganizationRequest request) |
| 6 | 10 | | { |
| 6 | 11 | | return request is RetrieveOptionSetRequest; |
| 6 | 12 | | } |
| | 13 | |
|
| | 14 | | public OrganizationResponse Execute(OrganizationRequest request, XrmFakedContext ctx) |
| 18 | 15 | | { |
| 18 | 16 | | var retrieveOptionSetRequest = (RetrieveOptionSetRequest)request; |
| | 17 | |
|
| 18 | 18 | | if (retrieveOptionSetRequest.MetadataId != Guid.Empty) //ToDo: Implement retrieving option sets by Id |
| 0 | 19 | | { |
| 0 | 20 | | FakeOrganizationServiceFault.Throw(ErrorCodes.ObjectDoesNotExist, $"Could not find optionset with option |
| 0 | 21 | | } |
| | 22 | |
|
| 18 | 23 | | var name = retrieveOptionSetRequest.Name; |
| | 24 | |
|
| 18 | 25 | | if (string.IsNullOrEmpty(name)) |
| 6 | 26 | | { |
| 6 | 27 | | FakeOrganizationServiceFault.Throw(ErrorCodes.InvalidArgument, "Name is required when optionSet id is no |
| 0 | 28 | | } |
| | 29 | |
|
| 12 | 30 | | if (!ctx.OptionSetValuesMetadata.ContainsKey(name)) |
| 6 | 31 | | { |
| 6 | 32 | | FakeOrganizationServiceFault.Throw(ErrorCodes.ObjectDoesNotExist, string.Format("An OptionSetMetadata wi |
| 0 | 33 | | } |
| | 34 | |
|
| 6 | 35 | | var optionSetMetadata = ctx.OptionSetValuesMetadata[name]; |
| | 36 | |
|
| 6 | 37 | | var response = new RetrieveOptionSetResponse() |
| 6 | 38 | | { |
| 6 | 39 | | Results = new ParameterCollection |
| 6 | 40 | | { |
| 6 | 41 | | { "OptionSetMetadata", optionSetMetadata } |
| 6 | 42 | | } |
| 6 | 43 | | }; |
| | 44 | |
|
| 6 | 45 | | return response; |
| 6 | 46 | | } |
| | 47 | |
|
| | 48 | | public Type GetResponsibleRequestType() |
| 4270 | 49 | | { |
| 4270 | 50 | | return typeof(RetrieveOptionSetRequest); |
| 4270 | 51 | | } |
| | 52 | | } |
| | 53 | | } |