public void sort_a_block_with_properties_and_nested_blocks() { var block = new ObjectBlock("Test"); block.AddBlock(new PropertyBlock("Prop2")); block.AddBlock(new PropertyBlock("Prop1")); var nested2 = new ObjectBlock("Nested2"); nested2.AddBlock(new PropertyBlock("Prop5")); nested2.AddBlock(new PropertyBlock("Prop3")); block.AddBlock(new ObjectBlock("Nested1")); block.AddBlock(nested2); block.Sort(new BlockSorter()); var blocks = block.Blocks.ToArray(); blocks[0].As <PropertyBlock>().Name.ShouldEqual("Prop1"); blocks[1].As <PropertyBlock>().Name.ShouldEqual("Prop2"); blocks[2].As <ObjectBlock>().Name.ShouldEqual("Nested1"); var nestedProperties = blocks[3].As <ObjectBlock>().Blocks.OfType <PropertyBlock>().ToArray(); nestedProperties[0].Name.ShouldEqual("Prop3"); nestedProperties[1].Name.ShouldEqual("Prop5"); }
public void writes_the_values() { var block = new ObjectBlock(); block.AddBlock(new PropertyBlock("prop1") { Value = "val1"} ); block.AddBlock(new PropertyBlock("prop2") { Value = "val2" } ); block.ToString().ShouldEqual("prop1: 'val1'{0}prop2: 'val2'{0}".ToFormat(Environment.NewLine)); }
public void get_children_for_existing_values() { var block1 = new ObjectBlock(); block1.AddBlock(new PropertyBlock("Url") { Value = "url1" }); var block2 = new ObjectBlock(); block2.AddBlock(new PropertyBlock("Url") { Value = "url2" }); var collection = new CollectionBlock("feeds"); collection.AddBlock(block1); collection.AddBlock(block2); theBlock.AddBlock(collection); var values = theValues.GetChildren("Feeds").ToArray(); values[0].Get("Url").ShouldEqual("url1"); values[1].Get("Url").ShouldEqual("url2"); }
public void get_mapped_children_for_existing_values() { var block1 = new ObjectBlock(); block1.AddBlock(new PropertyBlock("Url") { Value = "url1" }); var block2 = new ObjectBlock(); block2.AddBlock(new PropertyBlock("Url") { Value = "url2" }); var collection = new CollectionBlock("feed"); collection.AddBlock(block1); collection.AddBlock(block2); theBlock.AddBlock(collection); var mappedValueSource = new ObjectBlockValues(theBlock, new FeedObjectSettings(), typeof(Solution)); var values = mappedValueSource.GetChildren("Feeds").ToArray(); values[0].Get("Url").ShouldEqual("url1"); values[1].Get("Url").ShouldEqual("url2"); }
public void sorting_replaces_the_underlying_collection() { var b1 = MockRepository.GenerateStub <IBlock>(); var b2 = MockRepository.GenerateStub <IBlock>(); var sorter = new StubBlockSorter(b1, b2); var block = new ObjectBlock("Test"); block.AddBlock(new PropertyBlock("Prop1")); block.AddBlock(new PropertyBlock("Prop2")); block.Sort(sorter); block.Blocks.ShouldHaveTheSameElementsAs(b1, b2); }
public void sort_a_simple_block_with_properties() { var block = new ObjectBlock("Test"); block.AddBlock(new PropertyBlock("Prop3")); block.AddBlock(new PropertyBlock("Prop2")); block.AddBlock(new PropertyBlock("Prop4")); block.AddBlock(new PropertyBlock("Prop1")); block.Sort(new BlockSorter()); var properties = block.Blocks.Cast <PropertyBlock>().ToArray(); properties[0].Name.ShouldEqual("Prop1"); properties[1].Name.ShouldEqual("Prop2"); properties[2].Name.ShouldEqual("Prop3"); properties[3].Name.ShouldEqual("Prop4"); }
public void get_child_for_existing_values() { var child = new ObjectBlock("test"); child.AddBlock(new PropertyBlock("sub-property")); theBlock.AddBlock(child); theValues.GetChild("test").Has("sub-property").ShouldBeTrue(); }
public void has_child() { var child = new ObjectBlock("test"); child.AddBlock(new PropertyBlock("sub-property")); theBlock.AddBlock(child); theValues.HasChild("test").ShouldBeTrue(); }