Exemple #1
0
        public void ParseODataUriTemplate_ForActions(string template)
        {
            // Arrange
            // function with optional parameters
            EdmAction setSalaray = new EdmAction("NS", "SetWholeSalary", IntType, isBound: true, entitySetPathExpression: null);

            setSalaray.AddParameter("entityset", new EdmCollectionTypeReference(new EdmCollectionType(new EdmEntityTypeReference(_customerType, false))));
            setSalaray.AddParameter("minSalary", IntType);
            setSalaray.AddOptionalParameter("maxSalary", IntType);
            setSalaray.AddOptionalParameter("aveSalary", IntType, "129");
            _edmModel.AddElement(setSalaray);

            IODataPathTemplateParser parser = new DefaultODataPathTemplateParser();
            MockServiceProvider      sp     = null;

            if (!template.Contains("NS."))
            {
                sp = new MockServiceProvider(_edmModel);
            }

            // Act
            ODataPathTemplate path = parser.Parse(_edmModel, template, sp);

            // Assert
            Assert.NotNull(path);
            Assert.Equal(2, path.Count);
            ActionSegmentTemplate actionSegment = Assert.IsType <ActionSegmentTemplate>(path[1]);

            Assert.Equal("NS.SetWholeSalary", actionSegment.Action.FullName());
        }
        public void TryTranslateActionSegmentTemplate_ThrowsArgumentNull_Context()
        {
            // Arrange
            EdmAction             action   = new EdmAction("NS", "action", null, true, null);
            ActionSegmentTemplate template = new ActionSegmentTemplate(action, null);

            // Act & Assert
            ExceptionAssert.ThrowsArgumentNull(() => template.TryTranslate(null), "context");
        }
        public void CommonActionProperties_ReturnsAsExpected()
        {
            // Assert
            EdmAction             action   = new EdmAction("NS", "action", null);
            ActionSegmentTemplate template = new ActionSegmentTemplate(action, null);

            // Act & Assert
            Assert.Equal(ODataSegmentKind.Action, template.Kind);
            Assert.Equal("NS.action", template.Literal);
            Assert.False(template.IsSingle);
            Assert.Null(template.EdmType);
            Assert.Null(template.NavigationSource);
        }
        public void CtorActionSegmentTemplate_SetsProperties()
        {
            // Arrange & Act
            EdmAction             action  = new EdmAction("NS", "action", null, true, null);
            ActionSegmentTemplate segment = new ActionSegmentTemplate(action, null);

            // Assert
            Assert.Same(action, segment.Action);
            Assert.NotNull(segment.Segment);
            Assert.Null(segment.NavigationSource);

            // Act & Assert
            ActionSegmentTemplate segment1 = new ActionSegmentTemplate(segment.Segment);

            Assert.Same(segment.Segment, segment1.Segment);
        }
        public void Translate_ReturnsODataActionImportSegment()
        {
            // Arrange
            EdmAction                     action   = new EdmAction("NS", "action", null);
            ActionSegmentTemplate         template = new ActionSegmentTemplate(action, null);
            ODataTemplateTranslateContext context  = new ODataTemplateTranslateContext();

            // Act
            ODataPathSegment actual = template.Translate(context);

            // Assert
            Assert.NotNull(actual);
            OperationSegment actionSegment = Assert.IsType <OperationSegment>(actual);

            Assert.Same(action, actionSegment.Operations.First());
        }
        public void GetTemplatesActionSegmentTemplate_ReturnsTemplates()
        {
            // Assert
            EdmAction             action  = new EdmAction("NS", "action", null, true, null);
            ActionSegmentTemplate segment = new ActionSegmentTemplate(action, null);

            // 1- Act & Assert
            IEnumerable <string> templates = segment.GetTemplates();

            Assert.Collection(templates,
                              e =>
            {
                Assert.Equal("/NS.action", e);
            },
                              e =>
            {
                Assert.Equal("/action", e);
            });

            // 2- Act & Assert
            templates = segment.GetTemplates(new ODataRouteOptions
            {
                EnableQualifiedOperationCall = false
            });
            string template = Assert.Single(templates);

            Assert.Equal("/action", template);

            // 3- Act & Assert
            templates = segment.GetTemplates(new ODataRouteOptions
            {
                EnableUnqualifiedOperationCall = false
            });
            template = Assert.Single(templates);
            Assert.Equal("/NS.action", template);
        }
