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 object?RawAdoNet() { var toExecute = new MockDbCommand(CommandText + " WHERE SalesOrderId=@p", _result); toExecute.Parameters.Add(new MockDbParameter("@p", _key)); var results = MaterializeSet(toExecute); return(results.FirstOrDefault()); }
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); }
public MockDbParameter(MockDbCommand mockDbCommand, int paramId) { this.mockDbCommand = mockDbCommand; this.paramId = paramId; }
public MockParameterCollection(MockDbCommand command) { this.command = command; }
private IEnumerable <SalesOrderHeader> MaterializeSet(MockDbCommand toExecute) { var headers = new List <SalesOrderHeader>(); using (var con = new MockDbConnection(ConnectionString, _result)) { toExecute.Connection = con; con.Open(); var reader = toExecute.ExecuteReader(); while (reader.Read()) { var soh = new SalesOrderHeader(); // using IsDBNull(ordinal) is slow, however it allows the usage of the typed Get<type>(ordinal) methods. This avoids // boxing / unboxing of the value again, which enhances performance more than IsDBNull can slow it down. soh.SalesOrderID = reader.GetInt32(0); if (!reader.IsDBNull(1)) { soh.AccountNumber = reader.GetString(1); } if (!reader.IsDBNull(2)) { soh.Comment = reader.GetString(2); } if (!reader.IsDBNull(3)) { soh.CreditCardApprovalCode = reader.GetString(3); } soh.DueDate = reader.GetDateTime(4); soh.Freight = reader.GetDecimal(5); soh.ModifiedDate = reader.GetDateTime(6); soh.OnlineOrderFlag = reader.GetBoolean(7); soh.OrderDate = reader.GetDateTime(8); if (!reader.IsDBNull(9)) { soh.PurchaseOrderNumber = reader.GetString(9); } soh.RevisionNumber = reader.GetByte(10); soh.Rowguid = reader.GetGuid(11); soh.SalesOrderNumber = reader.GetString(12); if (!reader.IsDBNull(13)) { soh.ShipDate = reader.GetDateTime(13); } soh.Status = reader.GetByte(14); soh.SubTotal = reader.GetDecimal(15); soh.TaxAmt = reader.GetDecimal(16); soh.TotalDue = reader.GetDecimal(17); soh.CustomerID = reader.GetInt32(18); if (!reader.IsDBNull(19)) { soh.SalesPersonID = reader.GetInt32(19); } if (!reader.IsDBNull(20)) { soh.TerritoryID = reader.GetInt32(20); } soh.BillToAddressID = reader.GetInt32(21); soh.ShipToAddressID = reader.GetInt32(22); soh.ShipMethodID = reader.GetInt32(23); if (!reader.IsDBNull(24)) { soh.CreditCardID = reader.GetInt32(24); } if (!reader.IsDBNull(25)) { soh.CurrencyRateID = reader.GetInt32(25); } headers.Add(soh); } reader.Close(); reader.Dispose(); con.Close(); } return(headers); }
public void CallByDbHandler() { var cmd = new MockDbCommand(); ParameterBuilder.Build(cmd, "p1", DbType.Object, handler, string.Empty); }
public void FuncByHandler() { var cmd = new MockDbCommand(); func2(cmd, string.Empty); }
public void FuncByDbType() { var cmd = new MockDbCommand(); func1(cmd, string.Empty); }