public void TypedDataSet() { int i = 0; //check dataset constructor myTypedDataSet ds = null; DataSet unTypedDs = new DataSet(); ds = new myTypedDataSet(); Assert.IsFalse(ds == null ,"TDS0" ); Assert.AreEqual(typeof(myTypedDataSet), ds.GetType() ,"TDS1" ); // fill dataset ds.ReadXml("Test/System.Data/TypedDataSet.xml"); // check DataSet named property "Orders" myTypedDataSet.OrdersDataTable tblOrders = null; tblOrders = ds.Orders; Assert.AreEqual(ds.Tables["Orders"],tblOrders ,"TDS2"); //check DataSet named property Orders - by index"); tblOrders = ds.Orders; Assert.AreEqual(ds.Tables[1],tblOrders ,"TDS3"); //add new row AddTableNameRow, check row count"); i = tblOrders.Rows.Count; tblOrders.AddOrdersRow("SAVEA",1,new DateTime(1998,05,01,00,00,00,000) ,new DateTime(1998,05,29,00,00,00,000) ,new DateTime(1998,05,04,00,00,00,000),1,30.0900m ,"Save-a-lot Markets","187 Suffolk Ln.","Boise","ID","83720","USA"); Assert.AreEqual(i+1 ,tblOrders.Rows.Count,"TDS5"); //check the new row AutoIncrement field - AddTableNameRow i = (int)tblOrders.Rows[tblOrders.Rows.Count-2][0]; Assert.AreEqual(i+1 ,(int)tblOrders.Rows[tblOrders.Rows.Count-1][0],"TDS6"); //Create New Row using NewTableNameRow, check row != null myTypedDataSet.OrdersRow drOrders = null; drOrders = tblOrders.NewOrdersRow(); Assert.IsFalse(drOrders == null ,"TDS7"); //Create New Row using NewTableNameRow, check row state Assert.AreEqual(DataRowState.Detached, drOrders.RowState , "TDS8"); //add new row NewTableNameRow, check row count //drOrders.OrderID = DBNull.Value; drOrders.CustomerID = "GREAL"; drOrders.EmployeeID = 4; drOrders.OrderDate = new DateTime(1998,04,30,00,00,00,000); drOrders.RequiredDate = new DateTime(1998,06,11,00,00,00,000); drOrders["ShippedDate"] = DBNull.Value; drOrders.ShipVia = 3; drOrders.Freight = 14.0100m; drOrders.ShipName = "Great Lakes"; drOrders.ShipAddress = "Food Market"; drOrders.ShipCity = "Baker Blvd."; drOrders.ShipRegion = "Eugene"; drOrders.ShipPostalCode = "OR 97403"; drOrders.ShipCountry = "USA"; i = tblOrders.Rows.Count; tblOrders.AddOrdersRow(drOrders); Assert.AreEqual(i+1 ,tblOrders.Rows.Count,"TDS9"); //check StrongTypingException try { DateTime d = drOrders.ShippedDate; //drOrders.ShippedDate = null, will raise exception Assert.Fail("TDS10: Failed to throw StrongTypingException"); } catch (StrongTypingException) {} catch (AssertionException exc) {throw exc;} catch (Exception exc) { Assert.Fail("TDS11: Wrong exception type. Got:" + exc); } //check the new row AutoIncrement field - NewTableNameRow i = (int)tblOrders.Rows[tblOrders.Rows.Count-2][0]; Assert.AreEqual(i+1 ,(int)tblOrders.Rows[tblOrders.Rows.Count-1][0],"TDS12"); // convenience IsNull functions // only if it can be null Assert.IsFalse(drOrders.IsShipAddressNull() ,"TDS13"); drOrders.SetShipAddressNull(); Assert.IsTrue(drOrders.IsShipAddressNull() ,"TDS14"); // Table exposes a public property Count == table.Rows.Count Assert.AreEqual(tblOrders.Count ,tblOrders.Rows.Count , "TDS15"); // find function myTypedDataSet.OrdersRow dr = tblOrders[0]; Assert.AreEqual(tblOrders.FindByOrderID(dr.OrderID),dr,"TDS16" ); //Remove row and check row count i = tblOrders.Count; myTypedDataSet.OrdersRow drr = tblOrders[0]; tblOrders.RemoveOrdersRow(drr); Assert.AreEqual(i-1 ,tblOrders.Count,"TDS17"); //first column is readonly Assert.IsTrue(tblOrders.OrderIDColumn.ReadOnly ,"TDS18"); //read only exception try { tblOrders[0].OrderID = 99; Assert.Fail("TDS19: Failed to throw ReadOnlyException"); } catch (ReadOnlyException) {} catch (AssertionException exc) {throw exc;} catch (Exception exc) { Assert.Fail("TDS20: Wrong exception type. Got:" + exc); } tblOrders.AcceptChanges(); //Check table events // add event handlers ds.Orders.OrdersRowChanging += new myTypedDataSet.OrdersRowChangeEventHandler(T_Changing); ds.Orders.OrdersRowChanged += new myTypedDataSet.OrdersRowChangeEventHandler(T_Changed); ds.Orders.OrdersRowDeleting += new myTypedDataSet.OrdersRowChangeEventHandler(T_Deleting); ds.Orders.OrdersRowDeleted += new myTypedDataSet.OrdersRowChangeEventHandler(T_Deleted); //RowChange event order tblOrders[0].ShipCity = "Tel Aviv"; Assert.AreEqual("AB",EventStatus , "TDS21"); EventStatus = string.Empty; //RowDelet event order tblOrders[0].Delete(); Assert.AreEqual("AB",EventStatus , "TDS22"); //expose DataColumn as property Assert.AreEqual(ds.Orders.OrderIDColumn ,ds.Tables["Orders"].Columns["OrderID"],"TDS23"); //Accept changes for all deleted and changedd rows. ds.AcceptChanges(); //check relations //ChildTableRow has property ParentTableRow myTypedDataSet.OrdersRow dr1 = ds.Order_Details[0].OrdersRow; DataRow dr2 = ds.Order_Details[0].GetParentRow(ds.Relations[0]); Assert.AreEqual(dr1 ,dr2 ,"TDS24"); //ParentTableRow has property ChildTableRow myTypedDataSet.Order_DetailsRow[] drArr1 = ds.Orders[0].GetOrder_DetailsRows(); DataRow[] drArr2 = ds.Orders[0].GetChildRows(ds.Relations[0]); Assert.AreEqual(drArr1 ,drArr2,"TDS25"); //now test serialization of a typed dataset generated by microsoft's xsd.exe DataSet1 ds1 = new DataSet1(); ds1.DataTable1.AddDataTable1Row("test"); ds1.DataTable1.AddDataTable1Row("test2"); global::System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new global::System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); MemoryStream stream = new MemoryStream(); formatter.Serialize(stream, ds1); stream.Seek(0, SeekOrigin.Begin); DataSet1 ds1load = (DataSet1) formatter.Deserialize(stream); Assert.IsTrue(ds1load.Tables.Contains("DataTable1")); Assert.AreEqual("DataTable1DataTable", ds1load.Tables["DataTable1"].GetType().Name); Assert.AreEqual(2, ds1load.DataTable1.Rows.Count); Assert.AreEqual("DataTable1Row", ds1load.DataTable1[0].GetType().Name); if (ds1load.DataTable1[0].Column1 == "test") { Assert.AreEqual("test2", ds1load.DataTable1[1].Column1); } else if (ds1load.DataTable1[0].Column1 == "test2") { Assert.AreEqual("test", ds1load.DataTable1[1].Column1); } else { Assert.Fail("Invalid entry for Column1"); } //now test when the mode is exclude schema ds1.SchemaSerializationMode = global::System.Data.SchemaSerializationMode.ExcludeSchema; stream = new MemoryStream(); formatter.Serialize(stream, ds1); stream.Seek(0, SeekOrigin.Begin); ds1load = (DataSet1) formatter.Deserialize(stream); Assert.IsTrue(ds1load.Tables.Contains("DataTable1")); Assert.AreEqual("DataTable1DataTable", ds1load.Tables["DataTable1"].GetType().Name); Assert.AreEqual(2, ds1load.DataTable1.Rows.Count); Assert.AreEqual("DataTable1Row", ds1load.DataTable1[0].GetType().Name); if (ds1load.DataTable1[0].Column1 == "test") { Assert.AreEqual("test2", ds1load.DataTable1[1].Column1); } else if (ds1load.DataTable1[0].Column1 == "test2") { Assert.AreEqual("test", ds1load.DataTable1[1].Column1); } else { Assert.Fail("Invalid entry for Column1"); } }
public void TypedDataSet() { int i = 0; //check dataset constructor myTypedDataSet ds = null; DataSet unTypedDs = new DataSet(); ds = new myTypedDataSet(); Assert.False(ds == null); Assert.Equal(typeof(myTypedDataSet), ds.GetType()); // fill dataset ds.ReadXml(new StringReader( @"<?xml version=""1.0"" standalone=""yes""?> <myTypedDataSet xmlns=""http://www.tempuri.org/myTypedDataSet.xsd""> <Order_x0020_Details> <OrderID>10250</OrderID> <ProductID>41</ProductID> <UnitPrice>7.7000</UnitPrice> <Quantity>10</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10250</OrderID> <ProductID>51</ProductID> <UnitPrice>42.4000</UnitPrice> <Quantity>35</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10250</OrderID> <ProductID>65</ProductID> <UnitPrice>16.8000</UnitPrice> <Quantity>15</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10251</OrderID> <ProductID>22</ProductID> <UnitPrice>16.8000</UnitPrice> <Quantity>6</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10251</OrderID> <ProductID>57</ProductID> <UnitPrice>15.6000</UnitPrice> <Quantity>15</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10251</OrderID> <ProductID>65</ProductID> <UnitPrice>16.8000</UnitPrice> <Quantity>20</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10252</OrderID> <ProductID>20</ProductID> <UnitPrice>64.8000</UnitPrice> <Quantity>40</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10252</OrderID> <ProductID>33</ProductID> <UnitPrice>2.0000</UnitPrice> <Quantity>25</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10252</OrderID> <ProductID>60</ProductID> <UnitPrice>27.2000</UnitPrice> <Quantity>40</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10253</OrderID> <ProductID>31</ProductID> <UnitPrice>10.0000</UnitPrice> <Quantity>20</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10253</OrderID> <ProductID>39</ProductID> <UnitPrice>14.4000</UnitPrice> <Quantity>42</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10253</OrderID> <ProductID>49</ProductID> <UnitPrice>16.0000</UnitPrice> <Quantity>40</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10254</OrderID> <ProductID>24</ProductID> <UnitPrice>3.6000</UnitPrice> <Quantity>15</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10254</OrderID> <ProductID>55</ProductID> <UnitPrice>19.2000</UnitPrice> <Quantity>21</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10254</OrderID> <ProductID>74</ProductID> <UnitPrice>8.0000</UnitPrice> <Quantity>21</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10255</OrderID> <ProductID>2</ProductID> <UnitPrice>15.2000</UnitPrice> <Quantity>20</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10255</OrderID> <ProductID>16</ProductID> <UnitPrice>13.9000</UnitPrice> <Quantity>35</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10255</OrderID> <ProductID>36</ProductID> <UnitPrice>15.2000</UnitPrice> <Quantity>25</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10255</OrderID> <ProductID>59</ProductID> <UnitPrice>44.0000</UnitPrice> <Quantity>30</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10256</OrderID> <ProductID>53</ProductID> <UnitPrice>26.2000</UnitPrice> <Quantity>15</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10256</OrderID> <ProductID>77</ProductID> <UnitPrice>10.4000</UnitPrice> <Quantity>12</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10257</OrderID> <ProductID>27</ProductID> <UnitPrice>35.1000</UnitPrice> <Quantity>25</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10257</OrderID> <ProductID>39</ProductID> <UnitPrice>14.4000</UnitPrice> <Quantity>6</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10257</OrderID> <ProductID>77</ProductID> <UnitPrice>10.4000</UnitPrice> <Quantity>15</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10258</OrderID> <ProductID>2</ProductID> <UnitPrice>15.2000</UnitPrice> <Quantity>50</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10258</OrderID> <ProductID>5</ProductID> <UnitPrice>17.0000</UnitPrice> <Quantity>65</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10258</OrderID> <ProductID>32</ProductID> <UnitPrice>25.6000</UnitPrice> <Quantity>6</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10259</OrderID> <ProductID>21</ProductID> <UnitPrice>8.0000</UnitPrice> <Quantity>10</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10259</OrderID> <ProductID>37</ProductID> <UnitPrice>20.8000</UnitPrice> <Quantity>1</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10260</OrderID> <ProductID>41</ProductID> <UnitPrice>7.7000</UnitPrice> <Quantity>16</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10260</OrderID> <ProductID>57</ProductID> <UnitPrice>15.6000</UnitPrice> <Quantity>50</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10260</OrderID> <ProductID>62</ProductID> <UnitPrice>39.4000</UnitPrice> <Quantity>15</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10260</OrderID> <ProductID>70</ProductID> <UnitPrice>12.0000</UnitPrice> <Quantity>21</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10261</OrderID> <ProductID>21</ProductID> <UnitPrice>8.0000</UnitPrice> <Quantity>20</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10261</OrderID> <ProductID>35</ProductID> <UnitPrice>14.4000</UnitPrice> <Quantity>20</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10262</OrderID> <ProductID>5</ProductID> <UnitPrice>17.0000</UnitPrice> <Quantity>12</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10262</OrderID> <ProductID>7</ProductID> <UnitPrice>24.0000</UnitPrice> <Quantity>15</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10262</OrderID> <ProductID>56</ProductID> <UnitPrice>30.4000</UnitPrice> <Quantity>2</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10263</OrderID> <ProductID>16</ProductID> <UnitPrice>13.9000</UnitPrice> <Quantity>60</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10263</OrderID> <ProductID>24</ProductID> <UnitPrice>3.6000</UnitPrice> <Quantity>28</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10263</OrderID> <ProductID>30</ProductID> <UnitPrice>20.7000</UnitPrice> <Quantity>60</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10263</OrderID> <ProductID>74</ProductID> <UnitPrice>8.0000</UnitPrice> <Quantity>36</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10264</OrderID> <ProductID>2</ProductID> <UnitPrice>15.2000</UnitPrice> <Quantity>35</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10264</OrderID> <ProductID>41</ProductID> <UnitPrice>7.7000</UnitPrice> <Quantity>25</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10265</OrderID> <ProductID>17</ProductID> <UnitPrice>31.2000</UnitPrice> <Quantity>30</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10265</OrderID> <ProductID>70</ProductID> <UnitPrice>12.0000</UnitPrice> <Quantity>20</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10266</OrderID> <ProductID>12</ProductID> <UnitPrice>30.4000</UnitPrice> <Quantity>12</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10267</OrderID> <ProductID>40</ProductID> <UnitPrice>14.7000</UnitPrice> <Quantity>50</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10267</OrderID> <ProductID>59</ProductID> <UnitPrice>44.0000</UnitPrice> <Quantity>70</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10267</OrderID> <ProductID>76</ProductID> <UnitPrice>14.4000</UnitPrice> <Quantity>15</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10268</OrderID> <ProductID>29</ProductID> <UnitPrice>99.0000</UnitPrice> <Quantity>10</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10268</OrderID> <ProductID>72</ProductID> <UnitPrice>27.8000</UnitPrice> <Quantity>4</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10269</OrderID> <ProductID>33</ProductID> <UnitPrice>2.0000</UnitPrice> <Quantity>60</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10269</OrderID> <ProductID>72</ProductID> <UnitPrice>27.8000</UnitPrice> <Quantity>20</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10270</OrderID> <ProductID>36</ProductID> <UnitPrice>15.2000</UnitPrice> <Quantity>30</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Order_x0020_Details> <OrderID>10270</OrderID> <ProductID>43</ProductID> <UnitPrice>36.8000</UnitPrice> <Quantity>25</Quantity> <Discount>5.0</Discount> </Order_x0020_Details> <Orders> <OrderID>10250</OrderID> <CustomerID>HANAR</CustomerID> <EmployeeID>4</EmployeeID> <OrderDate>1996-07-08T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-05T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-12T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10251</OrderID> <CustomerID>VICTE</CustomerID> <EmployeeID>3</EmployeeID> <OrderDate>1996-07-08T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-05T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-15T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10252</OrderID> <CustomerID>SUPRD</CustomerID> <EmployeeID>4</EmployeeID> <OrderDate>1996-07-09T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-06T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-11T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10253</OrderID> <CustomerID>HANAR</CustomerID> <EmployeeID>3</EmployeeID> <OrderDate>1996-07-10T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-07-24T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-16T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10254</OrderID> <CustomerID>CHOPS</CustomerID> <EmployeeID>5</EmployeeID> <OrderDate>1996-07-11T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-08T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-23T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10255</OrderID> <CustomerID>RICSU</CustomerID> <EmployeeID>9</EmployeeID> <OrderDate>1996-07-12T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-09T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-15T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10256</OrderID> <CustomerID>WELLI</CustomerID> <EmployeeID>3</EmployeeID> <OrderDate>1996-07-15T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-12T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-17T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10257</OrderID> <CustomerID>HILAA</CustomerID> <EmployeeID>4</EmployeeID> <OrderDate>1996-07-16T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-13T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-22T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10258</OrderID> <CustomerID>ERNSH</CustomerID> <EmployeeID>1</EmployeeID> <OrderDate>1996-07-17T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-14T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-23T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10259</OrderID> <CustomerID>CENTC</CustomerID> <EmployeeID>4</EmployeeID> <OrderDate>1996-07-18T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-15T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-25T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10260</OrderID> <CustomerID>OTTIK</CustomerID> <EmployeeID>4</EmployeeID> <OrderDate>1996-07-19T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-16T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-29T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10261</OrderID> <CustomerID>QUEDE</CustomerID> <EmployeeID>4</EmployeeID> <OrderDate>1996-07-19T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-16T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-30T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10262</OrderID> <CustomerID>RATTC</CustomerID> <EmployeeID>8</EmployeeID> <OrderDate>1996-07-22T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-19T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-25T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10263</OrderID> <CustomerID>ERNSH</CustomerID> <EmployeeID>9</EmployeeID> <OrderDate>1996-07-23T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-20T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-31T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10264</OrderID> <CustomerID>FOLKO</CustomerID> <EmployeeID>6</EmployeeID> <OrderDate>1996-07-24T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-21T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-08-23T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10265</OrderID> <CustomerID>BLONP</CustomerID> <EmployeeID>2</EmployeeID> <OrderDate>1996-07-25T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-22T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-08-12T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10266</OrderID> <CustomerID>WARTH</CustomerID> <EmployeeID>3</EmployeeID> <OrderDate>1996-07-26T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-09-06T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-07-31T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10267</OrderID> <CustomerID>FRANK</CustomerID> <EmployeeID>4</EmployeeID> <OrderDate>1996-07-29T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-26T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-08-06T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10268</OrderID> <CustomerID>GROSR</CustomerID> <EmployeeID>8</EmployeeID> <OrderDate>1996-07-30T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-27T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-08-02T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10269</OrderID> <CustomerID>WHITC</CustomerID> <EmployeeID>5</EmployeeID> <OrderDate>1996-07-31T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-14T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-08-09T00:00:00.0000000+03:00</ShippedDate> </Orders> <Orders> <OrderID>10270</OrderID> <CustomerID>WARTH</CustomerID> <EmployeeID>1</EmployeeID> <OrderDate>1996-08-01T00:00:00.0000000+03:00</OrderDate> <RequiredDate>1996-08-29T00:00:00.0000000+03:00</RequiredDate> <ShippedDate>1996-08-02T00:00:00.0000000+03:00</ShippedDate> </Orders> </myTypedDataSet>")); // check DataSet named property "Orders" myTypedDataSet.OrdersDataTable tblOrders = null; tblOrders = ds.Orders; Assert.Equal(ds.Tables["Orders"], tblOrders); //check DataSet named property Orders - by index"); tblOrders = ds.Orders; Assert.Equal(ds.Tables[1], tblOrders); //add new row AddTableNameRow, check row count"); i = tblOrders.Rows.Count; tblOrders.AddOrdersRow("SAVEA", 1, new DateTime(1998, 05, 01, 00, 00, 00, 000) , new DateTime(1998, 05, 29, 00, 00, 00, 000) , new DateTime(1998, 05, 04, 00, 00, 00, 000), 1, 30.0900m , "Save-a-lot Markets", "187 Suffolk Ln.", "Boise", "ID", "83720", "USA"); Assert.Equal(i + 1, tblOrders.Rows.Count); //check the new row AutoIncrement field - AddTableNameRow i = (int)tblOrders.Rows[tblOrders.Rows.Count - 2][0]; Assert.Equal(i + 1, (int)tblOrders.Rows[tblOrders.Rows.Count - 1][0]); //Create New Row using NewTableNameRow, check row != null myTypedDataSet.OrdersRow drOrders = null; drOrders = tblOrders.NewOrdersRow(); Assert.False(drOrders == null); //Create New Row using NewTableNameRow, check row state Assert.Equal(DataRowState.Detached, drOrders.RowState); //add new row NewTableNameRow, check row count //drOrders.OrderID = DBNull.Value; drOrders.CustomerID = "GREAL"; drOrders.EmployeeID = 4; drOrders.OrderDate = new DateTime(1998, 04, 30, 00, 00, 00, 000); drOrders.RequiredDate = new DateTime(1998, 06, 11, 00, 00, 00, 000); drOrders["ShippedDate"] = DBNull.Value; drOrders.ShipVia = 3; drOrders.Freight = 14.0100m; drOrders.ShipName = "Great Lakes"; drOrders.ShipAddress = "Food Market"; drOrders.ShipCity = "Baker Blvd."; drOrders.ShipRegion = "Eugene"; drOrders.ShipPostalCode = "OR 97403"; drOrders.ShipCountry = "USA"; i = tblOrders.Rows.Count; tblOrders.AddOrdersRow(drOrders); Assert.Equal(i + 1, tblOrders.Rows.Count); //check StrongTypingException Assert.Throws<StrongTypingException>(() => { DateTime d = drOrders.ShippedDate; //drOrders.ShippedDate = null, will raise exception }); //check the new row AutoIncrement field - NewTableNameRow i = (int)tblOrders.Rows[tblOrders.Rows.Count - 2][0]; Assert.Equal(i + 1, (int)tblOrders.Rows[tblOrders.Rows.Count - 1][0]); // convenience IsNull functions // only if it can be null Assert.False(drOrders.IsShipAddressNull()); drOrders.SetShipAddressNull(); Assert.True(drOrders.IsShipAddressNull()); // Table exposes a public property Count == table.Rows.Count Assert.Equal(tblOrders.Count, tblOrders.Rows.Count); // find function myTypedDataSet.OrdersRow dr = tblOrders[0]; Assert.Equal(tblOrders.FindByOrderID(dr.OrderID), dr); //Remove row and check row count i = tblOrders.Count; myTypedDataSet.OrdersRow drr = tblOrders[0]; tblOrders.RemoveOrdersRow(drr); Assert.Equal(i - 1, tblOrders.Count); //first column is readonly Assert.True(tblOrders.OrderIDColumn.ReadOnly); //read only exception Assert.Throws<ReadOnlyException>(() => { tblOrders[0].OrderID = 99; }); tblOrders.AcceptChanges(); //Check table events // add event handlers ds.Orders.OrdersRowChanging += new myTypedDataSet.OrdersRowChangeEventHandler(T_Changing); ds.Orders.OrdersRowChanged += new myTypedDataSet.OrdersRowChangeEventHandler(T_Changed); ds.Orders.OrdersRowDeleting += new myTypedDataSet.OrdersRowChangeEventHandler(T_Deleting); ds.Orders.OrdersRowDeleted += new myTypedDataSet.OrdersRowChangeEventHandler(T_Deleted); //RowChange event order tblOrders[0].ShipCity = "Tel Aviv"; Assert.Equal("AB", _eventStatus); _eventStatus = string.Empty; //RowDelet event order tblOrders[0].Delete(); Assert.Equal("AB", _eventStatus); //expose DataColumn as property Assert.Equal(ds.Orders.OrderIDColumn, ds.Tables["Orders"].Columns["OrderID"]); //Accept changes for all deleted and changedd rows. ds.AcceptChanges(); //check relations //ChildTableRow has property ParentTableRow myTypedDataSet.OrdersRow dr1 = ds.Order_Details[0].OrdersRow; DataRow dr2 = ds.Order_Details[0].GetParentRow(ds.Relations[0]); Assert.Equal(dr1, dr2); //ParentTableRow has property ChildTableRow myTypedDataSet.Order_DetailsRow[] drArr1 = ds.Orders[0].GetOrder_DetailsRows(); DataRow[] drArr2 = ds.Orders[0].GetChildRows(ds.Relations[0]); Assert.Equal(drArr1, drArr2); //now test serialization of a typed dataset generated by microsoft's xsd.exe DataSet1 ds1 = new DataSet1(); ds1.DataTable1.AddDataTable1Row("test"); ds1.DataTable1.AddDataTable1Row("test2"); global::System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter = new global::System.Runtime.Serialization.Formatters.Binary.BinaryFormatter(); MemoryStream stream = new MemoryStream(); formatter.Serialize(stream, ds1); stream.Seek(0, SeekOrigin.Begin); DataSet1 ds1load = (DataSet1)formatter.Deserialize(stream); Assert.True(ds1load.Tables.Contains("DataTable1")); Assert.Equal("DataTable1DataTable", ds1load.Tables["DataTable1"].GetType().Name); Assert.Equal(2, ds1load.DataTable1.Rows.Count); Assert.Equal("DataTable1Row", ds1load.DataTable1[0].GetType().Name); if (ds1load.DataTable1[0].Column1 == "test") { Assert.Equal("test2", ds1load.DataTable1[1].Column1); } else if (ds1load.DataTable1[0].Column1 == "test2") { Assert.Equal("test", ds1load.DataTable1[1].Column1); } else { Assert.False(true); } //now test when the mode is exclude schema ds1.SchemaSerializationMode = global::System.Data.SchemaSerializationMode.ExcludeSchema; stream = new MemoryStream(); formatter.Serialize(stream, ds1); stream.Seek(0, SeekOrigin.Begin); ds1load = (DataSet1)formatter.Deserialize(stream); Assert.True(ds1load.Tables.Contains("DataTable1")); Assert.Equal("DataTable1DataTable", ds1load.Tables["DataTable1"].GetType().Name); Assert.Equal(2, ds1load.DataTable1.Rows.Count); Assert.Equal("DataTable1Row", ds1load.DataTable1[0].GetType().Name); if (ds1load.DataTable1[0].Column1 == "test") { Assert.Equal("test2", ds1load.DataTable1[1].Column1); } else if (ds1load.DataTable1[0].Column1 == "test2") { Assert.Equal("test", ds1load.DataTable1[1].Column1); } else { Assert.False(true); } }