예제 #1
0
        public void CreateStructure_WhenHashSetOfComplex_ReturnsOneIndexPerElementInCorrectOrder()
        {
            Builder = StructureBuilder.Create(c => c.Register <TestItemWithHashSetOfComplex>());
            var item = new TestItemWithHashSetOfComplex
            {
                HashSetOfComplex = new HashSet <Value>
                {
                    new Value {
                        Is = 5
                    },
                    new Value {
                        Is = 6
                    },
                    new Value {
                        Is = 7
                    }
                }
            };

            var structure = Builder.CreateStructure(item);

            var indices = structure.Indexes.Where(i => i.Path.StartsWith("HashSetOfComplex[")).ToList();

            Assert.AreEqual(5, indices[0].Value);
            Assert.AreEqual(6, indices[1].Value);
            Assert.AreEqual(7, indices[2].Value);
        }
예제 #2
0
        public void CreateStructure_WhenDictionary_ReturnsOneIndexPerElementInCorrectOrder()
        {
            Builder = StructureBuilder.Create(c => c.Register <TestItemWithDictionary>());
            var item = new TestItemWithDictionary {
                KeyValues = new Dictionary <string, int> {
                    { "Key1", 5 }, { "Key2", 6 }, { "Key3", 7 }
                }
            };

            var structure = Builder.CreateStructure(item);

            var indices = structure.Indexes.Where(i => i.Path.StartsWith("KeyValues")).ToList();

            Assert.AreEqual(6, indices.Count);

            Assert.AreEqual("KeyValues[0].Key", indices[0].Path);
            Assert.AreEqual("Key1", indices[0].Value);
            Assert.AreEqual("KeyValues[1].Key", indices[1].Path);
            Assert.AreEqual("Key2", indices[1].Value);
            Assert.AreEqual("KeyValues[2].Key", indices[2].Path);
            Assert.AreEqual("Key3", indices[2].Value);

            Assert.AreEqual("KeyValues[0].Value", indices[3].Path);
            Assert.AreEqual(5, indices[3].Value);
            Assert.AreEqual("KeyValues[1].Value", indices[4].Path);
            Assert.AreEqual(6, indices[4].Value);
            Assert.AreEqual("KeyValues[2].Value", indices[5].Path);
            Assert.AreEqual(7, indices[5].Value);
        }
예제 #3
0
        public void CreateStructure_WhenChildItemWithInheritedNullablesHasNullValues_NoIndexesAreCreated()
        {
            Builder = StructureBuilder.Create(c => c.Register <ChildWithNullables>());
            var item = ChildWithNullables.CreateWithNullValues();

            var structure = Builder.CreateStructure(item);

            structure.Indexes.Should().BeEmpty();
        }
예제 #4
0
        public void CreateStructure_When_structure_has_null_collection_It_should_create_structure_with_index_for_other_members()
        {
            Builder = StructureBuilder.Create(c => c.Register <WithNullCollection>());
            var item = new WithNullCollection {
                Temp = "Foo", Values = null
            };

            var structure = Builder.CreateStructure(item);

            Assert.AreEqual(1, structure.Indexes.Count);
            Assert.AreEqual("Temp", structure.Indexes[0].Path);
        }
예제 #5
0
        public void CreateStructure_WhenSetOfIntsIsNull_ReturnsNoIndex()
        {
            Builder = StructureBuilder.Create(c => c.Register <TestItemWithISet>());
            var item = new TestItemWithISet {
                SetOfInts = null
            };

            var structure = Builder.CreateStructure(item);

            var actual = structure.Indexes.SingleOrDefault(si => si.Path.StartsWith("SetOfInts"));

            Assert.IsNull(actual);
        }
