public void InitializInsertRestrictionsTypeWithRecordSuccess()
        {
            // Assert
            IEdmRecordExpression primitiveExampleValue = new EdmRecordExpression(
                new EdmPropertyConstructor("Description", new EdmStringConstant("example desc")),
                new EdmPropertyConstructor("Value", new EdmStringConstant("example value")));

            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("Insertable", new EdmBooleanConstant(false)),
                new EdmPropertyConstructor("NonInsertableProperties", new EdmCollectionExpression(new EdmPathExpression("abc/xyz"))),
                new EdmPropertyConstructor("NonInsertableNavigationProperties", new EdmCollectionExpression(new EdmNavigationPropertyPathExpression("abc"), new EdmNavigationPropertyPathExpression("RelatedEvents"))),
                new EdmPropertyConstructor("MaxLevels", new EdmIntegerConstant(8)),
                new EdmPropertyConstructor("CustomQueryOptions", new EdmCollectionExpression(
                                               new EdmRecordExpression(
                                                   new EdmPropertyConstructor("Name", new EdmStringConstant("primitive name")),
                                                   new EdmPropertyConstructor("Description", new EdmStringConstant("primitive desc")),
                                                   new EdmPropertyConstructor("DocumentationURL", new EdmStringConstant("http://any3")),
                                                   new EdmPropertyConstructor("Required", new EdmBooleanConstant(true)),
                                                   new EdmPropertyConstructor("ExampleValues", new EdmCollectionExpression(primitiveExampleValue)))))
                // QueryOptions
                // Permission
                // CustomHeaders
                );

            // Act
            InsertRestrictionsType insert = new InsertRestrictionsType();

            insert.Initialize(record);

            // Assert
            VerifyInsertRestrictions(insert);
        }
        public void InitializReadRestrictionsTypeWithRecordSuccess()
        {
            // Assert
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("Readable", new EdmBooleanConstant(false)),
                new EdmPropertyConstructor("CustomQueryOptions", new EdmCollectionExpression(
                                               new EdmRecordExpression(new EdmPropertyConstructor("Name", new EdmStringConstant("root query name"))))),
                // Root Permission
                // Root CustomHeaders
                new EdmPropertyConstructor("ReadByKeyRestrictions", new EdmRecordExpression(
                                               new EdmPropertyConstructor("Readable", new EdmBooleanConstant(true)),
                                               new EdmPropertyConstructor("CustomHeaders", new EdmCollectionExpression(
                                                                              new EdmRecordExpression(new EdmPropertyConstructor("Name", new EdmStringConstant("by key head name")))))
                                               // ByKey Permission
                                               // ByKey CustomQueryOptions
                                               ))
                );

            // Act
            ReadRestrictionsType read = new ReadRestrictionsType();

            read.Initialize(record);

            // Assert
            VerifyReadRestrictions(read);
        }
示例#3
0
        public static IEdmExpression CreatePermission(params string[] scopeNames)
        {
            var restriction = new EdmRecordExpression(
                CreatePermissionProperty(scopeNames));

            return(restriction);
        }
示例#4
0
        public void InitializeSecuritySchemeWithRecordSuccess()
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("Authorization", new EdmStringConstant("DelegatedWork")),
                new EdmPropertyConstructor("RequiredScopes", new EdmCollectionExpression(
                                               new EdmStringConstant("User.ReadAll"),
                                               new EdmStringConstant("User.WriteAll"))));

            SecurityScheme securityScheme = new SecurityScheme();

            Assert.Null(securityScheme.Authorization);
            Assert.Null(securityScheme.RequiredScopes);

            // Act
            securityScheme.Initialize(record);

            // Assert
            Assert.NotNull(securityScheme.Authorization);
            Assert.Equal("DelegatedWork", securityScheme.Authorization);

            Assert.NotNull(securityScheme.RequiredScopes);
            Assert.Equal(2, securityScheme.RequiredScopes.Count);
            Assert.Equal(new[] { "User.ReadAll", "User.WriteAll" }, securityScheme.RequiredScopes);
        }
