public void TestAliasDictionary() { var d = Test123.GetTest123s2(); var dt = d.ToDataReader().ApplyColumnsAliases(new Dictionary <string, string>() { { "Col1", "NewCol1" } }).ToDataTable(); var cols = dt.GetDataColumns().Select(c => c.ColumnName).ToArray(); Assert.AreEqual(cols[0], "NewCol1"); Assert.AreEqual(cols[1], "Col2"); Assert.AreEqual(cols[2], "Col3"); var drow = dt.Rows[0]; //new Test123 {Col1 = 1, Col2 = 1.1m, Col3 = "TestCol3"}, Assert.AreEqual(drow[0], 1); Assert.AreEqual(drow[1], 1.1m); Assert.AreEqual(drow[2], "TestCol3"); Assert.AreEqual(drow["NewCol1"], 1); Assert.AreEqual(drow["Col2"], 1.1m); Assert.AreEqual(drow["Col3"], "TestCol3"); }
public void TestAliasDataAnnotationReverse() { var d = Test123.GetTest123s2(); var dt = d.ToDataReader() .ApplyColumnAlias("Col3", "NewCol3") .ApplyColumnsAliasesReverse <Test123, IDataReader>() .ToDataTable(); var cols = dt.GetDataColumns().Select(c => c.ColumnName).ToArray(); Assert.AreEqual(cols[0], "Col1"); Assert.AreEqual(cols[1], "Col2"); Assert.AreEqual(cols[2], "Col3"); var drow = dt.Rows[0]; //new Test123 {Col1 = 1, Col2 = 1.1m, Col3 = "TestCol3"}, Assert.AreEqual(drow[0], 1); Assert.AreEqual(drow[1], 1.1m); Assert.AreEqual(drow[2], "TestCol3"); Assert.AreEqual(drow["Col1"], 1); Assert.AreEqual(drow["Col2"], 1.1m); Assert.AreEqual(drow["Col3"], "TestCol3"); }
public void TestSmartDataReaderConversions() { var d = Test123.GetTest123s2(); var clientId = Guid.NewGuid(); var dt = DateTime.Now; var dc = ""; var ga = "0.02"; var dr = d.ToDataReader() .AddColumn("ClientId", row => clientId) .AddColumn("Rd", row => dt) .AddColumn("Dc", row => dc) .AddColumn("Ga", row => ga); var destinationColumns = new TypedDataColumnInfo[] { new TypedDataColumnInfo { DataType = typeof(DateTime), Ordinal = 15, ColumnName = "Rd" }, new TypedDataColumnInfo { DataType = typeof(Guid), Ordinal = 4, ColumnName = "ClientId" }, new TypedDataColumnInfo { DataType = typeof(decimal), Ordinal = 8, ColumnName = "Dc" }, new TypedDataColumnInfo { DataType = typeof(decimal), Ordinal = 3, ColumnName = "Ga" } }; var s = new SmartDataReader <IDataReader>(dr, destinationColumns, DataTransformGroups.Default); var r = s.CountRows(); r.ReadToEnd(); Assert.AreEqual(clientId.ToString(), r["ClientId"].ToString()); Assert.AreEqual(dt.ToString(), r["Rd"].ToString()); Assert.AreEqual(null, r["Dc"]); Assert.AreEqual(0.02m, Convert.ToDecimal(r["Ga"].ToString())); }
public void TestAddOneCol() { var d = Test123.GetTest123s2(); var clientId = Guid.NewGuid(); var dr = d.ToDataReader() .AddColumn("ClientId", row => clientId); dr.Read(); Assert.AreEqual(clientId.ToString(), dr["ClientId"].ToString()); }
public void TestAddTwoCol() { var d = Test123.GetTest123s2(); var dt = DateTime.Now; var clientId = Guid.NewGuid(); var dr = d.ToDataReader() .AddColumn("ClientId", row => clientId) .AddColumn("Rd", row => dt); dr.Read(); Assert.AreEqual(clientId.ToString(), dr["ClientId"].ToString()); Assert.AreEqual(dt.ToString(), dr["Rd"].ToString()); }
public void TestAddFilter() { var d = Test123.GetTest123s2(); var clientId = Guid.NewGuid(); var dt = DateTime.Now; var dr = d.ToDataReader() .AddColumn("ClientId", row => clientId) .AddColumn("Rd", row => dt) .Where(row => row["Col1"].ToString() == "111"); dr.ReadToEnd(); Assert.AreEqual(clientId.ToString(), dr["ClientId"].ToString()); Assert.AreEqual(dt.ToString(), dr["Rd"].ToString()); }
public void TestAliasRead() { var d = Test123.GetTest123s2(); var dr = d.ToDataReader().ApplyColumnsAliases(new Dictionary <string, string>() { { "Col1", "NewCol1" } }); dr.Read(); Assert.AreEqual(dr.GetName(0), "NewCol1"); Assert.AreEqual(dr.GetName(1), "Col2"); Assert.AreEqual(dr.GetName(2), "Col3"); Assert.AreEqual(dr[0], 1); Assert.AreEqual(dr[1], 1.1m); Assert.AreEqual(dr[2], "TestCol3"); Assert.AreEqual(dr["NewCol1"], 1); Assert.AreEqual(dr["Col2"], 1.1m); Assert.AreEqual(dr["Col3"], "TestCol3"); }