示例#1
0
        public void when_creating_name_property_then_throws_because_its_reserved()
        {
            var toolkit = new ToolkitSchema("FooToolkit", "1.0");

            Assert.Throws<ArgumentException>(() =>
                toolkit.CreateProductSchema("IFoo").CreatePropertySchema("Name", typeof(string)));
        }
        public void when_creating_product_then_sets_its_toolkit_property()
        {
            var toolkit = new ToolkitSchema("FooToolkit", "1.0");
            var product = toolkit.CreateProductSchema("Product");

            Assert.NotNull(product.Toolkit);
            Assert.Same(toolkit, product.Toolkit);
        }
示例#3
0
        public void when_creating_duplicate_named_property_then_throws()
        {
            var toolkit = new ToolkitSchema("FooToolkit", "1.0");
            var product = toolkit.CreateProductSchema("IFoo");

            product.CreatePropertySchema("IsVisible", typeof(bool));

            Assert.Throws<ArgumentException>(() => product.CreatePropertySchema("IsVisible", typeof(bool)));
        }
        public void when_mapping_product_then_does_not_remove_underscore_properties()
        {
            var toolkit = new ToolkitSchema("Toolkit", "1.0");
            var schema = toolkit.CreateProductSchema("IProduct");

            var product = new Product("Product", "IProduct");
            product.CreateProperty("_IsVisible").Value = true;

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

            Assert.NotNull(product.Schema);
            Assert.Equal(1, product.Properties.Count());
            Assert.Equal("_IsVisible", product.Properties.First().Name);
            Assert.True((bool)product.Properties.First().Value);
        }
        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);
        }
        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);
        }
 public ProductSchemaFixture()
 {
     var toolkit = new ToolkitSchema("Test", "1.0");
     product = toolkit.CreateProductSchema("Product");
 }
        public void when_mapping_product_then_removes_properties_that_dont_exist_in_schema()
        {
            var toolkit = new ToolkitSchema("Toolkit", "1.0");
            var schema = toolkit.CreateProductSchema("IProduct");
            schema.CreatePropertySchema("IsPublic", typeof(bool));

            var product = new Product("Product", "IProduct");
            product.CreateProperty("IsVisible").Value = true;

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

            Assert.NotNull(product.Schema);
            Assert.Equal(1, product.Properties.Count());
            Assert.Equal("IsPublic", product.Properties.First().Name);
            Assert.False((bool)product.Properties.First().Value);
        }
        public void when_mapping_product_then_removes_elements_with_no_matching_schema()
        {
            var toolkit = new ToolkitSchema("Toolkit", "1.0");
            var schema = toolkit.CreateProductSchema("IProduct");
            schema.CreateElementSchema("IElement");

            var product = new Product("Product", "IProduct");
            var element = product.CreateElement("Element", "IFoo");

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

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

            Assert.Equal(0, product.Components.Count());
            Assert.Null(element.Parent);
        }
        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);
        }