示例#5
0
        public void GetCollectionForRecordWorks()
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("prop", new EdmCollectionExpression(
                                               new EdmRecordExpression(
                                                   new EdmPropertyConstructor("Scope", new EdmStringConstant("scope1")),
                                                   new EdmPropertyConstructor("RestrictedProperties", new EdmStringConstant("restrictedProperties1"))),
                                               new EdmRecordExpression(
                                                   new EdmPropertyConstructor("Scope", new EdmStringConstant("scope2")),
                                                   new EdmPropertyConstructor("RestrictedProperties", new EdmStringConstant("restrictedProperties2"))))));

            // Act
            IList <ScopeType> actual = record.GetCollection <ScopeType>("prop");

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(2, actual.Count);

            for (int i = 1; i <= actual.Count; i++)
            {
                Assert.Equal("scope" + i, actual[i - 1].Scope);
                Assert.Equal("restrictedProperties" + i, actual[i - 1].RestrictedProperties);
            }
        }
        public void InitializeDeleteRestrictionsTypeWithRecordSuccess()
        {
            // Assert
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("Deletable", new EdmBooleanConstant(false)),
                new EdmPropertyConstructor("NonDeletableNavigationProperties",
                                           new EdmCollectionExpression(new EdmNavigationPropertyPathExpression("abc"), new EdmNavigationPropertyPathExpression("RelatedEvents"))),
                new EdmPropertyConstructor("MaxLevels", new EdmIntegerConstant(42)),
                new EdmPropertyConstructor("Permissions", new EdmCollectionExpression(
                                               new EdmRecordExpression(
                                                   new EdmPropertyConstructor("SchemeName", new EdmStringConstant("schemeName"))))),
                new EdmPropertyConstructor("CustomQueryOptions", new EdmCollectionExpression(
                                               new EdmRecordExpression(
                                                   new EdmPropertyConstructor("Name", new EdmStringConstant("odata-debug")),
                                                   new EdmPropertyConstructor("DocumentationURL", new EdmStringConstant("https://debug.html")))))
                // CustomHeaders
                );

            // Act
            DeleteRestrictionsType delete = new DeleteRestrictionsType();

            delete.Initialize(record);

            // Assert
            VerifyDeleteRestrictionsType(delete);
        }
