示例#1
0
        public void PkMappingTest()
        {
            var container = new Container();

            container.Setup(c => c.ScanType <ISimpleEntity>());

            var locator = container.GetLocator();

            var reader = new DataReaderMock("ISimpleEntity.Id", "ISimpleEntity.Text", "ISimpleEntity.Number");

            reader.Add(1, "Text1", 42);
            reader.Add(2, "Text2", 84);

            var entities = ResultSetReader.Read <ISimpleEntity>(reader, locator).ToList();

            Assert.Equal(2, entities.Count);

            for (var i = 1; i < 3; i++)
            {
                var entity = entities[i - 1];

                Assert.Equal(i, entity.Id);
                Assert.Equal($"Text{i}", entity.Text);
                Assert.Equal(42 * i, entity.Number);
            }
        }
示例#2
0
        public void TestHierarchicaMapping()
        {
            var container = new Container();

            container.Setup(c => c.ScanType <IHierarchy>());

            var locator = container.GetLocator();

            var reader = new DataReaderMock("IHierarchy.Id", "IHierarchy.Friend.Id", "IHierarchy.Children.Id", "IHierarchy.Children.Children.Id");

            reader.Add("A", "Friend_Of_A", "ChildOfA_1", "ChildOfChildOfA1_1");
            reader.Add("A", "Friend_Of_A", "ChildOfA_1", "ChildOfChildOfA1_2");
            reader.Add("A", "Friend_Of_A", "ChildOfA_2", "ChildOfChildOfA2_1");

            var entities = ResultSetReader.Read <IHierarchy>(reader, locator).ToList();

            Assert.Equal(1, entities.Count);

            Assert.Equal("A", entities[0].Id);
            Assert.Equal(2, entities[0].Children.Count());

            Assert.Equal(2, entities[0].Children.First().Children.Count());
            Assert.Equal(1, entities[0].Children.Last().Children.Count());

            Assert.Equal("ChildOfChildOfA2_1", entities[0].Children.Last().Children.Single().Id);

            Assert.NotNull(entities[0].Friend);
            Assert.Equal("Friend_Of_A", entities[0].Friend.Id);
        }
示例#3
0
        public void TestReader()
        {
            var reader = new DataReaderMock("A", "A.B", "A.C", "A.B.A");

            reader.Add("A1", "A.B1", "A.C1", "A.B.A1");

            Assert.True(reader.Read());

            Assert.False(reader.IsNull("A"));
            Assert.Equal("A1", reader.Get <string>("A"));
            Assert.True(reader.IsNull("B"));

            var child = reader.GetDeeperReader("A");

            Assert.True(child.IsNull("A"));
            Assert.Equal("A.B1", child.Get <string>("B"));
            Assert.Equal("A.C1", child.Get <string>("C"));

            child = child.GetDeeperReader("B");
            Assert.True(child.IsNull("B"));
            Assert.True(child.IsNull("C"));
            Assert.Equal("A.B.A1", child.Get <string>("A"));
        }
示例#4
0
        protected override IDataReader CreateChildReader(string childPath, List <string> columnIndex)
        {
            var child = new DataReaderMock(childPath, m_columns.ToList(), m_position, m_data);

            return(child);
        }