예제 #6
0
        public void CreateStructure_WhenUIntOnFirstLevel_ReturnsSimpleValue()
        {
            Builder = StructureBuilder.Create(c => c.Register <TestItemForFirstLevel>());
            var item = new TestItemForFirstLevel {
                UIntValue = 42
            };

            var structure = Builder.CreateStructure(item);

            var actual = structure.Indexes.Single(si => si.Path == "UIntValue").Value;

            actual.Should().Be((uint)42);
        }
예제 #7
0
        public void CreateStructure_WhenIntOnFirstLevel_ReturnsSimpleValue()
        {
            Builder = StructureBuilder.Create(c => c.Register <TestItemForFirstLevel>());
            var item = new TestItemForFirstLevel {
                IntValue = 42
            };

            var structure = Builder.CreateStructure(item);

            var actual = structure.Indexes.Single(si => si.Path == "IntValue").Value;

            Assert.AreEqual(42, actual);
        }
예제 #8
0
        public void CreateStructure_WhenEnumerableIntsOnFirstLevelAreNull_ReturnsNoIndex()
        {
            Builder = StructureBuilder.Create(c => c.Register <TestItemForFirstLevel>());
            var item = new TestItemForFirstLevel {
                IntArray = null
            };

            var structure = Builder.CreateStructure(item);

            var actual = structure.Indexes.SingleOrDefault(si => si.Path.StartsWith("IntArray"));

            Assert.IsNull(actual);
        }
예제 #9
0
        public void CreateStructure_WhenStructureContainsStructWithValue_ValueOfStructIsRepresentedInIndex()
        {
            Builder = StructureBuilder.Create(c => c.Register <IHaveStruct>());
            var item = new IHaveStruct {
                Content = "My content"
            };

            var structure = Builder.CreateStructure(item);

            Assert.AreEqual(1, structure.Indexes.Count);
            Assert.AreEqual("Content", structure.Indexes[0].Path);
            Assert.AreEqual(typeof(MyText), structure.Indexes[0].DataType);
            Assert.AreEqual(new MyText("My content"), structure.Indexes[0].Value);
        }
예제 #10
0
        public void Should_be_able_to_index_nested_child_by_registrating_child_only()
        {
            Builder = StructureBuilder.Create(c => c.Register <MyRoot>(cfg => cfg
                                                                       .UsingIndexMode(IndexMode.Inclusive)
                                                                       .Members(e => e.OneChild.GrandChild.SomeInt)));

            var item = new MyRoot
            {
                SomeString = "Foo Bar",
                SomeInt    = 1,
                OneChild   = new MyChild
                {
                    SomeString = "One child",
                    SomeInt    = 2,
                    GrandChild = new MyGrandChild
                    {
                        SomeString = "Grand child 2.1",
                        SomeInt    = 21
                    }
                },
                ManyChildren = new List <MyChild>
                {
                    new MyChild
                    {
                        SomeString = "List Child1",
                        SomeInt    = 3,
                        GrandChild = new MyGrandChild
                        {
                            SomeString = "Grand child 3.1",
                            SomeInt    = 31
                        }
                    },
                    new MyChild
                    {
                        SomeString = "List Child2",
                        SomeInt    = 4,
                        GrandChild = new MyGrandChild
                        {
                            SomeString = "Grand child 4.1",
                            SomeInt    = 41
                        }
                    }
                }
            };

            var structure = Builder.CreateStructure(item);

            Assert.AreEqual(1, structure.Indexes.Count);
        }
예제 #11
0
        public void CreateStructure_WhenHashSetOfComplex_HasThreeNullItems_ReturnsNoIndex()
        {
            Builder = StructureBuilder.Create(c => c.Register <TestItemWithHashSetOfComplex>());
            var item = new TestItemWithHashSetOfComplex {
                HashSetOfComplex = new HashSet <Value> {
                    null, null, null
                }
            };

            var structure = Builder.CreateStructure(item);

            var actual = structure.Indexes.SingleOrDefault(si => si.Path.StartsWith("HashSetOfComplex.Is"));

            Assert.IsNull(actual);
        }
