Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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());
        }
Пример #6
0
        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);
        }
Пример #7
0
        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);
        }
Пример #8
0
        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"));
        }
Пример #9
0
        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"));
        }
Пример #10
0
        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);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
        }
Пример #13
0
        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)));
        }
Пример #14
0
        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());
        }
Пример #15
0
        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);
        }
Пример #16
0
        public void when_mapping_product_then_removes_collections_with_no_matching_schema()
        {
            var toolkit = new ToolkitSchema("Toolkit", "1.0");
            var schema = toolkit.CreateProductSchema("IProduct");

            var product = new Product("Product", "IProduct");
            var collection = product.CreateCollection("Collection", "IFoo");

            Assert.Equal(1, product.Components.Count());

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

            Assert.Equal(0, product.Components.Count());
            Assert.Null(collection.Parent);
        }