public void DataServiceProviderWrapperShouldFailOnMultipleServiceOperationsWithSameName()
        {
            ResourceType stringType = ResourceType.GetPrimitiveResourceType(typeof(string));
            var duplicateOperation1 = new ServiceOperation("Duplicate", ServiceOperationResultKind.DirectValue, stringType, null, "GET", new[] { new ServiceOperationParameter("p1", stringType) });
            duplicateOperation1.SetReadOnly();
            var duplicateOpration2 = new ServiceOperation("Duplicate", ServiceOperationResultKind.DirectValue, ResourceType.GetPrimitiveResourceType(typeof(int)), null, "GET", new ServiceOperationParameter[0]);
            duplicateOpration2.SetReadOnly();

            var providerWrapper = CreateProviderWrapper(addMetadata: p =>
                                                                     {
                                                                         p.AddServiceOp(duplicateOperation1);
                                                                         p.AddServiceOp(duplicateOpration2);
                                                                     });

            Action getVisibleOperations = () => providerWrapper.GetVisibleOperations().ToList();
            getVisibleOperations.ShouldThrow<DataServiceException>()
                .WithMessage(ErrorStrings.DataServiceProviderWrapper_MultipleServiceOperationsWithSameName("Duplicate"))
                .And.StatusCode.Should().Be(500);
        }
        private static void RunPayloadKindTest(RequestTargetKind requestTargetKind, RequestTargetSource requestTargetSource, ResourceType targetResourceType, bool singleResult, bool isLinkUri, ODataPayloadKind expectedKind)
        {
            var segment = new SegmentInfo
            {
                TargetKind = requestTargetKind,
                TargetSource = requestTargetSource,
                TargetResourceType = targetResourceType,
                SingleResult = singleResult,
                Identifier = "Fake",
            };

            var operation = new ServiceOperation("Fake", ServiceOperationResultKind.Void, null, null, "GET", null);
            operation.SetReadOnly();
            segment.Operation = new OperationWrapper(operation);
            segment.ProjectedProperty = new ResourceProperty("Fake", ResourcePropertyKind.Primitive, ResourceType.GetPrimitiveResourceType(typeof(int)));

            SegmentInfo[] segmentInfos;
            if (isLinkUri)
            {
                segmentInfos = new[]
                {
                    new SegmentInfo(),
                    new SegmentInfo
                    {
                       TargetKind = RequestTargetKind.Link,  
                    },
                    segment
                };
            }
            else
            {
                segmentInfos = new[]
                {
                    new SegmentInfo
                    {
                        Identifier = "Fake",
                    },
                    new SegmentInfo(),
                    segment
                };
            }

            var requestDescription = new RequestDescription(segmentInfos, new Uri("http://temp.org/"));
            requestDescription.ResponsePayloadKind.Should().Be(expectedKind);
        }
        /// <summary>
        /// Ensures that the product caches service operations based on their names.
        /// </summary>
        /// <param name="operation">The operation which may or may-not be cached.</param>
        /// <param name="throwIfAlreadyCached">Whether or not to throw if the operation is already cached.</param>
        /// <returns>The same operation if not cached, or a copy if it was.</returns>
        private ServiceOperation EnforceMetadataCache(ServiceOperation operation, bool throwIfAlreadyCached)
        {
            if (!ProviderImplementationSettings.Current.EnforceMetadataCaching)
            {
                return operation;
            }

            ResourceType resultType = null;
            ResourceSet resultSet = null;
            if (operation.ResourceSet != null)
            {
                // The ResourceSet of a service operation should be cached, but it isnt
                resultSet = this.EnforceMetadataCache(operation.ResourceSet, false, true, false);
                resultType = resultSet.ResourceType;
            }
            else
            {
                // The ResultType of a service operation should be cached, but it isn't
                resultType = this.EnforceMetadataCache(operation.ResultType, false, false);
            }

            if (this.serviceOperationCache.Add(operation.Name))
            {
                return operation;
            }

            ExceptionUtilities.Assert(!throwIfAlreadyCached, "Service operation '{0}' was resolved more than once", operation.Name);

            var copy = new ServiceOperation(operation.Name, operation.ResultKind, resultType, resultSet, operation.Method, Enumerable.Empty<ServiceOperationParameter>());
            copy.SetReadOnly();
            return copy;
        }