本文整理汇总了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"));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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");
}
示例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)));
}
示例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"));
}
示例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);
}
示例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());
}
示例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);
}
示例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);
}