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


C# Product.CreateElement方法代码示例

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


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

示例1: when_creating_component_named_as_property_then_throws

        public void when_creating_component_named_as_property_then_throws()
        {
            var product = new Product("Foo", "IFoo");
            product.CreateProperty("Element");

            Assert.Throws<ArgumentException>(() => product.CreateElement("Element", "IElement"));
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:7,代码来源:ComponentModelFixture.cs

示例2: 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

示例3: when_mapping_product_then_maps_component_schema

        public void when_mapping_product_then_maps_component_schema()
        {
            var toolkit = new ToolkitSchema("Toolkit", "1.0");
            var schema = toolkit.CreateProductSchema("IProduct");
            var element = schema.CreateElementSchema("IElement");
            element.CreatePropertySchema("IsPublic", typeof(bool));

            var product = new Product("Product", "IProduct");
            product.CreateElement("Element", "IElement")
                .CreateProperty("IsPublic").Value = true;

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

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

示例4: when_disposing_element_then_does_not_raise_deleted_event

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

            var deleted = false;
            child.Events.Deleted += (s, e) => deleted = true;

            child.Dispose();

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

示例5: when_creating_element_then_it_has_schema_defined_properties

        public void when_creating_element_then_it_has_schema_defined_properties()
        {
            var product = new Product("Foo", "IFoo");
            var info = Mock.Of<IProductInfo>(x =>
                x.Toolkit.Id == "Test" &&
                x.Toolkit.Version == "1.0" &&
                x.SchemaId == "IFoo" &&
                x.Components == new IComponentInfo[]
                {
                    Mock.Of<IElementInfo>(e =>
                        e.SchemaId == "IElement" &&
                        e.Properties == new []
                        {
                            Mock.Of<IPropertyInfo>(p => p.Name == "IsPublic" && p.PropertyType == typeof(bool))
                        })
                });

            product.Schema = info;

            var child = product.CreateElement("Element", "IElement");

            Assert.Equal(1, child.Properties.Count());
            Assert.Equal("IsPublic", child.Properties.First().Name);
            Assert.NotNull(child.Properties.First().Schema);
            Assert.Equal(typeof(bool), child.Properties.First().Schema.PropertyType);
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:26,代码来源:ComponentModelFixture.cs

示例6: when_creating_element_then_it_has_schema

        public void when_creating_element_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<IElementInfo>(e => e.SchemaId == "IElement")
                });

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

            var child = product.CreateElement("Element", "IElement");

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

示例7: when_property_changed_on_element_then_raises_property_changed_on_parent

        public void when_property_changed_on_element_then_raises_property_changed_on_parent()
        {
            var product = new Product("Product", "IProduct");
            product.CreateElement("Element", "IElement")
                .CreateProperty("key").Value = "foo";

            var changed = default(PropertyChangeEventArgs);

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

            product.Components.First().Set("key", "bar");

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

示例8: when_enumerating_components_then_can_access_created_element

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

            var component = product.Components.FirstOrDefault();

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

示例9: when_element_new_name_is_duplicated_with_other_element_then_throws

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

            product.CreateElement("Storage", "IStorage");

            var child = product.CreateElement("Storage2", "IStorage");

            Assert.Throws<ArgumentException>(() => child.Name = "Storage");
        }
开发者ID:NuPattern,项目名称:CodeFirst,代码行数:10,代码来源:ComponentModelFixture.cs

示例10: 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

示例11: 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

示例12: when_deleting_element_then_raises_component_removed

        public void when_deleting_element_then_raises_component_removed()
        {
            var product = new Product("Foo", "IFoo");
            var removed = default(IComponent);
            var child = product.CreateElement("Storage", "IStorage");

            product.ComponentRemoved += (sender, args) => removed = args.Value;

            child.Delete();

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

示例13: when_deleting_renamed_element_then_removes_from_parent_components

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

            child.Name = "Bar";
            child.Delete();

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

示例14: when_deleting_element_then_disposes_it

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

            child.Delete();

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

示例15: when_creating_hierarchy_then_can_access_owning_product

        public void when_creating_hierarchy_then_can_access_owning_product()
        {
            var product = new Product("Foo", "IFoo");
            var child = product.CreateElement("Bar", "IBar").CreateElement("Baz", "IBaz");

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


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