AddRow() public method

public AddRow ( ) : void
return void
コード例 #1
0
        public void Creating_child_instances_from_two_rows_with_two_children_referencing_same_parent_gives_two_children_referencing_same_parent_instance()
        {
            var resultSet = new ResultSet();

            resultSet.AddRow(new ColumnValue("Child Id", 1), new ColumnValue("Parent Id", _guid1));
            resultSet.AddRow(new ColumnValue("Child Id", 2), new ColumnValue("Parent Id", _guid1));

            var children = _mapper.CreateInstanceGraphs<Child>(resultSet, _childParentRelation);

            Assert.AreEqual(2, children.Count);

            var parent = children.First().Parent;

            Assert.AreEqual(1, children.First().Id);
            Assert.AreEqual(2, children.Last().Id);
            Assert.AreEqual(_guid1, parent.Id);

            Assert.AreSame(parent, children.Last().Parent);

            Assert.AreEqual(2, parent.Children.Count);
            CollectionAssert.Contains(parent.Children, children.First());
            CollectionAssert.Contains(parent.Children, children.Last());
        }
コード例 #2
0
        public void Creating_instances_from_two_rows_with_single_parent_with_two_children_gives_single_parent_with_two_children()
        {
            var resultSet = new ResultSet();

            resultSet.AddRow(new ColumnValue("Child Id", 1), new ColumnValue("Parent Id", _guid1));
            resultSet.AddRow(new ColumnValue("Child Id", 2), new ColumnValue("Parent Id", _guid1));

            var parents = _mapper.CreateInstanceGraphs<Parent>(resultSet, _parentChildRelation);

            Assert.AreEqual(1, parents.Count);

            var parent = parents.First();
            var children = parent.Children;

            Assert.AreEqual(1, children.First().Id);
            Assert.AreEqual(2, children.Last().Id);
            Assert.AreSame(parent, children.First().Parent);
            Assert.AreSame(parent, children.Last().Parent);
        }
コード例 #3
0
        public void Two_rows_sharing_some_entities_are_mapped_to_two_hierachies_sharing_instances()
        {
            var resultSet = new ResultSet();

            resultSet.AddRow(new ColumnValue("Parent Id", _guid1), new ColumnValue("Child Id", 1), new ColumnValue("GrandChild Id", 2));
            resultSet.AddRow(new ColumnValue("Parent Id", _guid2), new ColumnValue("Child Id", 3), new ColumnValue("GrandChild Id", 2));
            resultSet.AddRow(new ColumnValue("Parent Id", _guid1), new ColumnValue("Child Id", 2), new ColumnValue("GrandChild Id", 4));
            resultSet.AddRow(new ColumnValue("Parent Id", _guid1), new ColumnValue("Child Id", 2), new ColumnValue("GrandChild Id", 5));

            var parents = _mapper.CreateInstanceGraphs<Parent>(resultSet, new [] { _parentChildRelation, _childGrandChildRelation });

            Assert.AreEqual(2, parents.Count);

            var firstParent = parents.First();
            var secondParent = parents.Last();
            var firstParentChild1 = firstParent.Children.FirstOrDefault();
            var firstParentChild2 = firstParent.Children.LastOrDefault();
            var secondParentChild = secondParent.Children.FirstOrDefault();

            Assert.AreEqual(2, firstParent.Children.Count);
            Assert.AreEqual(1, firstParentChild1.GrandChildren.Count);
            Assert.AreEqual(2, firstParentChild2.GrandChildren.Count);

            Assert.AreEqual(_guid1, firstParent.Id);
            Assert.AreEqual(1, firstParentChild1.Id);
            Assert.AreEqual(2, firstParentChild1.GrandChildren.First().Id);
            Assert.AreEqual(2, firstParentChild2.Id);
            Assert.AreEqual(4, firstParentChild2.GrandChildren.First().Id);
            Assert.AreEqual(5, firstParentChild2.GrandChildren.Last().Id);

            Assert.AreEqual(_guid2, secondParent.Id);
            Assert.AreEqual(3, secondParentChild.Id);
            Assert.AreEqual(2, secondParentChild.GrandChildren.First().Id);

            Assert.AreSame(firstParentChild1.GrandChildren.First(), secondParentChild.GrandChildren.First());
        }
コード例 #4
0
        public void Rows_in_result_set_without_id_column_values_are_mapped_to_separate_entities_even_though_columns_values_match()
        {
            var resultSet = new ResultSet();

            resultSet.AddRow(new ColumnValue("ParentWithoutId Name", "First name"), new ColumnValue("ChildWithoutId Name", "child name 0"));
            resultSet.AddRow(new ColumnValue("ParentWithoutId Name", "Another first name"), new ColumnValue("ChildWithoutId Name", "child name 1"));
            resultSet.AddRow(new ColumnValue("ParentWithoutId Name", "First name"), new ColumnValue("ChildWithoutId Name", "child name 2"));

            var parents = _mapper.CreateInstanceGraphs<ParentWithoutId>(resultSet, new[] { _idLessRelation });

            Assert.AreEqual(3, parents.Count);

            Assert.AreEqual(1, parents[0].Children.Count);
            Assert.AreEqual(1, parents[1].Children.Count);
            Assert.AreEqual(1, parents[2].Children.Count);

            Assert.AreEqual("First name", parents[0].Name);
            Assert.AreEqual("Another first name", parents[1].Name);
            Assert.AreEqual("First name", parents[2].Name);

            Assert.AreEqual("child name 0", parents[0].Children[0].Name);
            Assert.AreEqual("child name 1", parents[1].Children[0].Name);
            Assert.AreEqual("child name 2", parents[2].Children[0].Name);

            Assert.AreEqual(parents[0], parents[0].Children[0].Parent);
            Assert.AreEqual(parents[1], parents[1].Children[0].Parent);
            Assert.AreEqual(parents[2], parents[2].Children[0].Parent);
        }