/// <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); }
/// <summary> /// Find out whehter the given segment is select-all-function-segment (ContainerName.*) /// </summary> /// <param name="selectSegment">The segment</param> /// <returns>Whether segment is select-all-function-segment</returns> private bool IsSelectAllFunctionSegment(ODataUriSegment selectSegment) { UnrecognizedSegment selectAllFunctionSegment = selectSegment as UnrecognizedSegment; if (selectAllFunctionSegment != null && selectAllFunctionSegment.Value == this.model.GetDefaultEntityContainer().Name + ".*") { return(true); } return(false); }
/// <summary> /// Find out whether to expect action descriptor given expand and select segments. /// </summary> /// <param name="selectSegmentList">The select segments</param> /// <param name="expandSegmentList">The expand segments</param> /// <param name="action">The action</param> /// <returns>Whether to expect action descriptor</returns> private bool FunctionMatchWithExpandSegmentList(List <ODataUriSegment> selectSegmentList, List <ODataUriSegment> expandSegmentList, Function action) { // check if $select path and $expand path matchs int index = 0; NavigationSegment expandNavSegment = null; foreach (var expandSegment in expandSegmentList) { expandNavSegment = expandSegment as NavigationSegment; ExceptionUtilities.CheckArgumentNotNull(expandNavSegment, "Unexpected expand segment."); NavigationSegment selectNavSegment = selectSegmentList[index] as NavigationSegment; if (selectNavSegment == null || !expandNavSegment.NavigationProperty.Equals(selectNavSegment.NavigationProperty)) { return(false); } index++; } // check if the action binding type matches with last segment of $expand path EntityDataType bindingEntityDataType = action.Parameters.First().DataType as EntityDataType; ExceptionUtilities.CheckArgumentNotNull(bindingEntityDataType, "Unexpected feed-bound action."); EntityType bindingEntityType = bindingEntityDataType.Definition; if (bindingEntityType != expandNavSegment.NavigationProperty.ToAssociationEnd.EntityType) { return(false); } // expect action descriptor (return true) for $expand=Rating if: $select=Rating, $select=Rating/ActionName, $Select=Rating/Container.* if (selectSegmentList.Count == expandSegmentList.Count + 1) { ODataUriSegment lastSelectSegment = selectSegmentList.Last(); return(this.FuctionMatchWithSelectFunctionSegment(action, lastSelectSegment) || this.IsSelectAllFunctionSegment(lastSelectSegment)); } return(true); }
/// <summary> /// Find out whether to expect action descriptor with projection in request uri /// </summary> /// <param name="requestUri">The request uri</param> /// <param name="action">The action</param> /// <param name="isTopLevelElement">Whether the entity being verified is top level payload element</param> /// <returns>Whether to expect action descriptor</returns> private bool ExpectActionWithProjection(ODataUri requestUri, Function action, bool isTopLevelElement) { ODataUriSegmentPathCollection selectSegments = requestUri.SelectSegments; ODataUriSegmentPathCollection expandSegments = requestUri.ExpandSegments; // handle single level $select path, expect action descriptor if $select=ActionName or $select=Container.* foreach (var selectSegmentPath in selectSegments.Where(ss => ss.Count == 1)) { ODataUriSegment selectSegment = selectSegmentPath.Single(); if (isTopLevelElement && this.FuctionMatchWithSelectFunctionSegment(action, selectSegment)) { return(true); } if (this.IsSelectAllFunctionSegment(selectSegment)) { return(true); } } // handle multiple level $select path, expect action descriptor for $expand=Rating if: $select=Rating or $select=Rating/ActionName or $Select=Rating/Container.* foreach (var expandSegmentPath in expandSegments) { List <ODataUriSegment> expandSegmentList = expandSegmentPath.ToList(); foreach (var selectSegmentPath in selectSegments.Where(ss => ss.Count == expandSegmentPath.Count || ss.Count == expandSegmentPath.Count + 1)) { List <ODataUriSegment> selectSegmentList = selectSegmentPath.ToList(); if (this.FunctionMatchWithExpandSegmentList(selectSegmentList, expandSegmentList, action)) { return(true); } } } return(false); }
public void BatchReaderMixedEncodingTest() { EdmModel model = new EdmModel(); EdmEntityType personType = model.EntityType("Person") .KeyProperty("Id", EdmCoreModel.Instance.GetInt32(false) as EdmTypeReference) .Property("Name", EdmPrimitiveTypeKind.String, isNullable: true); model.Fixup(); EdmEntitySet personSet = model.EntitySet("Person", personType); EntityInstance personInstance = PayloadBuilder.Entity("TestModel.Person") .Property("Id", PayloadBuilder.PrimitiveValue(1)) .Property("Name", PayloadBuilder.PrimitiveValue("Mr Foo Baz")); ODataUriSegment root = ODataUriBuilder.Root(new Uri("http://www.odata.org")); ODataUri testUri = new ODataUri(root, ODataUriBuilder.EntitySet(personSet)); Encoding[] encodings = new Encoding[] { Encoding.UTF8, Encoding.BigEndianUnicode, Encoding.Unicode }; IEnumerable <BatchReaderMixedEncodingTestCase> testCases = encodings.SelectMany(batchEncoding => encodings.Select(changesetEncoding => new BatchReaderMixedEncodingTestCase { BatchEncoding = batchEncoding, Changesets = new[] { new BatchReaderMixedEncodingChangeset { ChangesetEncoding = changesetEncoding, Operations = new[] { new BatchReaderMixedEncodingOperation { OperationEncoding = Encoding.Unicode, PayloadFormat = ODataFormat.Atom, }, new BatchReaderMixedEncodingOperation { // Uses changeset's encoding PayloadFormat = ODataFormat.Atom, }, }, }, new BatchReaderMixedEncodingChangeset { Operations = new[] { new BatchReaderMixedEncodingOperation { // Uses batch's encoding OperationEncoding = batchEncoding, PayloadFormat = ODataFormat.Atom, }, }, }, }, } )); this.CombinatorialEngineProvider.RunCombinations( testCases, this.ReaderTestConfigurationProvider.DefaultFormatConfigurations, (testCase, testConfiguration) => { var testPayload = personInstance.DeepCopy(); if (!testConfiguration.IsRequest) { testPayload.AddAnnotation(new PayloadFormatVersionAnnotation() { Response = true, ResponseWrapper = true }); } var testDescriptor = this.CreateTestDescriptor(testCase, testPayload, testUri, testConfiguration.IsRequest); testDescriptor.PayloadEdmModel = model; testDescriptor.RunTest(testConfiguration); }); }
/// <summary> /// Converts the given segment into a string /// </summary> /// <param name="segment">The segment to convert</param> /// <returns>The converted segment string</returns> public string ConvertToString(ODataUriSegment segment) { ExceptionUtilities.CheckArgumentNotNull(segment, "segment"); var entitySet = segment as EntitySetSegment; if (entitySet != null) { return(this.ConvertToString(entitySet)); } var key = segment as KeyExpressionSegment; if (key != null) { return(this.ConvertToString(key)); } var property = segment as PropertySegment; if (property != null) { return(this.ConvertToString(property)); } var navigation = segment as NavigationSegment; if (navigation != null) { return(this.ConvertToString(navigation)); } var serviceRoot = segment as ServiceRootSegment; if (serviceRoot != null) { return(this.ConvertToString(serviceRoot)); } var system = segment as SystemSegment; if (system != null) { return(this.ConvertToString(system)); } var namedStreamEndpoint = segment as NamedStreamSegment; if (namedStreamEndpoint != null) { return(this.ConvertToString(namedStreamEndpoint)); } var oftype = segment as EntityTypeSegment; if (oftype != null) { return(this.ConvertToString(oftype)); } var function = segment as FunctionSegment; if (function != null) { return(this.ConvertToString(function)); } var unknown = segment as UnrecognizedSegment; ExceptionUtilities.CheckObjectNotNull(unknown, "Segment was of unrecognized type: '{0}'", segment.GetType().FullName); return(this.ConvertToString(unknown)); }