示例#7
0
        private static void AddComplexPropertyCommunityAlternateKey(EdmModel model, EdmEntityType entity)
        {
            // Alternate key 1 -> Code
            List <IEdmExpression> propertyRefs = new List <IEdmExpression>();
            IEdmRecordExpression  propertyRef  = new EdmRecordExpression(
                new EdmPropertyConstructor("Alias", new EdmStringConstant("Code")),
                new EdmPropertyConstructor("Name", new EdmPropertyPathExpression("Code")));

            propertyRefs.Add(propertyRef);

            EdmRecordExpression alternateKey1 = new EdmRecordExpression(new EdmPropertyConstructor("Key", new EdmCollectionExpression(propertyRefs)));

            // Alternate key 2 -> City & Street
            propertyRefs = new List <IEdmExpression>();
            propertyRef  = new EdmRecordExpression(
                new EdmPropertyConstructor("Alias", new EdmStringConstant("City")),
                new EdmPropertyConstructor("Name", new EdmPropertyPathExpression("Location/City")));
            propertyRefs.Add(propertyRef);

            propertyRef = new EdmRecordExpression(
                new EdmPropertyConstructor("Alias", new EdmStringConstant("Street")),
                new EdmPropertyConstructor("Name", new EdmPropertyPathExpression("Location/Street")));
            propertyRefs.Add(propertyRef);

            EdmRecordExpression alternateKey2 = new EdmRecordExpression(new EdmPropertyConstructor("Key", new EdmCollectionExpression(propertyRefs)));

            IEdmTerm coreAlternateTerm = AlternateKeysVocabularyModel.Instance.FindDeclaredTerm("OData.Community.Keys.V1.AlternateKeys");

            Assert.NotNull(coreAlternateTerm);

            var annotation = new EdmVocabularyAnnotation(entity, coreAlternateTerm, new EdmCollectionExpression(alternateKey1, alternateKey2));

            annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
            model.SetVocabularyAnnotation(annotation);
        }
        public void InitializeOAuth2AuthCodeWithRecordSuccess()
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("TokenUrl", new EdmStringConstant("http://tokenUrl")),
                new EdmPropertyConstructor("AuthorizationUrl", new EdmStringConstant("http://authorizationUrl")));

            OAuth2AuthCode authCode = new OAuth2AuthCode();

            Assert.Null(authCode.Name);
            Assert.Null(authCode.Description);
            Assert.Null(authCode.Scopes);
            Assert.Null(authCode.AuthorizationUrl);
            Assert.Null(authCode.TokenUrl);

            // Act
            authCode.Initialize(record);

            // Assert
            Assert.Null(authCode.Name);
            Assert.Null(authCode.Description);
            Assert.Null(authCode.Scopes);
            Assert.Equal("http://authorizationUrl", authCode.AuthorizationUrl);
            Assert.Equal("http://tokenUrl", authCode.TokenUrl);
        }
        public void InitializNavigationRestrictionsTypeWithRecordSuccess()
        {
            // Assert
            EdmModel     model          = new EdmModel();
            IEdmEnumType navigationType = model.FindType("Org.OData.Capabilities.V1.NavigationType") as IEdmEnumType;

            Assert.NotNull(navigationType);

            IEdmRecordExpression restriction1 = new EdmRecordExpression(
                new EdmPropertyConstructor("NavigationProperty", new EdmNavigationPropertyPathExpression("abc")),
                new EdmPropertyConstructor("Navigability", new EdmEnumMemberExpression(navigationType.Members.First(c => c.Name == "Single"))),
                new EdmPropertyConstructor("SkipSupported", new EdmBooleanConstant(false)));

            IEdmRecordExpression restriction2 = new EdmRecordExpression(
                new EdmPropertyConstructor("NavigationProperty", new EdmNavigationPropertyPathExpression("xyz")),
                new EdmPropertyConstructor("Navigability", new EdmEnumMemberExpression(navigationType.Members.First(c => c.Name == "None"))),
                new EdmPropertyConstructor("OptimisticConcurrencyControl", new EdmBooleanConstant(true)));

            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("Navigability", new EdmEnumMemberExpression(navigationType.Members.First(c => c.Name == "Recursive"))),
                new EdmPropertyConstructor("RestrictedProperties", new EdmCollectionExpression(restriction1, restriction2))
                );

            // Act
            NavigationRestrictionsType navigation = new NavigationRestrictionsType();

            navigation.Initialize(record);

            // Assert
            VerifyNavigationRestrictions(navigation);
        }
        public void InitializSearchRestrictionsTypeWithRecordSuccess()
        {
            // Assert
            EdmModel     model             = new EdmModel();
            IEdmEnumType searchExpressions = model.FindType("Org.OData.Capabilities.V1.SearchExpressions") as IEdmEnumType;

            Assert.NotNull(searchExpressions);

            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("Searchable", new EdmBooleanConstant(false)),
                new EdmPropertyConstructor("UnsupportedExpressions", new EdmEnumMemberExpression(
                                               searchExpressions.Members.First(c => c.Name == "AND"),
                                               searchExpressions.Members.First(c => c.Name == "OR")))
                );

            // Act
            SearchRestrictionsType search = new SearchRestrictionsType();

            search.Initialize(record);

            // Assert
            Assert.False(search.Searchable);
            Assert.NotNull(search.UnsupportedExpressions);
            Assert.Equal(SearchExpressions.AND | SearchExpressions.OR, search.UnsupportedExpressions.Value);
        }
