public void TestResultMapperForDifferentTypeSameResult() { var engine = new ExecuteEngineConfig().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[]>())); cmd.SetupResult(new MockDataReader(columns, new List <object[]>())); engine.QueryBuffer <CacheEntity>(cmd); Assert.Equal(1, ((IEngineController)engine).Diagnostics.ResultMapperCacheCount); engine.QueryBuffer <Cache2Entity>(cmd); Assert.Equal(2, ((IEngineController)engine).Diagnostics.ResultMapperCacheCount); ((IEngineController)engine).ClearResultMapperCache(); Assert.Equal(0, ((IEngineController)engine).Diagnostics.ResultMapperCacheCount); }
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)); }
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); }
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)); }
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]); }
public void TestCustomParser() { var engine = new ExecuteEngineConfig().ToEngine(); var columns = new[] { new MockColumn(typeof(long), "Id"), new MockColumn(typeof(string), "Name") }; var values = new List <object[]> { new object[] { "1", 2 } }; var cmd = new MockDbCommand(); cmd.SetupResult(new MockDataReader(columns, values)); var entity = engine.QueryFirstOrDefault <ParserEntity>(cmd); Assert.NotNull(entity); Assert.Equal(1, entity.Id); Assert.Equal("2", entity.Name); }