예제 #12
0
        public void CreateStructure_WhenEnumerableIntsOnFirstLevel_ReturnsOneIndexPerElementInCorrectOrder()
        {
            Builder = StructureBuilder.Create(c => c.Register <TestItemForFirstLevel>());
            var item = new TestItemForFirstLevel {
                IntArray = new[] { 5, 6, 7 }
            };

            var structure = Builder.CreateStructure(item);

            var indices = structure.Indexes.Where(i => i.Path.StartsWith("IntArray[")).ToList();

            Assert.AreEqual(5, indices[0].Value);
            Assert.AreEqual(6, indices[1].Value);
            Assert.AreEqual(7, indices[2].Value);
        }
예제 #13
0
        public void CreateStructure_WhenISetOfInts_ReturnsOneIndexPerElementInCorrectOrder()
        {
            Builder = StructureBuilder.Create(c => c.Register <TestItemWithISet>());
            var item = new TestItemWithISet {
                SetOfInts = new HashSet <int> {
                    5, 6, 7
                }
            };

            var structure = Builder.CreateStructure(item);

            var indices = structure.Indexes.Where(i => i.Path.StartsWith("SetOfInts[")).ToList();

            Assert.AreEqual(5, indices[0].Value);
            Assert.AreEqual(6, indices[1].Value);
            Assert.AreEqual(7, indices[2].Value);
        }
예제 #14
0
        public void CreateStructure_WhenChildItemWithInheritedNullablesHasValues_IndexesAreCreated()
        {
            Builder = StructureBuilder.Create(c => c.Register <ChildWithNullables>());
            var item = ChildWithNullables.CreatePopulated();

            var structure = Builder.CreateStructure(item);

            Assert.AreEqual(2, structure.Indexes.Count);

            Assert.AreEqual("NullableInt", structure.Indexes[0].Path);
            Assert.AreEqual(typeof(int?), structure.Indexes[0].DataType);
            Assert.AreEqual(item.NullableInt, structure.Indexes[0].Value);

            Assert.AreEqual("NullableGuid", structure.Indexes[1].Path);
            Assert.AreEqual(typeof(Guid?), structure.Indexes[1].DataType);
            Assert.AreEqual(item.NullableGuid, structure.Indexes[1].Value);
        }
예제 #15
0
        public void CreateStructure_When_5thLevel_has_null_values_It_should_create_structure_with_index_for_other_members()
        {
            Builder = StructureBuilder.Create(c => c.Register <TestItemForFifthLevel>());
            var item = new TestItemForFifthLevel
            {
                Containers = new List <Container>()
                {
                    new Container()
                    {
                        IntValue = 27,
                        MyItem   = new Item()
                    }
                }
            };

            var structure = Builder.CreateStructure(item);

            Assert.AreEqual(1, structure.Indexes.Count);
            Assert.AreEqual("Containers[0].IntValue", structure.Indexes[0].Path);
        }
예제 #16
0
        public void CreateStructure_WhenCustomNonGenericEnumerableWithComplexElement_ReturnsIndexesForElements()
        {
            Builder = StructureBuilder.Create(c => c.Register <ModelForMyCustomNonGenericEnumerable>());
            var item = new ModelForMyCustomNonGenericEnumerable();

            item.Items.Add(new MyElement {
                IntValue = 1, StringValue = "A"
            });
            item.Items.Add(new MyElement {
                IntValue = 2, StringValue = "B"
            });

            var structure = Builder.CreateStructure(item);

            var indices = structure.Indexes;

            Assert.AreEqual("A", indices[0].Value);
            Assert.AreEqual("B", indices[1].Value);
            Assert.AreEqual(1, indices[2].Value);
            Assert.AreEqual(2, indices[3].Value);
        }
예제 #17
0
 public StructureBuilderGraphTests()
 {
     Builder = StructureBuilder.Create(c => c.Register <Root>());
 }