当前位置: 首页>>代码示例>>C#>>正文


C# ResourceType.Except方法代码示例

本文整理汇总了C#中ResourceType.Except方法的典型用法代码示例。如果您正苦于以下问题:C# ResourceType.Except方法的具体用法?C# ResourceType.Except怎么用?C# ResourceType.Except使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ResourceType的用法示例。


在下文中一共展示了ResourceType.Except方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CollectionTypeValidation

        public void CollectionTypeValidation()
        {
            ResourceType entityType = new ResourceType(typeof(object), ResourceTypeKind.EntityType, null, "foo", "Order", false);
            ResourceType complexType = new ResourceType(typeof(object), ResourceTypeKind.ComplexType, null, "foo", "bar", false);
            ResourceType complexType2 = new ResourceType(typeof(object), ResourceTypeKind.ComplexType, null, "foo", "bar2", false);
            complexType2.AddProperty(new ResourceProperty("CollectionProperty", ResourcePropertyKind.Collection, ResourceType.GetCollectionResourceType(complexType)));

            var itemTypes = new ResourceType[] { complexType, complexType2 }.Concat(ResourceTypeUtils.GetPrimitiveResourceTypes());
            var collectionTypes = itemTypes.Except(new[] { ResourceType.GetPrimitiveResourceType(typeof(System.IO.Stream)) }).Select(it => new { ItemType = it, CollectionType = ResourceType.GetCollectionResourceType(it) });
            AstoriaTestNS.TestUtil.RunCombinations(
                collectionTypes,
                c =>
                {
                    Assert.AreEqual(c.ItemType, c.CollectionType.ItemType, "The item type of the collection doesn't match the one specified upon creation.");
                    Assert.AreEqual("Collection(" + c.ItemType.FullName + ")", c.CollectionType.FullName, "The full name of a collection type is wrong.");
                    Assert.AreEqual("Collection(" + c.ItemType.FullName + ")", c.CollectionType.Name, "The name of a collection type is wrong.");
                    Assert.AreEqual("", c.CollectionType.Namespace, "The namespace of a collection type should be empty.");
                    Assert.IsTrue(c.CollectionType.IsReadOnly, "The collection type is always read-only.");
                    Assert.IsFalse(c.CollectionType.IsAbstract, "Collection type is never abstract.");
                    Assert.IsFalse(c.CollectionType.IsOpenType, "Collection type is never open.");
                    Assert.IsFalse(c.CollectionType.IsMediaLinkEntry, "Collection type is never an MLE.");
                    Assert.AreEqual(typeof(IEnumerable<>).MakeGenericType(c.ItemType.InstanceType), c.CollectionType.InstanceType, "The instance type of the collection type is wrong.");
                    Assert.IsTrue(c.CollectionType.CanReflectOnInstanceType, "Collection type has CanReflectOnInstanceType always true.");
                    Assert.IsNull(c.CollectionType.BaseType, "Collection type has never a base type.");
                    Assert.AreEqual(ResourceTypeKind.Collection, c.CollectionType.ResourceTypeKind, "The kind of a collection type is always Collection.");
                    Assert.AreEqual(0, c.CollectionType.PropertiesDeclaredOnThisType.Count(), "Collection type has no properties.");
                    Assert.AreEqual(0, c.CollectionType.Properties.Count(), "Collection type has no properties.");
                    Assert.AreEqual(0, c.CollectionType.KeyProperties.Count(), "Collection type has no properties.");
                    Assert.AreEqual(0, c.CollectionType.ETagProperties.Count(), "Collection type has no properties.");
                    Assert.IsNull(c.CollectionType.CustomState, "Custom state should be null by default.");

                    ExceptionUtils.ThrowsException<InvalidOperationException>(
                        () => c.CollectionType.IsMediaLinkEntry = true,
                        "Setting MLE on collection type should fail.");
                    ExceptionUtils.ThrowsException<InvalidOperationException>(
                        () => c.CollectionType.IsOpenType = true,
                        "Setting IsOpenType on collection type should fail.");
                    ExceptionUtils.ThrowsException<InvalidOperationException>(
                        () => c.CollectionType.CanReflectOnInstanceType = false,
                        "Setting CanReflectOnInstanceType on collection type should fail.");
                    // Setting a custom state should still work
                    c.CollectionType.CustomState = "some value";
                    Assert.AreEqual("some value", c.CollectionType.CustomState, "Custom state doesn't persist its value.");

                    ExceptionUtils.ThrowsException<InvalidOperationException>(
                        () => c.CollectionType.AddProperty(new ResourceProperty("ID", ResourcePropertyKind.ComplexType, complexType)),
                        "Adding a property on collection type should fail.");
                    
                    c.CollectionType.SetReadOnly();
                    Assert.IsTrue(c.CollectionType.IsReadOnly, "The collection type is always read-only.");
                });

            // Verify that only primitive and complex types are allowed as items in a collection
            ResourceType collectionType = ResourceType.GetCollectionResourceType(complexType);
            foreach (var t in new ResourceType[] { entityType, collectionType })
            {
                Exception exception = AstoriaTestNS.TestUtil.RunCatching(() => ResourceType.GetCollectionResourceType(t));
                Assert.IsTrue(exception is ArgumentException, "Exception of a wrong type");
                Assert.AreEqual(
                    "Only collection properties that contain primitive types or complex types are supported.",
                    exception.Message, "Wrong exception message.");
            }
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:63,代码来源:CollectionResourceTypeTests.cs


注:本文中的ResourceType.Except方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。