/// <summary> /// Find out whether action matches with the ODataUri select function segment /// </summary> /// <param name="action">The action</param> /// <param name="selectSegment">The segment</param> /// <returns>Whether action matches with the function segment</returns> private bool FuctionMatchWithSelectFunctionSegment(Function action, ODataUriSegment selectSegment) { FunctionSegment selectFunctionSegment = selectSegment as FunctionSegment; if (selectFunctionSegment != null && selectFunctionSegment.Function == action) { return(true); } // Sometimes the $select segment is an UnrecognizedSegment UnrecognizedSegment otherTypeOfSelectSegment = selectSegment as UnrecognizedSegment; if (otherTypeOfSelectSegment != null && selectFunctionSegment == null) { string actionName = action.Name; // Determine the if selction segment was <Action Name> or <EntityContainer>.<Action Name> if (otherTypeOfSelectSegment.Value.Contains('.')) { actionName = string.Concat(action.Model.GetDefaultEntityContainer().Name, ".", actionName); } if (otherTypeOfSelectSegment.Value.Equals(actionName, System.StringComparison.OrdinalIgnoreCase)) { return(true); } } return(false); }
private void VerifyQueryResult(ODataRequest request, ODataResponse response, FunctionSegment functionSegment, IVerifyServiceActionQueryResult verifyServiceQueryResult) { EntitySet expectedBindingEntitySet = null; var actionLessUri = ConstructODataUriWithoutActionInformation(this.entityModelSchema.GetDefaultEntityContainer().EntitySets, request.Uri); bool entitySetFound = actionLessUri.TryGetExpectedEntitySet(out expectedBindingEntitySet); ExceptionUtilities.Assert(entitySetFound, "EntitySet not found for Uri {0}", actionLessUri.ToString()); // SDP never applies for actions var preActionQueryValueResult = this.ODataUriEvaluator.Evaluate(actionLessUri, true, false); IDictionary <string, QueryValue> queryValueParametersLookup = new Dictionary <string, QueryValue>(); if (request.Body != null) { queryValueParametersLookup = this.CreateQueryValueParameters(request, functionSegment, queryValueParametersLookup); } var expected = verifyServiceQueryResult.GetExpectedQueryValue(preActionQueryValueResult, queryValueParametersLookup.Values.ToArray()); HttpStatusCode expectedStatusCode = CalculateExpectedStatusCode(functionSegment); string expectedETag = null; SyncHelpers.ExecuteActionAndWait(c => this.Synchronizer.SynchronizeEntireEntitySet(c, expectedBindingEntitySet.Name)); expectedETag = this.VerifyExpected(request, response, expected, expectedStatusCode, expectedETag); ETagHeaderVerifier etagHeaderVerifier = new ETagHeaderVerifier(); etagHeaderVerifier.Verify(expectedETag, request, response); }
internal static HttpStatusCode CalculateExpectedStatusCode(FunctionSegment functionSegment) { // If the action returns information expect 200, otherwise 204 if (functionSegment.Function.ReturnType == null) { return(HttpStatusCode.NoContent); } else { return(HttpStatusCode.OK); } }
/// <summary> /// Find out whether to use payload for client verification /// </summary> /// <param name="queryUri">The request uri</param> /// <returns>Whether to use payload for client verification</returns> private bool ShouldUsePayloadDrivenVerification(ODataUri queryUri) { if (queryUri.IsAction()) { return(true); } if (queryUri.IsServiceOperation()) { FunctionSegment functionSegment = queryUri.Segments.OfType <FunctionSegment>().Last(); return(!functionSegment.Function.Annotations.OfType <FunctionBodyAnnotation>().Single().IsRoot); } return(false); }
/// <summary> /// Converts the given ServiceOperation segment into a string /// </summary> /// <param name="segment">The segment to convert</param> /// <returns>The converted segment string</returns> public string ConvertToString(FunctionSegment segment) { string uriEndingToUse = string.Empty; if (segment.UseParentheses) { uriEndingToUse = "()"; } if (segment.Container != null) { return(this.EscapeUriString(segment.Container.Name) + "." + this.EscapeUriString(segment.Function.Name) + uriEndingToUse); } else { return(this.EscapeUriString(segment.Function.Name) + uriEndingToUse); } }
private IDictionary <string, QueryValue> CreateQueryValueParameters(ODataRequest request, FunctionSegment functionSegment, IDictionary <string, QueryValue> queryValueParametersLookup) { var parameters = request.Body.RootElement as ComplexInstance; // Convert the parameters to query values ExceptionUtilities.CheckObjectNotNull(parameters, "Expected parameters to not be null for action"); queryValueParametersLookup = this.ParametersPayloadElementToQueryValuesConverter.Convert(parameters, functionSegment.Function); return(queryValueParametersLookup); }