//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2011 Xamarin Inc. (http://www.xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
using System;
using System.Collections;
+using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Globalization;
[TestFixture]
public class DataTableTest : DataSetAssertion
{
- string EOL = Environment.NewLine;
+ string EOL = "\r\n";
[Test]
public void Ctor()
Assert.AreEqual ("Error#1", (table.GetErrors ())[0].RowError, "#A02");
}
-#if NET_2_0
[Test]
public void NewRowAddedTest ()
{
Assert.IsTrue (_tableNewRowAddedEventFired, "#NewRowAdded Event #01");
}
-#endif
[Test]
public void CloneCopyTest ()
DataColumn[] colArray = {table.Columns[0]};
table.PrimaryKey = colArray;
table.ExtendedProperties.Add ("TimeStamp", DateTime.Now);
-#if NET_1_1 // This prevents further tests after .NET 1.1.
-#else
- CultureInfo cultureInfo = new CultureInfo ("en-gb");
- table.Locale = cultureInfo;
-#endif
row = table1.NewRow ();
row ["Name"] = "Abc";
Assert.AreEqual ("Id / Name + (Id * Id)", cloneTable.DisplayExpression, "#A06");
Assert.AreEqual (1, cloneTable.ExtendedProperties.Count, "#A07");
Assert.IsFalse (cloneTable.HasErrors, "#A08");
-#if NET_1_1
-#else
- Assert.AreEqual (2057, cloneTable.Locale.LCID, "#A09");
-#endif
Assert.AreEqual (100, cloneTable.MinimumCapacity, "#A10");
Assert.AreEqual ("Namespace#1", cloneTable.Namespace, "#A11");
Assert.AreEqual ("PrefixNo:1", cloneTable.Prefix, "#A12");
Assert.AreEqual ("Id / Name + (Id * Id)", copyTable.DisplayExpression, "#A21");
Assert.AreEqual (1, copyTable.ExtendedProperties.Count, "#A22");
Assert.IsTrue (copyTable.HasErrors, "#A23");
-#if NET_1_1
-#else
- Assert.AreEqual (2057, copyTable.Locale.LCID, "#A24");
-#endif
Assert.AreEqual (100, copyTable.MinimumCapacity, "#A25");
Assert.AreEqual ("Namespace#1", copyTable.Namespace, "#A26");
Assert.AreEqual ("PrefixNo:1", copyTable.Prefix, "#A27");
Assert.AreEqual ("Table#1", copyTable.TableName, "#A30");
}
+ [Test]
+ public void CloneExtendedProperties ()
+ {
+ // bug 668
+ DataTable t1 = new DataTable ("t1");
+ DataColumn c1 = t1.Columns.Add ("c1");
+ c1.ExtendedProperties.Add ("Company", "Xamarin");
+
+ DataTable t2 = t1.Clone ();
+ Assert.AreEqual ("Xamarin", t1.Columns["c1"].ExtendedProperties["Company"], "CEP1");
+ Assert.AreEqual ("Xamarin", t2.Columns["c1"].ExtendedProperties["Company"], "CEP2");
+ }
+
+ [Test]
+ [ExpectedException (typeof (EvaluateException))]
+ public void CloneExtendedProperties1 ()
+ {
+ // Xamarin bug 666
+ DataTable table1 = new DataTable("Table1") ;
+
+ DataColumn c1 = table1.Columns.Add("c1", typeof(string), "'hello ' + c2") ; /* Should cause an exception */
+ }
+
+ [Test]
+ public void CloneExtendedProperties2 ()
+ {
+ // Xamarin bug 666
+ DataTable table1 = new DataTable("Table1") ;
+
+ DataColumn c1 = table1.Columns.Add("c1") ;
+ DataColumn c2 = table1.Columns.Add("c2") ;
+
+ c1.Expression = "'hello ' + c2";
+
+ DataTable t2 = table1.Clone(); // this should not cause an exception
+ }
+
[Test]
public void LoadDataException ()
{
Assert.IsTrue (ex.Message.IndexOf ("'1'") != -1, "#B6");
}
}
-
+
+#if NET_4_0
+ [Test]
+ public void ImportRowTypeChangeTest ()
+ {
+ // this is from http://bugzilla.xamarin.com/show_bug.cgi?id=2926
+
+ Type [] types = new Type [] { typeof (string), typeof (sbyte), typeof (byte), typeof (short), typeof (ushort), typeof (int), typeof (uint), typeof (long), typeof (ulong), typeof (float), typeof (double), typeof (char), typeof (decimal), typeof (DateTime) };
+ object [] values = new object [] { "1", (sbyte) 1, (byte) 2, (short) 3, (ushort) 4, (int) 5, (uint) 6, (long) 7, (ulong) 8, (float) 9, (double) 10, 'z', (decimal) 13, new DateTime (24) };
+ int length = types.Length;
+
+ HashSet<Tuple<Type, Type>> invalid = new HashSet<Tuple<Type, Type>> () {
+ Tuple.Create (typeof (string), typeof (DateTime)),
+ Tuple.Create (typeof (sbyte), typeof (DateTime)),
+ Tuple.Create (typeof (byte), typeof (DateTime)),
+ Tuple.Create (typeof (short), typeof (DateTime)),
+ Tuple.Create (typeof (ushort), typeof (DateTime)),
+ Tuple.Create (typeof (int), typeof (DateTime)),
+ Tuple.Create (typeof (uint), typeof (DateTime)),
+ Tuple.Create (typeof (long), typeof (DateTime)),
+ Tuple.Create (typeof (ulong), typeof (DateTime)),
+ Tuple.Create (typeof (float), typeof (char)),
+ Tuple.Create (typeof (float), typeof (DateTime)),
+ Tuple.Create (typeof (double), typeof (char)),
+ Tuple.Create (typeof (double), typeof (DateTime)),
+ Tuple.Create (typeof (char), typeof (float)),
+ Tuple.Create (typeof (char), typeof (double)),
+ Tuple.Create (typeof (char), typeof (decimal)),
+ Tuple.Create (typeof (char), typeof (DateTime)),
+ Tuple.Create (typeof (Decimal), typeof (char)),
+ Tuple.Create (typeof (Decimal), typeof (DateTime)),
+ Tuple.Create (typeof (DateTime), typeof (sbyte)),
+ Tuple.Create (typeof (DateTime), typeof (byte)),
+ Tuple.Create (typeof (DateTime), typeof (short)),
+ Tuple.Create (typeof (DateTime), typeof (ushort)),
+ Tuple.Create (typeof (DateTime), typeof (int)),
+ Tuple.Create (typeof (DateTime), typeof (uint)),
+ Tuple.Create (typeof (DateTime), typeof (long)),
+ Tuple.Create (typeof (DateTime), typeof (ulong)),
+ Tuple.Create (typeof (DateTime), typeof (float)),
+ Tuple.Create (typeof (DateTime), typeof (double)),
+ Tuple.Create (typeof (DateTime), typeof (char)),
+ Tuple.Create (typeof (DateTime), typeof (decimal)),
+ };
+
+ for (int a = 0; a < length; a++) {
+ for (int b = 0; b < length; b++) {
+ DataSet ds = new DataSet ();
+ DataTable dt1 = ds.Tables.Add ("T1");
+ DataTable dt2 = ds.Tables.Add ("T2");
+
+ string name = "C-" + types [a].Name + "-to-" + types [b].Name;
+ dt1.Columns.Add (name, types [a]);
+ dt2.Columns.Add (name, types [b]);
+
+ DataRow r1 = dt1.NewRow ();
+ dt1.Rows.Add (r1);
+
+ r1 [0] = values [a];
+
+ if (invalid.Contains (Tuple.Create (types [a], types [b]))) {
+ try {
+ dt2.ImportRow (r1);
+ Assert.Fail ("#B: " + name + " expected ArgumentException");
+ } catch /*(ArgumentException)*/ {
+ continue;
+ }
+ } else {
+ dt2.ImportRow (r1);
+ DataRow r2 = dt2.Rows [0];
+ Assert.AreEqual (types [b], r2 [0].GetType (), "#A: " + name);
+ }
+ }
+ }
+ }
+#endif
+
[Test]
public void ClearReset () //To test Clear and Reset methods
{
// clear test
table.Clear ();
Assert.AreEqual (0, table.Rows.Count, "#A08");
-#if NET_1_1
Assert.AreEqual (0, table.Constraints.Count, "#A09");
-#else
- Assert.AreEqual (1, table.Constraints.Count, "#A09");
-#endif
Assert.AreEqual (0, table.ChildRelations.Count, "#A10");
}
table.Rows.Add (new object [] { 4, "mono 4" });
table.AcceptChanges ();
-#if NET_2_0
_tableClearedEventFired = false;
table.TableCleared += new DataTableClearEventHandler (OnTableCleared);
_tableClearingEventFired = false;
table.TableClearing += new DataTableClearEventHandler (OnTableClearing);
-#endif // NET_2_0
table.Clear ();
-#if NET_2_0
Assert.IsTrue (_tableClearingEventFired, "#3 should have fired cleared event");
Assert.IsTrue (_tableClearedEventFired, "#0 should have fired cleared event");
-#endif // NET_2_0
DataRow r = table.Rows.Find (1);
Assert.IsTrue (r == null, "#1 should have cleared");
Assert.AreEqual (1, table.Rows.Count, "#2 should add row");
}
-#if NET_2_0
private bool _tableClearedEventFired;
private void OnTableCleared (object src, DataTableClearEventArgs args)
{
{
_tableNewRowAddedEventFired = true;
}
-#endif // NET_2_0
-#if NET_2_0
[Test]
public void TestWriteXmlSchema1 ()
{
Assert.AreEqual (" </xs:element>", substring, "test#32");
Assert.AreEqual ("</xs:schema>", TextString, "test#33");
}
-#endif
[Test]
public void Serialize ()
Assert.AreEqual (1, dt.Rows.Count);
}
-#if NET_2_0
private bool tableInitialized;
[Test]
public void TableInitializedEventTest1 ()
{
tableInitialized = true;
}
-#endif
public void OnRowChanging (object src, DataRowChangeEventArgs args)
{
rowActionChanged = args.Action;
}
-#if NET_2_0
private DataTable dt;
private void localSetup () {
dt = new DataTable ("test");
#region Read/Write XML Tests
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void ReadXmlSchema ()
{
DataTable Table = new DataTable ();
[Test]
public void ReadWriteXmlSchema_ByFileName ()
{
- string sTempFileName1 = "tmpDataSet_ReadWriteXml_43899-1.xml";
- string sTempFileName2 = "tmpDataSet_ReadWriteXml_43899-2.xml";
+ string sTempFileName1 = Path.Combine (Path.GetTempPath (), "tmpDataSet_ReadWriteXml_43899-1.xml");
+ string sTempFileName2 = Path.Combine (Path.GetTempPath (), "tmpDataSet_ReadWriteXml_43899-2.xml");
DataSet ds1 = new DataSet ();
ds1.Tables.Add (DataProvider.CreateParentDataTable ());
string TextString = GetNormalizedSchema (writer.ToString ());
//string TextString = writer.ToString ();
+ EOL = "\n";
string substring = TextString.Substring (0, TextString.IndexOf (EOL));
TextString = TextString.Substring (TextString.IndexOf (EOL) + EOL.Length);
Assert.AreEqual ("<?xml version=\"1.0\" encoding=\"utf-16\"?>", substring, "test#01");
}
[Test]
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void WriteXmlSchema_Hierarchy ()
{
DataSet ds = new DataSet ();
[Test]
[Ignore ("MS behavior is far from consistent to be regarded as a reference implementation.")]
// See the same-named tests in DataSetTest.cs
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
// WriteXmlSchema doesn't have overload wityh 2 parameters in System.Data
// and is commented-out TWICE below
public void ReadWriteXmlSchema()
[Test]
[Ignore ("MS behavior is far from consistent to be regarded as a reference implementation.")]
// See the same-named tests in DataSetTest.cs
-#if TARGET_JVM
- [Category ("NotWorking")]
-#endif
public void ReadWriteXmlSchema_IgnoreSchema ()
{
DataSet ds = new DataSet ();
#endregion // Read/Write XML Tests
-#endif // NET_2_0
}
public class MyDataTable : DataTable
Assert.AreEqual (5, n, "n");
}
-#if !TARGET_JVM
+#if !MONOTOUCH
[Test]
public void NFIFromBug55978 ()
{