示例#11
0
        public static void SetSearchRestrictionsCapabilitiesAnnotation(this EdmModel model, IEdmEntitySet entitySet, bool searchable, CapabilitiesSearchExpressions unsupported)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (entitySet == null)
            {
                throw new ArgumentNullException("entitySet");
            }

            var target     = entitySet;
            var term       = SearchRestrictionsTerm;
            var name       = new EdmEnumTypeReference(SearchExpressionsType, false).ToStringLiteral((long)unsupported);
            var properties = new IEdmPropertyConstructor[]
            {
                new EdmPropertyConstructor("Searchable", new EdmBooleanConstant(searchable)),
                new EdmPropertyConstructor("UnsupportedExpressions", new EdmEnumMemberReferenceExpression(SearchExpressionsType.Members.Single(m => m.Name == name))),
            };
            var record = new EdmRecordExpression(properties);

            var annotation = new EdmAnnotation(target, term, record);

            annotation.SetSerializationLocation(model, entitySet.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
        public void ValueTerm_Record_OnEntityType()
        {
            this.SetupModels();

            IEdmEntityType person          = this.baseModel.FindEntityType("NS1.Person");
            IEdmValueTerm  termStringValue = this.longDefinitionModel.FindValueTerm("bar.StringValue");
            var            record          = new EdmRecordExpression(
                new EdmPropertyConstructor("p1", new EdmStringConstant("s1")),
                new EdmPropertyConstructor("p2", new EdmIntegerConstant(2)));

            this.CreateAndAttachValueAnnotation(person, termStringValue, record);

            string expectedCsdl =
                @"<Schema Namespace=""NS1"" xmlns=""http://docs.oasis-open.org/odata/ns/edm"">
    <EntityType Name=""Person"">
        <Key>
            <PropertyRef Name=""Name"" />
        </Key>
        <Property Name=""Name"" Type=""Edm.String"" Nullable=""false"" />
        <Property Name=""Birthday"" Type=""Edm.DateTimeOffset"" Nullable=""false"" />
    </EntityType>
    <Annotations Target=""NS1.Person"">
        <Annotation Term=""bar.StringValue"">
            <Record>
                <PropertyValue Property=""p1"" String=""s1"" />
                <PropertyValue Property=""p2"" Int=""2"" />
            </Record>
        </Annotation>
    </Annotations>
</Schema>";

            this.SerializeAndVerifyAgainst(this.baseModel, expectedCsdl);
        }
示例#13
0
        public void InitializeApiKeyWithRecordSuccess()
        {
            // Arrange
            EdmModel       model      = new EdmModel();
            IEdmType       edmType    = model.FindType("Org.OData.Authorization.V1.KeyLocation");
            IEdmEnumType   enumType   = edmType as IEdmEnumType;
            IEdmEnumMember enumMember = enumType.Members.FirstOrDefault(c => c.Name == "Header");

            Assert.NotNull(enumMember);

            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("Name", new EdmStringConstant("DelegatedWork")),
                new EdmPropertyConstructor("Description", new EdmStringConstant("Description of the authorization scheme")),
                new EdmPropertyConstructor("KeyName", new EdmStringConstant("keyName")),
                new EdmPropertyConstructor("Location", new EdmEnumMemberExpression(enumMember)));

            ApiKey apiKey = new ApiKey();

            Assert.Null(apiKey.Name);
            Assert.Null(apiKey.Description);
            Assert.Null(apiKey.Location);
            Assert.Null(apiKey.KeyName);

            // Act
            apiKey.Initialize(record);

            // Assert
            Assert.Equal("DelegatedWork", apiKey.Name);
            Assert.Equal("Description of the authorization scheme", apiKey.Description);
            Assert.Equal("keyName", apiKey.KeyName);
            Assert.Equal(KeyLocation.Header, apiKey.Location);
        }
        public void InitializeOAuth2PasswordWithRecordSuccess()
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("RefreshUrl", new EdmStringConstant("http://refreshUrl")),
                new EdmPropertyConstructor("TokenUrl", new EdmStringConstant("http://tokenUrl")));

            OAuth2Password password = new OAuth2Password();

            Assert.Null(password.Name);
            Assert.Null(password.Description);
            Assert.Null(password.Scopes);
            Assert.Null(password.RefreshUrl);
            Assert.Null(password.TokenUrl);

            // Act
            password.Initialize(record);

            // Assert
            Assert.Null(password.Name);
            Assert.Null(password.Description);
            Assert.Null(password.Scopes);
            Assert.Equal("http://refreshUrl", password.RefreshUrl);
            Assert.Equal("http://tokenUrl", password.TokenUrl);
        }
        public void EdmRecordExpression()
        {
            var e = new EdmRecordExpression(EdmCoreModel.Instance.GetBoolean(true).AsStructured(),
                                            new EdmPropertyConstructor("p1", new EdmStringConstant("qwerty")),
                                            new EdmPropertyConstructor("p2", new EdmStringConstant("qwerty2")));

            Assert.AreEqual(EdmExpressionKind.Record, e.ExpressionKind, "e.ExpressionKind");
            Assert.AreEqual("Edm.Boolean", e.DeclaredType.FullName(), "e.DeclaredType");
            Assert.IsTrue(e.IsBad(), "e is bad because it has a bad declared type");
            Assert.AreEqual(1, e.Errors().Count(), "Expression has errors");

            e = new EdmRecordExpression();
            Assert.IsNull(e.DeclaredType, "e.DeclaredType");
            Assert.AreEqual(0, e.Properties.Count(), "e.Properties.Count()");
            Assert.IsFalse(e.IsBad(), "e is good");
            Assert.AreEqual(0, e.Errors().Count(), "Expression has no errors");

            e = new EdmRecordExpression(new EdmEntityTypeReference(new EdmEntityType("", ""), false),
                                        new EdmPropertyConstructor("p1", new EdmStringConstant("qwerty")),
                                        new EdmPropertyConstructor("p2", new EdmStringConstant("qwerty2")));
            Assert.IsFalse(e.IsBad(), "e is good");
            Assert.AreEqual(0, e.Errors().Count(), "Expression has no errors");

            e = new EdmRecordExpression((IEdmStructuredTypeReference)null);
            Assert.IsNull(e.DeclaredType, "e.DeclaredType");
            Assert.AreEqual(0, e.Properties.Count(), "e.Properties.Count()");
            Assert.IsFalse(e.IsBad(), "e is good");
            Assert.AreEqual(0, e.Errors().Count(), "Expression has no errors");

            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmPropertyConstructor(null, new EdmStringConstant("qwerty")));
            this.VerifyThrowsException(typeof(ArgumentNullException), () => new EdmPropertyConstructor("p1", null));
        }