Exemple #7
0
 public static ODataOperationSegment ConvertTo(this ActionSegmentTemplate action)
 {
     return(new ODataOperationSegment(action.Action));
 }
Exemple #8
0
        public static ODataPath Translate(this ODataPathTemplate pathTemplate)
        {
            if (pathTemplate.Count == 0)
            {
                // It's service root, so far, let's skip it.
                return(null);
            }

            IList <ODataSegment> newSegments = new List <ODataSegment>();

            foreach (var segment in pathTemplate)
            {
                switch (segment.Kind)
                {
                case ODataSegmentKind.Metadata:
                    newSegments.Add(new ODataMetadataSegment());
                    break;

                case ODataSegmentKind.EntitySet:
                    EntitySetSegmentTemplate entitySet = (EntitySetSegmentTemplate)segment;
                    newSegments.Add(entitySet.ConvertTo());
                    break;

                case ODataSegmentKind.Singleton:
                    SingletonSegmentTemplate singleton = (SingletonSegmentTemplate)segment;
                    newSegments.Add(singleton.ConvertTo());
                    break;

                case ODataSegmentKind.Key:
                    KeySegmentTemplate key = (KeySegmentTemplate)segment;
                    newSegments.Add(key.ConvertTo());
                    break;

                case ODataSegmentKind.Cast:
                    CastSegmentTemplate cast = (CastSegmentTemplate)segment;
                    newSegments.Add(cast.ConvertTo());
                    break;

                case ODataSegmentKind.Property:
                    // TODO:
                    return(null);

                //PropertySegmentTemplate property = (PropertySegmentTemplate)segment;
                //newSegments.Add(property.ConvertTo());
                //break;

                case ODataSegmentKind.Navigation:
                    NavigationSegmentTemplate navigation = (NavigationSegmentTemplate)segment;
                    newSegments.Add(navigation.ConvertTo());
                    break;

                case ODataSegmentKind.Function:
                    FunctionSegmentTemplate function = (FunctionSegmentTemplate)segment;
                    newSegments.Add(function.ConvertTo());
                    break;

                case ODataSegmentKind.Action:
                    ActionSegmentTemplate action = (ActionSegmentTemplate)segment;
                    newSegments.Add(action.ConvertTo());
                    break;

                case ODataSegmentKind.FunctionImport:
                    FunctionImportSegmentTemplate functionImport = (FunctionImportSegmentTemplate)segment;
                    newSegments.Add(functionImport.ConvertTo());
                    break;

                case ODataSegmentKind.ActionImport:
                    ActionImportSegmentTemplate actionImport = (ActionImportSegmentTemplate)segment;
                    newSegments.Add(actionImport.ConvertTo());
                    break;

                case ODataSegmentKind.Value:
                    return(null);

                //ValueSegmentTemplate value = (ValueSegmentTemplate)segment;
                //newSegments.Add(value.ConvertTo());
                //break;

                case ODataSegmentKind.Ref:
                    return(null);

                //KeySegmentTemplate key = (KeySegmentTemplate)segment;
                //newSegments.Add(key.ConvertTo());
                //break;

                case ODataSegmentKind.NavigationLink:
                    return(null);

                //NavigationLinkSegmentTemplate navigationLink = (NavigationLinkSegmentTemplate)segment;
                //newSegments.Add(navigationLink.ConvertTo());
                //break;

                case ODataSegmentKind.Count:
                    CountSegmentTemplate count = (CountSegmentTemplate)segment;
                    newSegments.Add(count.ConvertTo());
                    break;

                case ODataSegmentKind.PathTemplate:
                    return(null);

                //KeySegmentTemplate key = (KeySegmentTemplate)segment;
                //newSegments.Add(key.ConvertTo());
                //break;

                case ODataSegmentKind.Dynamic:
                    return(null);

                //KeySegmentTemplate key = (KeySegmentTemplate)segment;
                //newSegments.Add(key.ConvertTo());
                //break;

                default:
                    throw new NotSupportedException();
                }
            }

            return(new ODataPath(newSegments));
        }