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


C# Product.CreateCollection方法代码示例

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


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

示例1: when_visiting_root_then_visits_entire_graph

        public void when_visiting_root_then_visits_entire_graph()
        {
            var products = 0;
            var elements = 0;
            var collections = 0;
            var containers = 0;
            var components = 0;
            var properties = 0;

            var visitor = InstanceVisitor.Create(
                p => products++,
                e => elements++,
                c => collections++,
                c => containers++,
                c => components++,
                p => properties++);

            var product = new Product("Foo", "IFoo");
            product.CreateElement("Element", "IElement")
                .CreateProperty("IsVisible");
            product.CreateCollection("Collection", "ICollection")
                .CreateElement("Element", "IElement");
            product.CreateProperty("IsVisible");

            product.Accept(visitor);

            Assert.Equal(1, products);
            Assert.Equal(2, elements);
            Assert.Equal(1, collections);
            Assert.Equal(4, containers);
            Assert.Equal(4, components);
            Assert.Equal(2, properties);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:33,代码来源:VisitableFixture.cs

示例2: when_creating_collection_item_then_can_access_product

        public void when_creating_collection_item_then_can_access_product()
        {
            var product = new Product("Product", "IProduct");
            var collection = product.CreateCollection("Collection", "ICollection");
            var item = collection.CreateItem("Item", "IItem");

            Assert.Same(product, item.Product);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:8,代码来源:ComponentModelFixture.cs

示例3: when_creating_collection_then_references_parent_product

        public void when_creating_collection_then_references_parent_product()
        {
            var product = new Product("Foo", "IFoo");

            var child = product.CreateCollection("Buckets", "IBuckets");

            Assert.Same(child.Parent, product);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:8,代码来源:ComponentModelFixture.cs

示例4: when_creating_collection_then_sets_name_and_schema_id

        public void when_creating_collection_then_sets_name_and_schema_id()
        {
            var product = new Product("Foo", "IFoo");

            var child = product.CreateCollection("Buckets", "IBuckets");

            Assert.Equal("Buckets", child.Name);
            Assert.Equal("IBuckets", child.SchemaId);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:9,代码来源:ComponentModelFixture.cs

示例5: when_creating_collection_item_then_can_access_it

        public void when_creating_collection_item_then_can_access_it()
        {
            var product = new Product("Product", "IProduct");
            var collection = product.CreateCollection("Collection", "ICollection");
            var item = collection.CreateItem("Item", "IItem");

            Assert.Equal(1, collection.Items.Count());
            Assert.Same(item, collection.Items.First());
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:9,代码来源:ComponentModelFixture.cs

示例6: when_creating_collection_item_then_raises_item_added

        public void when_creating_collection_item_then_raises_item_added()
        {
            var product = new Product("Product", "IProduct");
            var collection = product.CreateCollection("Collection", "ICollection");

            var item = default(IElement);

            collection.ItemAdded += (sender, args) => item = args.Value;

            var created = collection.CreateItem("Item", "IItem");

            Assert.NotNull(item);
            Assert.Same(created, item);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:14,代码来源:ComponentModelFixture.cs

示例7: when_mapping_product_then_maps_collection_item_schema

        public void when_mapping_product_then_maps_collection_item_schema()
        {
            var toolkit = new ToolkitSchema("Toolkit", "1.0");
            var schema = toolkit.CreateProductSchema("IProduct");
            var collection = schema.CreateCollectionSchema("ICollection");
            var item = collection.CreateItemSchema("IElement");
            item.CreatePropertySchema("IsPublic", typeof(bool));

            var product = new Product("Product", "IProduct");
            product.CreateCollection("Collection", "ICollection")
                .CreateItem("Element", "IElement")
                .CreateProperty("IsPublic").Value = true;

            ComponentMapper.SyncProduct(product, (IProductInfo)schema);

            Assert.NotNull(product.Components.First().Schema);
            Assert.NotNull(product.Components.OfType<ICollection>().First().Items.First().Schema);
            Assert.NotNull(product.Components.OfType<ICollection>().First().Items.First().Properties.First().Schema);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:19,代码来源:ComponentMapperFixture.cs

示例8: when_creating_duplicate_name_component_then_throws

        public void when_creating_duplicate_name_component_then_throws()
        {
            var product = new Product("Foo", "IFoo");
            var child = product.CreateCollection("Storage", "IStorage");

            // Same name and schema id
            Assert.Throws<ArgumentException>(() => product.CreateCollection("Storage", "IStorage"));
            // Same name, different schema id
            Assert.Throws<ArgumentException>(() => product.CreateCollection("Storage", "IBucket"));

            // Different component type, same name and schema id
            Assert.Throws<ArgumentException>(() => product.CreateElement("Storage", "IStorage"));
            // Different component type, same name, different schema id
            Assert.Throws<ArgumentException>(() => product.CreateElement("Storage", "IBucket"));
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:15,代码来源:ComponentModelFixture.cs

示例9: when_creating_duplicate_name_collection_item_then_throws

        public void when_creating_duplicate_name_collection_item_then_throws()
        {
            var product = new Product("Product", "IProduct");
            var collection = product.CreateCollection("Collection", "ICollection");
            var item = collection.CreateItem("Item", "IItem");

            Assert.Throws<ArgumentException>(() => collection.CreateItem("Item", "IItem"));
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:8,代码来源:ComponentModelFixture.cs

示例10: when_creating_collection_then_it_has_schema

        public void when_creating_collection_then_it_has_schema()
        {
            var info = Mock.Of<IProductInfo>(x =>
                x.Toolkit.Id == "Test" &&
                x.Toolkit.Version == "1.0" &&
                x.SchemaId == "IFoo" &&
                x.Components == new IComponentInfo[]
                {
                    Mock.Of<ICollectionInfo>(e =>
                        e.SchemaId == "ICollection" &&
                        e.Item == Mock.Of<IElementInfo>(i => i.SchemaId == "IElement"))
                });

            var product = new Product("Foo", "IFoo");
            product.Schema = info;

            var child = product.CreateCollection("Buckets", "ICollection");

            Assert.NotNull(child.Schema);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:20,代码来源:ComponentModelFixture.cs

示例11: when_property_changed_on_collection_item_then_raises_property_changed_on_parent

        public void when_property_changed_on_collection_item_then_raises_property_changed_on_parent()
        {
            var product = new Product("Product", "IProduct");
            product
                .CreateCollection("Collection", "ICollection")
                .CreateItem("Item", "IItem")
                .CreateProperty("key").Value = "foo";

            var changed = default(PropertyChangeEventArgs);

            product.Events.PropertyChanged += (sender, args) => changed = args;

            product.Components.OfType<ICollection>().First().Items.First().Set("key", "bar");

            Assert.NotNull(changed);
            Assert.Equal("Collection", changed.PropertyName);
            Assert.Same(changed.OldValue, changed.NewValue);
            Assert.Same(product.Components.First(), changed.NewValue);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:19,代码来源:ComponentModelFixture.cs

示例12: when_enumerating_components_then_can_access_created_collection

        public void when_enumerating_components_then_can_access_created_collection()
        {
            var product = new Product("Foo", "IFoo");
            var child = product.CreateCollection("Buckets", "IBuckets");

            var component = product.Components.FirstOrDefault();

            Assert.NotNull(component);
            Assert.Same(child, component);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:10,代码来源:ComponentModelFixture.cs

示例13: when_disposing_product_then_disposes_entire_graph

        public void when_disposing_product_then_disposes_entire_graph()
        {
            var product = new Product("Product", "IProduct");
            product.CreateCollection("Collection", "ICollection")
                .CreateItem("Item", "IItem");
            product.CreateElement("Element", "IElement")
                .CreateElement("NestedElement", "IElement");

            product.Dispose();

            Assert.True(product.IsDisposed);
            Assert.True(product.Components.All(c => c.IsDisposed));
            Assert.True(product.Components.OfType<Collection>().All(c => c.Items.All(e => e.IsDisposed)));
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:14,代码来源:ComponentModelFixture.cs

示例14: when_deleting_collection_item_then_removes_from_parent_collection

        public void when_deleting_collection_item_then_removes_from_parent_collection()
        {
            var product = new Product("Foo", "IFoo");
            var collection = product.CreateCollection("Collection", "ICollection");
            var child = collection.CreateItem("Item", "IItem");

            child.Delete();

            Assert.Equal(0, collection.Items.Count());
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:10,代码来源:ComponentModelFixture.cs

示例15: when_deleting_collection_item_then_raises_item_deleted

        public void when_deleting_collection_item_then_raises_item_deleted()
        {
            var product = new Product("Foo", "IFoo");
            var collection = product.CreateCollection("Collection", "ICollection");
            var child = collection.CreateItem("Item", "IItem");

            var deleted = default(IElement);
            collection.ItemRemoved += (sender, args) => deleted = args.Value;

            child.Delete();

            Assert.NotNull(deleted);
            Assert.Same(child, deleted);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:14,代码来源:ComponentModelFixture.cs


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