示例#16
0
        public void InitializeHttpWithRecordSuccess()
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("Name", new EdmStringConstant("HttpWork")),
                new EdmPropertyConstructor("Description", new EdmStringConstant("Description of the scheme")),
                new EdmPropertyConstructor("Scheme", new EdmStringConstant("Authorization scheme")),
                new EdmPropertyConstructor("BearerFormat", new EdmStringConstant("Format of the bearer token")));

            Http http = new Http();

            Assert.Null(http.Name);
            Assert.Null(http.Description);
            Assert.Null(http.Scheme);
            Assert.Null(http.BearerFormat);

            // Act
            http.Initialize(record);

            // Assert
            Assert.Equal("HttpWork", http.Name);
            Assert.Equal("Description of the scheme", http.Description);
            Assert.Equal("Authorization scheme", http.Scheme);
            Assert.Equal("Format of the bearer token", http.BearerFormat);
        }
示例#17
0
        private static void AddSelectTerm <T>(EdmModel model)
        {
            EdmComplexType complexType = new EdmComplexType("NS", "SelectType");

            complexType.AddStructuralProperty("DefaultSelect", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            complexType.AddStructuralProperty("DefaultHidden", new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true))));
            model.AddElement(complexType);
            EdmTerm term = new EdmTerm("NS", "MyTerm", new EdmComplexTypeReference(complexType, true));

            model.AddElement(term);

            Type   type       = typeof(T);
            string name       = type.Name;
            var    entityType = model.SchemaElements.OfType <IEdmEntityType>().FirstOrDefault(c => c.Name == name);

            if (entityType == null)
            {
                return;
            }

            IList <string> defaultSelects = new List <string>();
            IList <string> defaultHiddens = new List <string>();
            var            properties     = type.GetProperties(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);

            foreach (var property in properties)
            {
                var attrs = property.GetCustomAttributes(typeof(DefaultSelectAttribute), false);
                if (attrs != null && attrs.Any())
                {
                    defaultSelects.Add(property.Name);
                    continue;
                }

                attrs = property.GetCustomAttributes(typeof(DefaultHiddenAttribute), false);
                if (attrs != null && attrs.Any())
                {
                    defaultHiddens.Add(property.Name);
                    continue;
                }
            }

            if (defaultSelects.Any() && defaultHiddens.Any())
            {
                List <IEdmPropertyConstructor> edmPropertiesConstructors = new List <IEdmPropertyConstructor>
                {
                    new EdmPropertyConstructor("DefaultSelect", new EdmCollectionExpression(
                                                   defaultSelects.Select(e => new EdmPropertyPathExpression(e)))),
                    new EdmPropertyConstructor("DefaultHidden", new EdmCollectionExpression(
                                                   defaultHiddens.Select(e => new EdmPropertyPathExpression(e)))),
                };

                IEdmRecordExpression    record     = new EdmRecordExpression(edmPropertiesConstructors);
                EdmVocabularyAnnotation annotation = new EdmVocabularyAnnotation(entityType, term, record);
                annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
                model.SetVocabularyAnnotation(annotation);
            }
        }
        public void InitializeCollectionPropertyRestrictionsTypeWithRecordSuccess()
        {
            // Assert
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("CollectionProperty", new EdmPropertyPathExpression("abc/xyz")),
                new EdmPropertyConstructor("FilterFunctions", new EdmCollectionExpression(new EdmStringConstant("div"))),
                new EdmPropertyConstructor("FilterRestrictions", new EdmRecordExpression(new EdmPropertyConstructor("Filterable", new EdmBooleanConstant(true)))),
                new EdmPropertyConstructor("SearchRestrictions", new EdmRecordExpression(new EdmPropertyConstructor("Searchable", new EdmBooleanConstant(false)))),
                new EdmPropertyConstructor("SortRestrictions", new EdmRecordExpression(new EdmPropertyConstructor("Sortable", new EdmBooleanConstant(false)))),
                new EdmPropertyConstructor("TopSupported", new EdmBooleanConstant(true)),
                new EdmPropertyConstructor("Deletable", new EdmBooleanConstant(false))
                // SkipSupported
                // SelectSupport
                // Insertable
                // Updatable
                );

            // Act
            CollectionPropertyRestrictionsType collectionPropertyRestrictions = new CollectionPropertyRestrictionsType();

            collectionPropertyRestrictions.Initialize(record);

            // Assert
            Assert.Null(collectionPropertyRestrictions.SkipSupported);
            Assert.Null(collectionPropertyRestrictions.SelectSupport);
            Assert.Null(collectionPropertyRestrictions.Insertable);
            Assert.Null(collectionPropertyRestrictions.Updatable);

            Assert.Equal("abc/xyz", collectionPropertyRestrictions.CollectionProperty);

            Assert.NotNull(collectionPropertyRestrictions.FilterFunctions);
            string function = Assert.Single(collectionPropertyRestrictions.FilterFunctions);

            Assert.Equal("div", function);

            Assert.NotNull(collectionPropertyRestrictions.FilterRestrictions);
            Assert.NotNull(collectionPropertyRestrictions.FilterRestrictions.Filterable);
            Assert.True(collectionPropertyRestrictions.FilterRestrictions.Filterable.Value);

            Assert.NotNull(collectionPropertyRestrictions.SearchRestrictions);
            Assert.NotNull(collectionPropertyRestrictions.SearchRestrictions.Searchable);
            Assert.False(collectionPropertyRestrictions.SearchRestrictions.Searchable.Value);

            Assert.NotNull(collectionPropertyRestrictions.SortRestrictions);
            Assert.NotNull(collectionPropertyRestrictions.SortRestrictions.Sortable);
            Assert.False(collectionPropertyRestrictions.SortRestrictions.Sortable.Value);

            Assert.NotNull(collectionPropertyRestrictions.TopSupported);
            Assert.True(collectionPropertyRestrictions.TopSupported.Value);

            Assert.NotNull(collectionPropertyRestrictions.Deletable);
            Assert.False(collectionPropertyRestrictions.Deletable.Value);
        }
