コード例 #1
0
        public void TestFactoryNotExists()
        {
            var engine = new ExecuteEngineConfig()
                         .ConfigureResultMapperFactories(mappers => mappers.Clear())
                         .ToEngine();

            var columns = new[]
            {
                new MockColumn(typeof(long), "Id"),
                new MockColumn(typeof(string), "Name")
            };

            var cmd = new MockDbCommand();

            cmd.SetupResult(new MockDataReader(columns, new List <object[]>()));

            Assert.Throws <AccessorRuntimeException>(() => engine.QueryBuffer <DataEntity>(cmd));
        }
コード例 #2
0
        public void TestMapProperty()
        {
            var engine = new ExecuteEngineConfig().ToEngine();

            var columns = new[]
            {
                new MockColumn(typeof(int), "Column1"),
                new MockColumn(typeof(int), "Column2"),
                new MockColumn(typeof(int), "Column3"),
                new MockColumn(typeof(int), "Column4"),
                new MockColumn(typeof(int), "Column5"),
                new MockColumn(typeof(int), "Column6"),
                new MockColumn(typeof(int), "Column7"),
                new MockColumn(typeof(int), "Column8")
            };
            var values = new List <object[]>
            {
                new object[] { 1, 1, 1, 1, 1, 1, 1, 1 },
                new object[] { DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value, DBNull.Value }
            };

            var cmd = new MockDbCommand();

            cmd.SetupResult(new MockDataReader(columns, values));

            var list = engine.QueryBuffer <MapEntity>(cmd);

            Assert.Equal(2, list.Count);
            Assert.Equal(1, list[0].Column1);
            Assert.Equal(1, list[0].Column2);
            Assert.Equal(1, list[0].Column3);
            Assert.Equal(Value.One, list[0].Column4);
            Assert.Equal(Value.One, list[0].Column5);
            Assert.Equal(0, list[0].Column6);
            Assert.Equal(0, list[0].Column7);

            Assert.Equal(0, list[1].Column1);
            Assert.Null(list[1].Column2);
            Assert.Equal(0, list[1].Column3);
            Assert.Equal(Value.Zero, list[1].Column4);
            Assert.Null(list[1].Column5);
            Assert.Equal(0, list[1].Column6);
            Assert.Equal(0, list[1].Column7);
        }
コード例 #3
0
        public void TestDefaultConstructorRequired()
        {
            var engine = new ExecuteEngineConfig().ToEngine();

            var columns = new[]
            {
                new MockColumn(typeof(int), "Id")
            };
            var values = new List <object[]>
            {
                new object[] { 1 }
            };

            var cmd = new MockDbCommand();

            cmd.SetupResult(new MockDataReader(columns, values));

            Assert.Throws <ArgumentException>(() => engine.QueryBuffer <NoConstructor>(cmd));
        }
コード例 #4
0
        public void TestMapSingle()
        {
            var engine = new ExecuteEngineConfig().ToEngine();

            var columns = new[]
            {
                new MockColumn(typeof(int), "Column1")
            };
            var values = new List <object[]>
            {
                new object[] { 1 },
                new object[] { DBNull.Value }
            };

            var cmd = new MockDbCommand();

            cmd.SetupResult(new MockDataReader(columns, values));

            var list = engine.QueryBuffer <int>(cmd);

            Assert.Equal(2, list.Count);
            Assert.Equal(1, list[0]);
            Assert.Equal(0, list[1]);
        }