示例#19
0
        public void GetStringWorks()
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("prop", new EdmStringConstant("test")));

            // Act
            string actual = record.GetString("prop");

            // Assert
            Assert.NotNull(actual);
            Assert.Equal("test", actual);
        }
示例#20
0
        public void GetPropertyPathWorks()
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("prop", new EdmPropertyPathExpression("abc/xyz")));

            // Act
            string actual = record.GetPropertyPath("prop");

            // Assert
            Assert.NotNull(actual);
            Assert.Equal("abc/xyz", actual);
        }
示例#21
0
        public void GetBooleanWorks(bool expected)
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("prop", new EdmBooleanConstant(expected)));

            // Act
            bool?actual = record.GetBoolean("prop");

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(expected, actual.Value);
        }
示例#22
0
        public void GetIntegerWorks()
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("prop", new EdmIntegerConstant(42)));

            // Act
            long?actual = record.GetInteger("prop");

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(42, actual.Value);
        }
        public void CreateAuthorizationThrowsForOAuthAuthorizationRecord()
        {
            // Arrange & Act
            IEdmStructuredTypeReference structuredTypeRef = GetType("Org.OData.Authorization.V1.OAuthAuthorization");
            IEdmRecordExpression        record            = new EdmRecordExpression(structuredTypeRef,
                                                                                    new EdmPropertyConstructor("Name", new EdmStringConstant("temp")));

            Action test = () => OData.Vocabulary.Authorization.Authorization.CreateAuthorization(record);

            // Assert
            OpenApiException exception = Assert.Throws <OpenApiException>(test);

            Assert.Equal(String.Format(SRResource.AuthorizationRecordTypeNameNotCorrect, structuredTypeRef.FullName()), exception.Message);
        }
示例#24
0
        public static IEdmPropertyConstructor CreatePermissionProperty(params string[] scopeNames)
        {
            var scopes = scopeNames.Select(scope => new EdmRecordExpression(
                                               new EdmPropertyConstructor("Scope", new EdmStringConstant(scope)),
                                               new EdmPropertyConstructor("RestrictedProperties", new EdmStringConstant("*"))));

            var permission = new EdmRecordExpression(
                new EdmPropertyConstructor("SchemeName", new EdmStringConstant("AuthScheme")),
                new EdmPropertyConstructor("Scopes", new EdmCollectionExpression(scopes)));

            var property = new EdmPropertyConstructor("Permissions", new EdmCollectionExpression(permission));

            return(property);
        }
示例#25
0
        public void GetCollectionForStringWorks()
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("prop", new EdmCollectionExpression(
                                               new EdmStringConstant("abc"), new EdmStringConstant("xyz"))));

            // Act
            IList <string> actual = record.GetCollection("prop");

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(2, actual.Count);
            Assert.Equal(new[] { "abc", "xyz" }, actual);
        }
示例#26
0
        public void InitializeDeepInsertSupportTypeWithRecordSuccess()
        {
            // Assert
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("Supported", new EdmBooleanConstant(false)),
                new EdmPropertyConstructor("ContentIDSupported", new EdmBooleanConstant(true)));

            // Act
            DeepInsertSupportType deepInsert = new DeepInsertSupportType();

            deepInsert.Initialize(record);

            // Assert
            VerifyDeepInsertSupportType(deepInsert);
        }
示例#27
0
        public void GetEnumWorks()
        {
            // Arrange
            IEdmEnumType         enumType = new EdmEnumType("NS", "Color");
            EdmEnumMember        member   = new EdmEnumMember(enumType, "Red", new EdmEnumMemberValue(2));
            IEdmRecordExpression record   = new EdmRecordExpression(
                new EdmPropertyConstructor("prop", new EdmEnumMemberExpression(member)));

            // Act
            Color?actual = record.GetEnum <Color>("prop");

            // Assert
            Assert.NotNull(actual);
            Assert.Equal(Color.Red, actual.Value);
        }
        public void CreateAuthorizationReturnsOpenIDConnect(Type type)
        {
            // Arrange & Act
            string qualifiedName        = AuthorizationConstants.Namespace + "." + type.Name;
            IEdmRecordExpression record = new EdmRecordExpression(GetType(qualifiedName),
                                                                  new EdmPropertyConstructor("Name", new EdmStringConstant("temp")));

            // Assert
            var authorization = OData.Vocabulary.Authorization.Authorization.CreateAuthorization(record);

            Assert.NotNull(authorization);
            Assert.Equal(type, authorization.GetType());

            Assert.Equal("temp", authorization.Name);
            Assert.Null(authorization.Description);
        }
        private static void SetVocabularyAnnotation(this EdmModel model, IEdmVocabularyAnnotatable target,
                                                    IList <IEdmPropertyConstructor> properties, string qualifiedName)
        {
            Contract.Assert(model != null);
            Contract.Assert(target != null);

            IEdmTerm term = model.FindTerm(qualifiedName);

            if (term != null)
            {
                IEdmRecordExpression    record     = new EdmRecordExpression(properties);
                EdmVocabularyAnnotation annotation = new EdmVocabularyAnnotation(target, term, record);
                annotation.SetSerializationLocation(model, EdmVocabularyAnnotationSerializationLocation.Inline);
                model.SetVocabularyAnnotation(annotation);
            }
        }
示例#30
0
        public void GetRecordWorks()
        {
            // Arrange
            IEdmRecordExpression record = new EdmRecordExpression(
                new EdmPropertyConstructor("prop", new EdmRecordExpression(
                                               new EdmPropertyConstructor("Scope", new EdmStringConstant("scope name")),
                                               new EdmPropertyConstructor("RestrictedProperties", new EdmStringConstant("*")))));

            // Act
            ScopeType actual = record.GetRecord <ScopeType>("prop");

            // Assert
            Assert.NotNull(actual);
            Assert.Equal("scope name", actual.Scope);
            Assert.Equal("*", actual.RestrictedProperties);
        }