-//\r
-// SqlDecimalTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlDecimal\r
-//\r
-// Authors:\r
-// Ville Palo (vi64pa@koti.soon.fi)\r
-// Martin Willemoes Hansen\r
-//\r
-// (C) 2002 Ville Palo\r
-// (C) 2003 Martin Willemoes Hansen\r
-// \r
+//
+// SqlDecimalTest.cs - NUnit Test Cases for System.Data.SqlTypes.SqlDecimal
+//
+// Authors:
+// Ville Palo (vi64pa@koti.soon.fi)
+// Martin Willemoes Hansen
+//
+// (C) 2002 Ville Palo
+// (C) 2003 Martin Willemoes Hansen
+//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-\r
-using NUnit.Framework;\r
-using System;\r
-using System.Data.SqlTypes;\r
-using System.Threading;\r
-using System.Globalization;\r
-\r
-namespace MonoTests.System.Data.SqlTypes\r
-{\r
- [TestFixture]\r
- public class SqlDecimalTest : Assertion {\r
-\r
- private SqlDecimal Test1;\r
- private SqlDecimal Test2;\r
- private SqlDecimal Test3;\r
- private SqlDecimal Test4;\r
- \r
- [SetUp]\r
- public void GetReady() \r
- {\r
- Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");\r
- Test1 = new SqlDecimal (6464.6464m);\r
- Test2 = new SqlDecimal (10000.00m); \r
- Test3 = new SqlDecimal (10000.00m); \r
- Test4 = new SqlDecimal (-6m); \r
- }\r
-\r
- // Test constructor\r
- [Test]\r
- public void Create()\r
- {\r
- // SqlDecimal (decimal)\r
- SqlDecimal Test = new SqlDecimal (30.3098m);\r
- AssertEquals ("#A01", (decimal)30.3098, Test.Value);\r
- \r
- try {\r
- decimal d = Decimal.MaxValue;\r
- SqlDecimal test = new SqlDecimal (d + 1);\r
- Fail ("#A02"); \r
- } catch (Exception e) {\r
- AssertEquals ("#A03", typeof (OverflowException), e.GetType ());\r
- }\r
- \r
- // SqlDecimal (double)\r
- Test = new SqlDecimal (10E+10d);\r
- AssertEquals ("#A05", 100000000000.00000m, Test.Value);\r
- \r
- try {\r
- SqlDecimal test = new SqlDecimal (10E+200d);\r
- Fail ("#A06"); \r
- } catch (Exception e) {\r
- AssertEquals ("#A07", typeof (OverflowException), e.GetType ());\r
- }\r
- \r
- // SqlDecimal (int)\r
- Test = new SqlDecimal (-1);\r
- AssertEquals ("#A08", -1m, Test.Value);\r
- \r
- // SqlDecimal (long)\r
- Test = new SqlDecimal ((long)(-99999));\r
- AssertEquals ("#A09", -99999m, Test.Value);\r
- \r
- // SqlDecimal (byte, byte, bool. int[]\r
- Test = new SqlDecimal (10, 3, false, new int [4] {200, 1, 0, 0});\r
- AssertEquals ("#A10", -4294967.496m, Test.Value);\r
- \r
- try { \r
- Test = new SqlDecimal (100, 100, false, \r
- new int [4] {Int32.MaxValue, \r
- Int32.MaxValue, Int32.MaxValue, \r
- Int32.MaxValue});\r
- Fail ("#A11");\r
- } catch (SqlTypeException) {\r
- }\r
-\r
- // sqlDecimal (byte, byte, bool, int, int, int, int)\r
- Test = new SqlDecimal (12, 2, true, 100, 100, 0, 0);\r
- AssertEquals ("#A13", 4294967297.00m, Test.Value);\r
- \r
- try { \r
- Test = new SqlDecimal (100, 100, false, \r
- Int32.MaxValue, \r
- Int32.MaxValue, Int32.MaxValue, \r
- Int32.MaxValue);\r
- Fail ("#A14");\r
- } catch (SqlTypeException) {\r
- } \r
- }\r
-\r
- // Test public fields\r
- [Test]\r
- public void PublicFields()\r
- {\r
- AssertEquals ("#B01", (byte)38, SqlDecimal.MaxPrecision);\r
- AssertEquals ("#B02", (byte)38, SqlDecimal.MaxScale);\r
- \r
- // FIXME: on windows: Conversion overflow\r
- AssertEquals ("#B03a", 1262177448, SqlDecimal.MaxValue.Data [3]);\r
-\r
-\r
- AssertEquals ("#B04", 1262177448, SqlDecimal.MinValue.Data [3]);\r
- Assert ("#B05", SqlDecimal.Null.IsNull);\r
- Assert ("#B06", !Test1.IsNull);\r
- }\r
-\r
- // Test properties\r
- [Test]\r
- public void Properties()\r
- {\r
- byte[] b = Test1.BinData;\r
- AssertEquals ("#C01", (byte)64, b [0]);\r
- \r
- int[] i = Test1.Data;\r
- AssertEquals ("#C02", 64646464, i [0]);\r
- \r
- Assert ("#C03", SqlDecimal.Null.IsNull);\r
- Assert ("#C04", Test1.IsPositive);\r
- Assert ("#C05", !Test4.IsPositive);\r
- AssertEquals ("#C06", (byte)8, Test1.Precision);\r
- AssertEquals ("#C07", (byte)2, Test2.Scale);\r
- AssertEquals ("#C08", 6464.6464m, Test1.Value); \r
- AssertEquals ("#C09", (byte)4, Test1.Scale);\r
- AssertEquals ("#C10", (byte)7, Test2.Precision);\r
- AssertEquals ("#C11", (byte)1, Test4.Precision);\r
- }\r
-\r
- // PUBLIC METHODS\r
- [Test]\r
- public void ArithmeticMethods()\r
- {\r
-\r
- // Abs\r
- AssertEquals ("#D01", (SqlDecimal)6m, SqlDecimal.Abs (Test4));\r
- AssertEquals ("#D02", new SqlDecimal (6464.6464m).Value, SqlDecimal.Abs (Test1).Value);\r
- \r
- AssertEquals ("#D03", SqlDecimal.Null, SqlDecimal.Abs (SqlDecimal.Null));\r
- \r
- // Add()\r
- AssertEquals ("#D04", 16464.6464m, SqlDecimal.Add (Test1, Test2).Value);\r
-\r
- try {\r
- SqlDecimal test = SqlDecimal.Add (SqlDecimal.MaxValue, SqlDecimal.MaxValue);\r
- Fail ("#D05");\r
- } catch (OverflowException) {\r
- }\r
- \r
- AssertEquals ("#D07", (SqlDecimal)6465m, SqlDecimal.Ceiling(Test1));\r
- AssertEquals ("#D08", SqlDecimal.Null, SqlDecimal.Ceiling(SqlDecimal.Null));\r
- \r
- // Divide()\r
- AssertEquals ("#D09", (SqlDecimal)(-1077.441066m), SqlDecimal.Divide (Test1, Test4));\r
- AssertEquals ("#D10", 1.54687501546m, SqlDecimal.Divide (Test2, Test1).Value);\r
-\r
- try {\r
- SqlDecimal test = SqlDecimal.Divide(Test1, new SqlDecimal(0)).Value;\r
- Fail ("#D11");\r
- } catch(Exception e) {\r
- AssertEquals ("#D12", typeof (DivideByZeroException), e.GetType ());\r
- }\r
-\r
- AssertEquals ("#D13", (SqlDecimal)6464m, SqlDecimal.Floor (Test1));\r
- \r
- // Multiply()\r
- AssertEquals ("#D14", 64646464.000000m, SqlDecimal.Multiply (Test1, Test2).Value);\r
- AssertEquals ("#D15", -38787.8784m, SqlDecimal.Multiply (Test1, Test4).Value);\r
-\r
- try {\r
- SqlDecimal test = SqlDecimal.Multiply (SqlDecimal.MaxValue, Test1);\r
- Fail ("#D16");\r
- } catch (Exception e) {\r
- AssertEquals ("#D17", typeof (OverflowException), e.GetType ());\r
- }\r
- \r
- // Power\r
- AssertEquals ("#D18", (SqlDecimal)41791653.0770m, SqlDecimal.Power (Test1, 2));\r
- \r
- // Round\r
- AssertEquals ("#D19", (SqlDecimal)6464.65m, SqlDecimal.Round (Test1, 2));\r
- \r
- // Subtract()\r
- AssertEquals ("#D20", -3535.3536m, SqlDecimal.Subtract (Test1, Test3).Value);\r
-\r
- try {\r
- SqlDecimal test = SqlDecimal.Subtract(SqlDecimal.MinValue, SqlDecimal.MaxValue);\r
- Fail ("#D21");\r
- } catch (Exception e) {\r
- AssertEquals ("#D22", typeof (OverflowException), e.GetType ());\r
- } \r
- \r
- AssertEquals ("#D23", (SqlInt32)1, SqlDecimal.Sign (Test1));\r
- AssertEquals ("#D24", new SqlInt32(-1), SqlDecimal.Sign (Test4));\r
- }\r
-\r
- [Test]\r
- public void AdjustScale()\r
- {\r
- AssertEquals ("#E01", "6464.646400", SqlDecimal.AdjustScale (Test1, 2, false).Value.ToString ());\r
- AssertEquals ("#E02", "6464.65", SqlDecimal.AdjustScale (Test1, -2, true).Value.ToString ());\r
- AssertEquals ("#E03", "6464.64", SqlDecimal.AdjustScale (Test1, -2, false).Value.ToString ());\r
- AssertEquals ("#E01", "10000.000000000000", SqlDecimal.AdjustScale (Test2, 10, false).Value.ToString ());\r
- }\r
- \r
- [Test]\r
- public void ConvertToPrecScale()\r
- {\r
- AssertEquals ("#F01", new SqlDecimal(6464.6m).Value, SqlDecimal.ConvertToPrecScale (Test1, 5, 1).Value);\r
- \r
- try {\r
- SqlDecimal test = SqlDecimal.ConvertToPrecScale (Test1, 6, 5);\r
- Fail ("#F02");\r
- } catch (Exception e) {\r
- AssertEquals ("#F03", typeof (SqlTruncateException), e.GetType ());\r
- }\r
- \r
- AssertEquals ("#F01", (SqlString)"10000.00", SqlDecimal.ConvertToPrecScale (Test2, 7, 2).ToSqlString ()); \r
- }\r
- \r
- [Test]\r
- public void CompareTo()\r
- {\r
- SqlString TestString = new SqlString ("This is a test");\r
-\r
- Assert ("#G01", Test1.CompareTo (Test3) < 0);\r
- Assert ("#G02", Test2.CompareTo (Test1) > 0);\r
- Assert ("#G03", Test2.CompareTo (Test3) == 0);\r
- Assert ("#G04", Test4.CompareTo (SqlDecimal.Null) > 0);\r
-\r
- try {\r
- Test1.CompareTo (TestString);\r
- Fail("#G05");\r
- } catch(Exception e) {\r
- AssertEquals ("#G06", typeof (ArgumentException), e.GetType ());\r
- }\r
- }\r
-\r
- [Test]\r
- public void EqualsMethods()\r
- {\r
- Assert ("#H01", !Test1.Equals (Test2));\r
- Assert ("#H02", !Test2.Equals (new SqlString ("TEST")));\r
- Assert ("#H03", Test2.Equals (Test3));\r
-\r
- // Static Equals()-method\r
- Assert ("#H05", SqlDecimal.Equals (Test2, Test2).Value);\r
- Assert ("#H06", !SqlDecimal.Equals (Test1, Test2).Value);\r
- \r
- // NotEquals\r
- Assert ("#H07", SqlDecimal.NotEquals (Test1, Test2).Value);\r
- Assert ("#H08", SqlDecimal.NotEquals (Test4, Test1).Value);\r
- Assert ("#H09", !SqlDecimal.NotEquals (Test2, Test3).Value);\r
- Assert ("#H10", SqlDecimal.NotEquals (SqlDecimal.Null, Test3).IsNull); \r
- }\r
-\r
- /* Don't do such environment-dependent test. It will never succeed under Portable.NET and MS.NET\r
- [Test]\r
- public void GetHashCodeTest()\r
- {\r
- // FIXME: Better way to test HashCode\r
- AssertEquals ("#I01", -1281249885, Test1.GetHashCode ());\r
- }\r
- */\r
-\r
- [Test]\r
- public void GetTypeTest()\r
- {\r
- AssertEquals ("#J01", "System.Data.SqlTypes.SqlDecimal", \r
- Test1.GetType ().ToString ());\r
- AssertEquals ("#J02", "System.Decimal", Test1.Value.GetType ().ToString ());\r
- }\r
-\r
- [Test]\r
- public void Greaters()\r
- {\r
- // GreateThan ()\r
- Assert ("#K01", !SqlDecimal.GreaterThan (Test1, Test2).Value);\r
- Assert ("#K02", SqlDecimal.GreaterThan (Test2, Test1).Value);\r
- Assert ("#K03", !SqlDecimal.GreaterThan (Test2, Test3).Value);\r
-\r
- // GreaterTharOrEqual ()\r
- Assert ("#K04", !SqlDecimal.GreaterThanOrEqual (Test1, Test2).Value);\r
- Assert ("#K05", SqlDecimal.GreaterThanOrEqual (Test2, Test1).Value);\r
- Assert ("#K06", SqlDecimal.GreaterThanOrEqual (Test2, Test3).Value);\r
- }\r
-\r
- [Test]\r
- public void Lessers()\r
- {\r
- // LessThan()\r
- Assert ("#L01", !SqlDecimal.LessThan (Test3, Test2).Value);\r
- Assert ("#L02", !SqlDecimal.LessThan (Test2, Test1).Value);\r
- Assert ("#L03", SqlDecimal.LessThan (Test1, Test2).Value);\r
-\r
- // LessThanOrEqual ()\r
- Assert ("#L04", SqlDecimal.LessThanOrEqual (Test1, Test2).Value);\r
- Assert ("#L05", !SqlDecimal.LessThanOrEqual (Test2, Test1).Value);\r
- Assert ("#L06", SqlDecimal.LessThanOrEqual (Test2, Test3).Value);\r
- Assert ("#L07", SqlDecimal.LessThanOrEqual (Test1, SqlDecimal.Null).IsNull);\r
- }\r
-\r
- [Test]\r
- public void Parse()\r
- {\r
- try {\r
- SqlDecimal.Parse (null);\r
- Fail ("#m01");\r
- } catch (Exception e) {\r
- AssertEquals ("#M02", typeof (ArgumentNullException), e.GetType ());\r
- }\r
-\r
- try {\r
- SqlDecimal.Parse ("not-a-number");\r
- Fail ("#M03");\r
- } catch (Exception e) {\r
- AssertEquals ("#M04", typeof (FormatException), e.GetType ());\r
- }\r
-\r
- try {\r
- SqlDecimal test = SqlDecimal.Parse ("9e300");\r
- Fail ("#M05");\r
- } catch (FormatException) {\r
- }\r
-\r
- AssertEquals("#M07", 150m, SqlDecimal.Parse ("150").Value);\r
-\r
- // decimal.Parse() does not pass this string.\r
- string max = "99999999999999999999999999999999999999";\r
- SqlDecimal dx = SqlDecimal.Parse (max);\r
- AssertEquals ("#M08", max, dx.ToString ());\r
-\r
- try {\r
- dx = SqlDecimal.Parse (max + ".0");\r
- Fail ("#M09");\r
- } catch (FormatException) {\r
- }\r
- }\r
-\r
- [Test]\r
- public void Conversions()\r
- {\r
- // ToDouble\r
- AssertEquals ("N01", 6464.6464, Test1.ToDouble ());\r
- \r
- // ToSqlBoolean ()\r
- AssertEquals ("#N02", new SqlBoolean(1), Test1.ToSqlBoolean ());\r
- \r
- SqlDecimal Test = new SqlDecimal (0);\r
- Assert ("#N03", !Test.ToSqlBoolean ().Value);\r
- \r
- Test = new SqlDecimal (0);\r
- Assert ("#N04", !Test.ToSqlBoolean ().Value);\r
- Assert ("#N05", SqlDecimal.Null.ToSqlBoolean ().IsNull);\r
-\r
- // ToSqlByte ()\r
- Test = new SqlDecimal (250);\r
- AssertEquals ("#N06", (byte)250, Test.ToSqlByte ().Value);\r
-\r
- try {\r
- SqlByte b = (byte)Test2.ToSqlByte ();\r
- Fail ("#N07");\r
- } catch (Exception e) {\r
- AssertEquals ("#N08", typeof (OverflowException), e.GetType ());\r
- }\r
-\r
- // ToSqlDouble ()\r
- AssertEquals ("#N09", (SqlDouble)6464.6464, Test1.ToSqlDouble ());\r
-\r
- // ToSqlInt16 ()\r
- AssertEquals ("#N10", (short)1, new SqlDecimal (1).ToSqlInt16 ().Value);\r
-\r
- try {\r
- SqlInt16 test = SqlDecimal.MaxValue.ToSqlInt16().Value;\r
- Fail ("#N11");\r
- } catch (Exception e) {\r
- AssertEquals ("#N12", typeof (OverflowException), e.GetType ());\r
- } \r
-\r
- // ToSqlInt32 () \r
- // LAMESPEC: 6464.6464 --> 64646464 ??? with windows\r
- // MS.NET seems to return the first 32 bit integer (i.e. \r
- // Data [0]) but we don't have to follow such stupidity.\r
-// AssertEquals ("#N13a", (int)64646464, Test1.ToSqlInt32 ().Value);\r
-// AssertEquals ("#N13b", (int)1212, new SqlDecimal(12.12m).ToSqlInt32 ().Value);\r
- \r
- try {\r
- SqlInt32 test = SqlDecimal.MaxValue.ToSqlInt32 ().Value;\r
- Fail ("#N14");\r
- } catch (Exception e) { \r
- AssertEquals ("#N15", typeof (OverflowException), e.GetType ());\r
- }\r
-\r
- // ToSqlInt64 ()\r
- AssertEquals ("#N16", (long)6464, Test1.ToSqlInt64 ().Value);\r
-\r
- // ToSqlMoney ()\r
- AssertEquals ("#N17", (decimal)6464.6464, Test1.ToSqlMoney ().Value);\r
-\r
- try {\r
- SqlMoney test = SqlDecimal.MaxValue.ToSqlMoney ().Value;\r
- Fail ("#N18");\r
- } catch (Exception e) {\r
- AssertEquals ("#N19", typeof (OverflowException), e.GetType ());\r
- } \r
-\r
- // ToSqlSingle ()\r
- AssertEquals ("#N20", (float)6464.6464, Test1.ToSqlSingle ().Value);\r
-\r
- // ToSqlString ()\r
- AssertEquals ("#N21", "6464.6464", Test1.ToSqlString ().Value);\r
-\r
- // ToString ()\r
- AssertEquals ("#N22", "6464.6464", Test1.ToString ()); \r
- AssertEquals ("#N23", (SqlDouble)1E+38, SqlDecimal.MaxValue.ToSqlDouble ());\r
-\r
- }\r
- \r
- [Test]\r
- public void Truncate()\r
- {\r
-// AssertEquals ("#O01", new SqlDecimal (6464.6400m).Value, SqlDecimal.Truncate (Test1, 2).Value);\r
- AssertEquals ("#O01", 6464.6400m, SqlDecimal.Truncate (Test1, 2).Value);\r
- }\r
- \r
- // OPERATORS\r
-\r
- [Test]\r
- public void ArithmeticOperators()\r
- {\r
- // "+"-operator\r
- AssertEquals ("#P01", new SqlDecimal(16464.6464m), Test1 + Test2);\r
- \r
- try {\r
- SqlDecimal test = SqlDecimal.MaxValue + SqlDecimal.MaxValue;\r
- Fail ("#P02");\r
- } catch (Exception e) {\r
- AssertEquals ("#P03", typeof (OverflowException), e.GetType ());\r
- }\r
-\r
- // "/"-operator\r
- AssertEquals ("#P04", (SqlDecimal)1.54687501546m, Test2 / Test1);\r
-\r
- try {\r
- SqlDecimal test = Test3 / new SqlDecimal (0);\r
- Fail ("#P05");\r
- } catch (Exception e) {\r
- AssertEquals ("#P06", typeof (DivideByZeroException), e.GetType ());\r
- }\r
-\r
- // "*"-operator\r
- AssertEquals ("#P07", (SqlDecimal)64646464m, Test1 * Test2);\r
-\r
- try {\r
- SqlDecimal test = SqlDecimal.MaxValue * Test1;\r
- Fail ("#P08");\r
- } catch (Exception e) {\r
- AssertEquals ("#P09", typeof (OverflowException), e.GetType ());\r
- }\r
-\r
- // "-"-operator\r
- AssertEquals ("#P10", (SqlDecimal)3535.3536m, Test2 - Test1);\r
-\r
- try {\r
- SqlDecimal test = SqlDecimal.MinValue - SqlDecimal.MaxValue;\r
- Fail ("#P11");\r
- } catch (Exception e) {\r
- AssertEquals ("#P12", typeof (OverflowException), e.GetType ());\r
- }\r
- \r
- AssertEquals ("#P13", SqlDecimal.Null, SqlDecimal.Null + Test1);\r
- }\r
-\r
- [Test]\r
- public void ThanOrEqualOperators()\r
- {\r
-\r
- // == -operator\r
- Assert ("#Q01", (Test2 == Test3).Value);\r
- Assert ("#Q02", !(Test1 == Test2).Value);\r
- Assert ("#Q03", (Test1 == SqlDecimal.Null).IsNull);\r
- \r
- // != -operator\r
- Assert ("#Q04", !(Test2 != Test3).Value);\r
- Assert ("#Q05", (Test1 != Test3).Value);\r
- Assert ("#Q06", (Test4 != Test3).Value);\r
- Assert ("#Q07", (Test1 != SqlDecimal.Null).IsNull);\r
-\r
- // > -operator\r
- Assert ("#Q08", (Test2 > Test1).Value);\r
- Assert ("#Q09", !(Test1 > Test3).Value);\r
- Assert ("#Q10", !(Test2 > Test3).Value);\r
- Assert ("#Q11", (Test1 > SqlDecimal.Null).IsNull);\r
-\r
- // >= -operator\r
- Assert ("#Q12", !(Test1 >= Test3).Value);\r
- Assert ("#Q13", (Test3 >= Test1).Value);\r
- Assert ("#Q14", (Test2 >= Test3).Value);\r
- Assert ("#Q15", (Test1 >= SqlDecimal.Null).IsNull);\r
-\r
- // < -operator\r
- Assert ("#Q16", !(Test2 < Test1).Value);\r
- Assert ("#Q17", (Test1 < Test3).Value);\r
- Assert ("#Q18", !(Test2 < Test3).Value);\r
- Assert ("#Q19", (Test1 < SqlDecimal.Null).IsNull);\r
-\r
- // <= -operator\r
- Assert ("#Q20", (Test1 <= Test3).Value);\r
- Assert ("#Q21", !(Test3 <= Test1).Value);\r
- Assert ("#Q22", (Test2 <= Test3).Value);\r
- Assert ("#Q23", (Test1 <= SqlDecimal.Null).IsNull);\r
- }\r
-\r
- [Test]\r
- public void UnaryNegation()\r
- {\r
- AssertEquals ("#R01", 6m, -Test4.Value);\r
- AssertEquals ("#R02", -6464.6464m, -Test1.Value);\r
- AssertEquals ("#R03", SqlDecimal.Null, SqlDecimal.Null);\r
- }\r
-\r
- [Test]\r
- public void SqlBooleanToSqlDecimal()\r
- {\r
- SqlBoolean TestBoolean = new SqlBoolean (true);\r
- SqlDecimal Result;\r
-\r
- Result = (SqlDecimal)TestBoolean;\r
-\r
- AssertEquals ("#S01", 1m, Result.Value);\r
-\r
- Result = (SqlDecimal)SqlBoolean.Null;\r
- Assert ("#S02", Result.IsNull);\r
- AssertEquals ("#S03", SqlDecimal.Null, (SqlDecimal)SqlBoolean.Null);\r
- }\r
- \r
- [Test]\r
- public void SqlDecimalToDecimal()\r
- {\r
- AssertEquals ("#T01", 6464.6464m, (Decimal)Test1);\r
- }\r
-\r
- [Test]\r
- public void SqlDoubleToSqlDecimal()\r
- {\r
- SqlDouble Test = new SqlDouble (12E+10);\r
- AssertEquals ("#U01", 120000000000.00000m, ((SqlDecimal)Test).Value);\r
- }\r
- \r
- [Test]\r
- public void SqlSingleToSqlDecimal()\r
- {\r
- SqlSingle Test = new SqlSingle (1E+9);\r
- AssertEquals ("#V01", 1000000000.0000000m, ((SqlDecimal)Test).Value);\r
- \r
- try {\r
- SqlDecimal test = (SqlDecimal)SqlSingle.MaxValue;\r
- Fail ("#V02");\r
- } catch (Exception e) {\r
- AssertEquals ("#V03", typeof (OverflowException), e.GetType ());\r
- }\r
- }\r
-\r
- [Test]\r
- public void SqlStringToSqlDecimal()\r
- {\r
- SqlString TestString = new SqlString ("Test string");\r
- SqlString TestString100 = new SqlString ("100");\r
-\r
- AssertEquals ("#W01", 100m, ((SqlDecimal)TestString100).Value);\r
-\r
- try {\r
- SqlDecimal test = (SqlDecimal)TestString;\r
- Fail ("#W02");\r
- } catch(Exception e) {\r
- AssertEquals ("#W03", typeof (FormatException), e.GetType ());\r
- }\r
- \r
- try {\r
- SqlDecimal test = (SqlDecimal)new SqlString("9E+100");\r
- Fail ("#W04");\r
- } catch (Exception e) {\r
- AssertEquals ("#W05", typeof (FormatException), e.GetType());\r
- }\r
- }\r
-\r
- [Test]\r
- public void DecimalToSqlDecimal()\r
- {\r
- decimal d = 1000.1m;\r
- AssertEquals ("#X01", (SqlDecimal)1000.1m, (SqlDecimal)d); \r
- }\r
- \r
- [Test]\r
- public void ByteToSqlDecimal()\r
- { \r
- AssertEquals ("#Y01", 255m, ((SqlDecimal)SqlByte.MaxValue).Value);\r
- }\r
- \r
- [Test]\r
- public void SqlIntToSqlDouble()\r
- {\r
- SqlInt16 Test64 = new SqlInt16 (64);\r
- SqlInt32 Test640 = new SqlInt32 (640);\r
- SqlInt64 Test64000 = new SqlInt64 (64000);\r
- AssertEquals ("#Z01", 64m, ((SqlDecimal)Test64).Value);\r
- AssertEquals ("#Z02", 640m,((SqlDecimal)Test640).Value);\r
- AssertEquals ("#Z03", 64000m, ((SqlDecimal)Test64000).Value);\r
- }\r
-\r
- [Test]\r
- public void SqlMoneyToSqlDecimal()\r
- {\r
- SqlMoney TestMoney64 = new SqlMoney(64);\r
- AssertEquals ("#AA01", 64.0000M, ((SqlDecimal)TestMoney64).Value);\r
- }\r
-\r
- [Test]\r
- public void ToStringTest ()\r
- {\r
- AssertEquals ("#01", "Null", SqlDecimal.Null.ToString ());\r
- AssertEquals ("#02", "-99999999999999999999999999999999999999", SqlDecimal.MinValue.ToString ());\r
- AssertEquals ("#03", "99999999999999999999999999999999999999", SqlDecimal.MaxValue.ToString ());\r
- }\r
-\r
- [Test]\r
- public void Value ()\r
- {\r
- decimal d = decimal.Parse ("9999999999999999999999999999");\r
- }\r
- }\r
-}\r
-\r
+
+using NUnit.Framework;
+using System;
+using System.Data.SqlTypes;
+using System.Threading;
+using System.Globalization;
+
+namespace MonoTests.System.Data.SqlTypes
+{
+ [TestFixture]
+ public class SqlDecimalTest : Assertion {
+
+ private SqlDecimal Test1;
+ private SqlDecimal Test2;
+ private SqlDecimal Test3;
+ private SqlDecimal Test4;
+
+ [SetUp]
+ public void GetReady()
+ {
+ Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US");
+ Test1 = new SqlDecimal (6464.6464m);
+ Test2 = new SqlDecimal (10000.00m);
+ Test3 = new SqlDecimal (10000.00m);
+ Test4 = new SqlDecimal (-6m);
+ }
+
+ // Test constructor
+ [Test]
+ public void Create()
+ {
+ // SqlDecimal (decimal)
+ SqlDecimal Test = new SqlDecimal (30.3098m);
+ AssertEquals ("#A01", (decimal)30.3098, Test.Value);
+
+ try {
+ decimal d = Decimal.MaxValue;
+ SqlDecimal test = new SqlDecimal (d + 1);
+ Fail ("#A02");
+ } catch (Exception e) {
+ AssertEquals ("#A03", typeof (OverflowException), e.GetType ());
+ }
+
+ // SqlDecimal (double)
+ Test = new SqlDecimal (10E+10d);
+ AssertEquals ("#A05", 100000000000.00000m, Test.Value);
+
+ try {
+ SqlDecimal test = new SqlDecimal (10E+200d);
+ Fail ("#A06");
+ } catch (Exception e) {
+ AssertEquals ("#A07", typeof (OverflowException), e.GetType ());
+ }
+
+ // SqlDecimal (int)
+ Test = new SqlDecimal (-1);
+ AssertEquals ("#A08", -1m, Test.Value);
+
+ // SqlDecimal (long)
+ Test = new SqlDecimal ((long)(-99999));
+ AssertEquals ("#A09", -99999m, Test.Value);
+
+ // SqlDecimal (byte, byte, bool. int[]
+ Test = new SqlDecimal (10, 3, false, new int [4] {200, 1, 0, 0});
+ AssertEquals ("#A10", -4294967.496m, Test.Value);
+
+ try {
+ Test = new SqlDecimal (100, 100, false,
+ new int [4] {Int32.MaxValue,
+ Int32.MaxValue, Int32.MaxValue,
+ Int32.MaxValue});
+ Fail ("#A11");
+ } catch (SqlTypeException) {
+ }
+
+ // sqlDecimal (byte, byte, bool, int, int, int, int)
+ Test = new SqlDecimal (12, 2, true, 100, 100, 0, 0);
+ AssertEquals ("#A13", 4294967297.00m, Test.Value);
+
+ try {
+ Test = new SqlDecimal (100, 100, false,
+ Int32.MaxValue,
+ Int32.MaxValue, Int32.MaxValue,
+ Int32.MaxValue);
+ Fail ("#A14");
+ } catch (SqlTypeException) {
+ }
+ }
+
+ // Test public fields
+ [Test]
+ public void PublicFields()
+ {
+ AssertEquals ("#B01", (byte)38, SqlDecimal.MaxPrecision);
+ AssertEquals ("#B02", (byte)38, SqlDecimal.MaxScale);
+
+ // FIXME: on windows: Conversion overflow
+ AssertEquals ("#B03a", 1262177448, SqlDecimal.MaxValue.Data [3]);
+
+
+ AssertEquals ("#B04", 1262177448, SqlDecimal.MinValue.Data [3]);
+ Assert ("#B05", SqlDecimal.Null.IsNull);
+ Assert ("#B06", !Test1.IsNull);
+ }
+
+ // Test properties
+ [Test]
+ public void Properties()
+ {
+ byte[] b = Test1.BinData;
+ AssertEquals ("#C01", (byte)64, b [0]);
+
+ int[] i = Test1.Data;
+ AssertEquals ("#C02", 64646464, i [0]);
+
+ Assert ("#C03", SqlDecimal.Null.IsNull);
+ Assert ("#C04", Test1.IsPositive);
+ Assert ("#C05", !Test4.IsPositive);
+ AssertEquals ("#C06", (byte)8, Test1.Precision);
+ AssertEquals ("#C07", (byte)2, Test2.Scale);
+ AssertEquals ("#C08", 6464.6464m, Test1.Value);
+ AssertEquals ("#C09", (byte)4, Test1.Scale);
+ AssertEquals ("#C10", (byte)7, Test2.Precision);
+ AssertEquals ("#C11", (byte)1, Test4.Precision);
+ }
+
+ // PUBLIC METHODS
+ [Test]
+ [Category ("NotWorking")]
+ public void ArithmeticMethods()
+ {
+
+ // Abs
+ AssertEquals ("#D01", (SqlDecimal)6m, SqlDecimal.Abs (Test4));
+ AssertEquals ("#D02", new SqlDecimal (6464.6464m).Value, SqlDecimal.Abs (Test1).Value);
+
+ AssertEquals ("#D03", SqlDecimal.Null, SqlDecimal.Abs (SqlDecimal.Null));
+
+ // Add()
+ AssertEquals ("#D04", 16464.6464m, SqlDecimal.Add (Test1, Test2).Value);
+
+ try {
+ SqlDecimal test = SqlDecimal.Add (SqlDecimal.MaxValue, SqlDecimal.MaxValue);
+ Fail ("#D05");
+ } catch (OverflowException) {
+ }
+
+ AssertEquals ("#D07", (SqlDecimal)6465m, SqlDecimal.Ceiling(Test1));
+ AssertEquals ("#D08", SqlDecimal.Null, SqlDecimal.Ceiling(SqlDecimal.Null));
+
+ // Divide()
+ AssertEquals ("#D09", (SqlDecimal)(-1077.441066m), SqlDecimal.Divide (Test1, Test4));
+ AssertEquals ("#D10", 1.54687501546m, SqlDecimal.Divide (Test2, Test1).Value);
+
+ try {
+ SqlDecimal test = SqlDecimal.Divide(Test1, new SqlDecimal(0)).Value;
+ Fail ("#D11");
+ } catch(Exception e) {
+ AssertEquals ("#D12", typeof (DivideByZeroException), e.GetType ());
+ }
+
+ AssertEquals ("#D13", (SqlDecimal)6464m, SqlDecimal.Floor (Test1));
+
+ // Multiply()
+ AssertEquals ("#D14", 64646464.000000m, SqlDecimal.Multiply (Test1, Test2).Value);
+ AssertEquals ("#D15", -38787.8784m, SqlDecimal.Multiply (Test1, Test4).Value);
+
+ try {
+ SqlDecimal test = SqlDecimal.Multiply (SqlDecimal.MaxValue, Test1);
+ Fail ("#D16");
+ } catch (Exception e) {
+ AssertEquals ("#D17", typeof (OverflowException), e.GetType ());
+ }
+
+ // Power
+ AssertEquals ("#D18", (SqlDecimal)41791653.0770m, SqlDecimal.Power (Test1, 2));
+
+ // Round
+ AssertEquals ("#D19", (SqlDecimal)6464.65m, SqlDecimal.Round (Test1, 2));
+
+ // Subtract()
+ AssertEquals ("#D20", -3535.3536m, SqlDecimal.Subtract (Test1, Test3).Value);
+
+ try {
+ SqlDecimal test = SqlDecimal.Subtract(SqlDecimal.MinValue, SqlDecimal.MaxValue);
+ Fail ("#D21");
+ } catch (Exception e) {
+ AssertEquals ("#D22", typeof (OverflowException), e.GetType ());
+ }
+
+ AssertEquals ("#D23", (SqlInt32)1, SqlDecimal.Sign (Test1));
+ AssertEquals ("#D24", new SqlInt32(-1), SqlDecimal.Sign (Test4));
+ }
+
+ [Test]
+ public void AdjustScale()
+ {
+ AssertEquals ("#E01", "6464.646400", SqlDecimal.AdjustScale (Test1, 2, false).Value.ToString ());
+ AssertEquals ("#E02", "6464.65", SqlDecimal.AdjustScale (Test1, -2, true).Value.ToString ());
+ AssertEquals ("#E03", "6464.64", SqlDecimal.AdjustScale (Test1, -2, false).Value.ToString ());
+ AssertEquals ("#E01", "10000.000000000000", SqlDecimal.AdjustScale (Test2, 10, false).Value.ToString ());
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void ConvertToPrecScale()
+ {
+ AssertEquals ("#F01", new SqlDecimal(6464.6m).Value, SqlDecimal.ConvertToPrecScale (Test1, 5, 1).Value);
+
+ try {
+ SqlDecimal test = SqlDecimal.ConvertToPrecScale (Test1, 6, 5);
+ Fail ("#F02");
+ } catch (Exception e) {
+ AssertEquals ("#F03", typeof (SqlTruncateException), e.GetType ());
+ }
+
+ AssertEquals ("#F01", (SqlString)"10000.00", SqlDecimal.ConvertToPrecScale (Test2, 7, 2).ToSqlString ());
+ }
+
+ [Test]
+ public void CompareTo()
+ {
+ SqlString TestString = new SqlString ("This is a test");
+
+ Assert ("#G01", Test1.CompareTo (Test3) < 0);
+ Assert ("#G02", Test2.CompareTo (Test1) > 0);
+ Assert ("#G03", Test2.CompareTo (Test3) == 0);
+ Assert ("#G04", Test4.CompareTo (SqlDecimal.Null) > 0);
+
+ try {
+ Test1.CompareTo (TestString);
+ Fail("#G05");
+ } catch(Exception e) {
+ AssertEquals ("#G06", typeof (ArgumentException), e.GetType ());
+ }
+ }
+
+ [Test]
+ public void EqualsMethods()
+ {
+ Assert ("#H01", !Test1.Equals (Test2));
+ Assert ("#H02", !Test2.Equals (new SqlString ("TEST")));
+ Assert ("#H03", Test2.Equals (Test3));
+
+ // Static Equals()-method
+ Assert ("#H05", SqlDecimal.Equals (Test2, Test2).Value);
+ Assert ("#H06", !SqlDecimal.Equals (Test1, Test2).Value);
+
+ // NotEquals
+ Assert ("#H07", SqlDecimal.NotEquals (Test1, Test2).Value);
+ Assert ("#H08", SqlDecimal.NotEquals (Test4, Test1).Value);
+ Assert ("#H09", !SqlDecimal.NotEquals (Test2, Test3).Value);
+ Assert ("#H10", SqlDecimal.NotEquals (SqlDecimal.Null, Test3).IsNull);
+ }
+
+ /* Don't do such environment-dependent test. It will never succeed under Portable.NET and MS.NET
+ [Test]
+ public void GetHashCodeTest()
+ {
+ // FIXME: Better way to test HashCode
+ AssertEquals ("#I01", -1281249885, Test1.GetHashCode ());
+ }
+ */
+
+ [Test]
+ public void GetTypeTest()
+ {
+ AssertEquals ("#J01", "System.Data.SqlTypes.SqlDecimal",
+ Test1.GetType ().ToString ());
+ AssertEquals ("#J02", "System.Decimal", Test1.Value.GetType ().ToString ());
+ }
+
+ [Test]
+ public void Greaters()
+ {
+ // GreateThan ()
+ Assert ("#K01", !SqlDecimal.GreaterThan (Test1, Test2).Value);
+ Assert ("#K02", SqlDecimal.GreaterThan (Test2, Test1).Value);
+ Assert ("#K03", !SqlDecimal.GreaterThan (Test2, Test3).Value);
+
+ // GreaterTharOrEqual ()
+ Assert ("#K04", !SqlDecimal.GreaterThanOrEqual (Test1, Test2).Value);
+ Assert ("#K05", SqlDecimal.GreaterThanOrEqual (Test2, Test1).Value);
+ Assert ("#K06", SqlDecimal.GreaterThanOrEqual (Test2, Test3).Value);
+ }
+
+ [Test]
+ public void Lessers()
+ {
+ // LessThan()
+ Assert ("#L01", !SqlDecimal.LessThan (Test3, Test2).Value);
+ Assert ("#L02", !SqlDecimal.LessThan (Test2, Test1).Value);
+ Assert ("#L03", SqlDecimal.LessThan (Test1, Test2).Value);
+
+ // LessThanOrEqual ()
+ Assert ("#L04", SqlDecimal.LessThanOrEqual (Test1, Test2).Value);
+ Assert ("#L05", !SqlDecimal.LessThanOrEqual (Test2, Test1).Value);
+ Assert ("#L06", SqlDecimal.LessThanOrEqual (Test2, Test3).Value);
+ Assert ("#L07", SqlDecimal.LessThanOrEqual (Test1, SqlDecimal.Null).IsNull);
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void Parse()
+ {
+ try {
+ SqlDecimal.Parse (null);
+ Fail ("#m01");
+ } catch (Exception e) {
+ AssertEquals ("#M02", typeof (ArgumentNullException), e.GetType ());
+ }
+
+ try {
+ SqlDecimal.Parse ("not-a-number");
+ Fail ("#M03");
+ } catch (Exception e) {
+ AssertEquals ("#M04", typeof (FormatException), e.GetType ());
+ }
+
+ try {
+ SqlDecimal test = SqlDecimal.Parse ("9e300");
+ Fail ("#M05");
+ } catch (FormatException) {
+ }
+
+ AssertEquals("#M07", 150m, SqlDecimal.Parse ("150").Value);
+
+ // decimal.Parse() does not pass this string.
+ string max = "99999999999999999999999999999999999999";
+ SqlDecimal dx = SqlDecimal.Parse (max);
+ AssertEquals ("#M08", max, dx.ToString ());
+
+ try {
+ dx = SqlDecimal.Parse (max + ".0");
+ Fail ("#M09");
+ } catch (FormatException) {
+ }
+ }
+
+ [Test]
+ public void Conversions()
+ {
+ // ToDouble
+ AssertEquals ("N01", 6464.6464, Test1.ToDouble ());
+
+ // ToSqlBoolean ()
+ AssertEquals ("#N02", new SqlBoolean(1), Test1.ToSqlBoolean ());
+
+ SqlDecimal Test = new SqlDecimal (0);
+ Assert ("#N03", !Test.ToSqlBoolean ().Value);
+
+ Test = new SqlDecimal (0);
+ Assert ("#N04", !Test.ToSqlBoolean ().Value);
+ Assert ("#N05", SqlDecimal.Null.ToSqlBoolean ().IsNull);
+
+ // ToSqlByte ()
+ Test = new SqlDecimal (250);
+ AssertEquals ("#N06", (byte)250, Test.ToSqlByte ().Value);
+
+ try {
+ SqlByte b = (byte)Test2.ToSqlByte ();
+ Fail ("#N07");
+ } catch (Exception e) {
+ AssertEquals ("#N08", typeof (OverflowException), e.GetType ());
+ }
+
+ // ToSqlDouble ()
+ AssertEquals ("#N09", (SqlDouble)6464.6464, Test1.ToSqlDouble ());
+
+ // ToSqlInt16 ()
+ AssertEquals ("#N10", (short)1, new SqlDecimal (1).ToSqlInt16 ().Value);
+
+ try {
+ SqlInt16 test = SqlDecimal.MaxValue.ToSqlInt16().Value;
+ Fail ("#N11");
+ } catch (Exception e) {
+ AssertEquals ("#N12", typeof (OverflowException), e.GetType ());
+ }
+
+ // ToSqlInt32 ()
+ // LAMESPEC: 6464.6464 --> 64646464 ??? with windows
+ // MS.NET seems to return the first 32 bit integer (i.e.
+ // Data [0]) but we don't have to follow such stupidity.
+// AssertEquals ("#N13a", (int)64646464, Test1.ToSqlInt32 ().Value);
+// AssertEquals ("#N13b", (int)1212, new SqlDecimal(12.12m).ToSqlInt32 ().Value);
+
+ try {
+ SqlInt32 test = SqlDecimal.MaxValue.ToSqlInt32 ().Value;
+ Fail ("#N14");
+ } catch (Exception e) {
+ AssertEquals ("#N15", typeof (OverflowException), e.GetType ());
+ }
+
+ // ToSqlInt64 ()
+ AssertEquals ("#N16", (long)6464, Test1.ToSqlInt64 ().Value);
+
+ // ToSqlMoney ()
+ AssertEquals ("#N17", (decimal)6464.6464, Test1.ToSqlMoney ().Value);
+
+ try {
+ SqlMoney test = SqlDecimal.MaxValue.ToSqlMoney ().Value;
+ Fail ("#N18");
+ } catch (Exception e) {
+ AssertEquals ("#N19", typeof (OverflowException), e.GetType ());
+ }
+
+ // ToSqlSingle ()
+ AssertEquals ("#N20", (float)6464.6464, Test1.ToSqlSingle ().Value);
+
+ // ToSqlString ()
+ AssertEquals ("#N21", "6464.6464", Test1.ToSqlString ().Value);
+
+ // ToString ()
+ AssertEquals ("#N22", "6464.6464", Test1.ToString ());
+ AssertEquals ("#N23", (SqlDouble)1E+38, SqlDecimal.MaxValue.ToSqlDouble ());
+
+ }
+
+ [Test]
+ public void Truncate()
+ {
+// AssertEquals ("#O01", new SqlDecimal (6464.6400m).Value, SqlDecimal.Truncate (Test1, 2).Value);
+ AssertEquals ("#O01", 6464.6400m, SqlDecimal.Truncate (Test1, 2).Value);
+ }
+
+ // OPERATORS
+
+ [Test]
+ [Category ("NotWorking")]
+ public void ArithmeticOperators()
+ {
+ // "+"-operator
+ AssertEquals ("#P01", new SqlDecimal(16464.6464m), Test1 + Test2);
+
+ try {
+ SqlDecimal test = SqlDecimal.MaxValue + SqlDecimal.MaxValue;
+ Fail ("#P02");
+ } catch (Exception e) {
+ AssertEquals ("#P03", typeof (OverflowException), e.GetType ());
+ }
+
+ // "/"-operator
+ AssertEquals ("#P04", (SqlDecimal)1.54687501546m, Test2 / Test1);
+
+ try {
+ SqlDecimal test = Test3 / new SqlDecimal (0);
+ Fail ("#P05");
+ } catch (Exception e) {
+ AssertEquals ("#P06", typeof (DivideByZeroException), e.GetType ());
+ }
+
+ // "*"-operator
+ AssertEquals ("#P07", (SqlDecimal)64646464m, Test1 * Test2);
+
+ try {
+ SqlDecimal test = SqlDecimal.MaxValue * Test1;
+ Fail ("#P08");
+ } catch (Exception e) {
+ AssertEquals ("#P09", typeof (OverflowException), e.GetType ());
+ }
+
+ // "-"-operator
+ AssertEquals ("#P10", (SqlDecimal)3535.3536m, Test2 - Test1);
+
+ try {
+ SqlDecimal test = SqlDecimal.MinValue - SqlDecimal.MaxValue;
+ Fail ("#P11");
+ } catch (Exception e) {
+ AssertEquals ("#P12", typeof (OverflowException), e.GetType ());
+ }
+
+ AssertEquals ("#P13", SqlDecimal.Null, SqlDecimal.Null + Test1);
+ }
+
+ [Test]
+ public void ThanOrEqualOperators()
+ {
+
+ // == -operator
+ Assert ("#Q01", (Test2 == Test3).Value);
+ Assert ("#Q02", !(Test1 == Test2).Value);
+ Assert ("#Q03", (Test1 == SqlDecimal.Null).IsNull);
+
+ // != -operator
+ Assert ("#Q04", !(Test2 != Test3).Value);
+ Assert ("#Q05", (Test1 != Test3).Value);
+ Assert ("#Q06", (Test4 != Test3).Value);
+ Assert ("#Q07", (Test1 != SqlDecimal.Null).IsNull);
+
+ // > -operator
+ Assert ("#Q08", (Test2 > Test1).Value);
+ Assert ("#Q09", !(Test1 > Test3).Value);
+ Assert ("#Q10", !(Test2 > Test3).Value);
+ Assert ("#Q11", (Test1 > SqlDecimal.Null).IsNull);
+
+ // >= -operator
+ Assert ("#Q12", !(Test1 >= Test3).Value);
+ Assert ("#Q13", (Test3 >= Test1).Value);
+ Assert ("#Q14", (Test2 >= Test3).Value);
+ Assert ("#Q15", (Test1 >= SqlDecimal.Null).IsNull);
+
+ // < -operator
+ Assert ("#Q16", !(Test2 < Test1).Value);
+ Assert ("#Q17", (Test1 < Test3).Value);
+ Assert ("#Q18", !(Test2 < Test3).Value);
+ Assert ("#Q19", (Test1 < SqlDecimal.Null).IsNull);
+
+ // <= -operator
+ Assert ("#Q20", (Test1 <= Test3).Value);
+ Assert ("#Q21", !(Test3 <= Test1).Value);
+ Assert ("#Q22", (Test2 <= Test3).Value);
+ Assert ("#Q23", (Test1 <= SqlDecimal.Null).IsNull);
+ }
+
+ [Test]
+ public void UnaryNegation()
+ {
+ AssertEquals ("#R01", 6m, -Test4.Value);
+ AssertEquals ("#R02", -6464.6464m, -Test1.Value);
+ AssertEquals ("#R03", SqlDecimal.Null, SqlDecimal.Null);
+ }
+
+ [Test]
+ public void SqlBooleanToSqlDecimal()
+ {
+ SqlBoolean TestBoolean = new SqlBoolean (true);
+ SqlDecimal Result;
+
+ Result = (SqlDecimal)TestBoolean;
+
+ AssertEquals ("#S01", 1m, Result.Value);
+
+ Result = (SqlDecimal)SqlBoolean.Null;
+ Assert ("#S02", Result.IsNull);
+ AssertEquals ("#S03", SqlDecimal.Null, (SqlDecimal)SqlBoolean.Null);
+ }
+
+ [Test]
+ public void SqlDecimalToDecimal()
+ {
+ AssertEquals ("#T01", 6464.6464m, (Decimal)Test1);
+ }
+
+ [Test]
+ public void SqlDoubleToSqlDecimal()
+ {
+ SqlDouble Test = new SqlDouble (12E+10);
+ AssertEquals ("#U01", 120000000000.00000m, ((SqlDecimal)Test).Value);
+ }
+
+ [Test]
+ public void SqlSingleToSqlDecimal()
+ {
+ SqlSingle Test = new SqlSingle (1E+9);
+ AssertEquals ("#V01", 1000000000.0000000m, ((SqlDecimal)Test).Value);
+
+ try {
+ SqlDecimal test = (SqlDecimal)SqlSingle.MaxValue;
+ Fail ("#V02");
+ } catch (Exception e) {
+ AssertEquals ("#V03", typeof (OverflowException), e.GetType ());
+ }
+ }
+
+ [Test]
+ public void SqlStringToSqlDecimal()
+ {
+ SqlString TestString = new SqlString ("Test string");
+ SqlString TestString100 = new SqlString ("100");
+
+ AssertEquals ("#W01", 100m, ((SqlDecimal)TestString100).Value);
+
+ try {
+ SqlDecimal test = (SqlDecimal)TestString;
+ Fail ("#W02");
+ } catch(Exception e) {
+ AssertEquals ("#W03", typeof (FormatException), e.GetType ());
+ }
+
+ try {
+ SqlDecimal test = (SqlDecimal)new SqlString("9E+100");
+ Fail ("#W04");
+ } catch (Exception e) {
+ AssertEquals ("#W05", typeof (FormatException), e.GetType());
+ }
+ }
+
+ [Test]
+ public void DecimalToSqlDecimal()
+ {
+ decimal d = 1000.1m;
+ AssertEquals ("#X01", (SqlDecimal)1000.1m, (SqlDecimal)d);
+ }
+
+ [Test]
+ public void ByteToSqlDecimal()
+ {
+ AssertEquals ("#Y01", 255m, ((SqlDecimal)SqlByte.MaxValue).Value);
+ }
+
+ [Test]
+ public void SqlIntToSqlDouble()
+ {
+ SqlInt16 Test64 = new SqlInt16 (64);
+ SqlInt32 Test640 = new SqlInt32 (640);
+ SqlInt64 Test64000 = new SqlInt64 (64000);
+ AssertEquals ("#Z01", 64m, ((SqlDecimal)Test64).Value);
+ AssertEquals ("#Z02", 640m,((SqlDecimal)Test640).Value);
+ AssertEquals ("#Z03", 64000m, ((SqlDecimal)Test64000).Value);
+ }
+
+ [Test]
+ public void SqlMoneyToSqlDecimal()
+ {
+ SqlMoney TestMoney64 = new SqlMoney(64);
+ AssertEquals ("#AA01", 64.0000M, ((SqlDecimal)TestMoney64).Value);
+ }
+
+ [Test]
+ public void ToStringTest ()
+ {
+ AssertEquals ("#01", "Null", SqlDecimal.Null.ToString ());
+ AssertEquals ("#02", "-99999999999999999999999999999999999999", SqlDecimal.MinValue.ToString ());
+ AssertEquals ("#03", "99999999999999999999999999999999999999", SqlDecimal.MaxValue.ToString ());
+ }
+
+ [Test]
+ public void Value ()
+ {
+ decimal d = decimal.Parse ("9999999999999999999999999999");
+ }
+ }
+}
+
-//\r
-// DataSetReadXmlSchemaTest.cs\r
-//\r
-// Author:\r
-// Atsushi Enomoto <atsushi@ximian.com>\r
-//\r
+//
+// DataSetReadXmlSchemaTest.cs
+//
+// Author:
+// Atsushi Enomoto <atsushi@ximian.com>
+//
//
// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-\r
-\r
-using System;\r
-using System.IO;\r
-using System.Data;\r
-using System.Globalization;\r
-using System.Text;\r
-using System.Threading;\r
-using System.Xml;\r
-using NUnit.Framework;\r
-\r
-namespace MonoTests.System.Data\r
-{\r
- [TestFixture]\r
- public class DataSetReadXmlSchemaTest : DataSetAssertion\r
- {\r
- private DataSet CreateTestSet ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.Tables.Add ("Table1");\r
- ds.Tables.Add ("Table2");\r
- ds.Tables [0].Columns.Add ("Column1_1");\r
- ds.Tables [0].Columns.Add ("Column1_2");\r
- ds.Tables [0].Columns.Add ("Column1_3");\r
- ds.Tables [1].Columns.Add ("Column2_1");\r
- ds.Tables [1].Columns.Add ("Column2_2");\r
- ds.Tables [1].Columns.Add ("Column2_3");\r
- ds.Tables [0].Rows.Add (new object [] {"ppp", "www", "xxx"});\r
- ds.Relations.Add ("Rel1", ds.Tables [0].Columns [2], ds.Tables [1].Columns [0]);\r
- return ds;\r
- }\r
-\r
- CultureInfo currentCultureBackup;\r
-\r
- [SetUp]\r
- public void Setup ()\r
- {\r
- currentCultureBackup = Thread.CurrentThread.CurrentCulture;\r
- Thread.CurrentThread.CurrentCulture = new CultureInfo ("fi-FI");\r
- }\r
-\r
- [TearDown]\r
- public void Teardown ()\r
- {\r
- Thread.CurrentThread.CurrentCulture = currentCultureBackup;\r
- }\r
-\r
- [Test]\r
- public void SingleElementTreatmentDifference ()\r
- {\r
- // This is one of the most complicated case. When the content\r
- // type particle of 'Root' element is a complex element, it\r
- // is DataSet element. Otherwise, it is just a data table.\r
- //\r
- // But also note that there is another test named\r
- // LocaleOnRootWithoutIsDataSet(), that tests if locale on\r
- // the (mere) data table modifies *DataSet's* locale.\r
-\r
- // Moreover, when the schema contains another element\r
- // (regardless of its schema type), the elements will\r
- // never be treated as a DataSet.\r
- string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>\r
- <xs:element name='Root'> <!-- When simple, it becomes table. When complex, it becomes DataSet -->\r
- <xs:complexType>\r
- <xs:choice>\r
- {0}\r
- </xs:choice>\r
- </xs:complexType>\r
- </xs:element>\r
-</xs:schema>";\r
-\r
- string xsbase2 = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>\r
- <xs:element name='Root'> <!-- When simple, it becomes table. When complex, it becomes DataSet -->\r
- <xs:complexType>\r
- <xs:choice>\r
- {0}\r
- </xs:choice>\r
- </xs:complexType>\r
- </xs:element>\r
- <xs:element name='more' type='xs:string' />\r
-</xs:schema>";\r
-\r
- string simple = "<xs:element name='Child' type='xs:string' />";\r
- string complex = @"<xs:element name='Child'>\r
- <xs:complexType>\r
- <xs:attribute name='a1' />\r
- <xs:attribute name='a2' type='xs:integer' />\r
- </xs:complexType>\r
-</xs:element>";\r
- string elref = "<xs:element ref='more' />";\r
-\r
- string xs2 = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>\r
- <xs:element name='Root' type='RootType' />\r
- <xs:complexType name='RootType'>\r
- <xs:choice>\r
- <xs:element name='Child'>\r
- <xs:complexType>\r
- <xs:attribute name='a1' />\r
- <xs:attribute name='a2' type='xs:integer' />\r
- </xs:complexType>\r
- </xs:element>\r
- </xs:choice>\r
- </xs:complexType>\r
-</xs:schema>";\r
-\r
- DataSet ds = new DataSet ();\r
-\r
- string xs = String.Format (xsbase, simple);\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertDataSet ("simple", ds, "hoge", 1, 0);\r
- AssertDataTable ("simple", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);\r
-\r
- // reference to global complex type\r
- ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs2));\r
- AssertDataSet ("external complexType", ds, "hoge", 2, 1);\r
- AssertDataTable ("external Tab1", ds.Tables [0], "Root", 1, 0, 0, 1, 1, 1);\r
- AssertDataTable ("external Tab2", ds.Tables [1], "Child", 3, 0, 1, 0, 1, 0);\r
-\r
- // xsbase2 + complex -> datatable\r
- ds = new DataSet ();\r
- xs = String.Format (xsbase2, complex);\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertDataSet ("complex", ds, "hoge", 2, 1);\r
- AssertDataTable ("complex", ds.Tables [0], "Root", 1, 0, 0, 1, 1, 1);\r
- DataTable dt = ds.Tables [1];\r
- AssertDataTable ("complex", dt, "Child", 3, 0, 1, 0, 1, 0);\r
- AssertDataColumn ("a1", dt.Columns ["a1"], "a1", true, false, 0, 1, "a1", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, /*0*/-1, String.Empty, false, false);\r
- AssertDataColumn ("a2", dt.Columns ["a2"], "a2", true, false, 0, 1, "a2", MappingType.Attribute, typeof (long), DBNull.Value, String.Empty, -1, String.Empty, /*1*/-1, String.Empty, false, false);\r
- AssertDataColumn ("Root_Id", dt.Columns [2], "Root_Id", true, false, 0, 1, "Root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 2, String.Empty, false, false);\r
-\r
- // xsbase + complex -> dataset\r
- ds = new DataSet ();\r
- xs = String.Format (xsbase, complex);\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertDataSet ("complex", ds, "Root", 1, 0);\r
-\r
- ds = new DataSet ();\r
- xs = String.Format (xsbase2, elref);\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertDataSet ("complex", ds, "hoge", 1, 0);\r
- AssertDataTable ("complex", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);\r
- }\r
-\r
- [Test]\r
- public void SuspiciousDataSetElement ()\r
- {\r
- string schema = @"<?xml version='1.0'?>\r
-<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>\r
- <xsd:attribute name='foo' type='xsd:string'/>\r
- <xsd:attribute name='bar' type='xsd:string'/>\r
- <xsd:complexType name='attRef'>\r
- <xsd:attribute name='att1' type='xsd:int'/>\r
- <xsd:attribute name='att2' type='xsd:string'/>\r
- </xsd:complexType>\r
- <xsd:element name='doc'>\r
- <xsd:complexType>\r
- <xsd:choice>\r
- <xsd:element name='elem' type='attRef'/>\r
- </xsd:choice>\r
- </xsd:complexType>\r
- </xsd:element>\r
-</xsd:schema>";\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (schema));\r
- AssertDataSet ("ds", ds, "doc", 1, 0);\r
- AssertDataTable ("table", ds.Tables [0], "elem", 2, 0, 0, 0, 0, 0);\r
- }\r
-\r
- [Test]\r
- public void UnusedComplexTypesIgnored ()\r
- {\r
- string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>\r
- <xs:element name='Root'>\r
- <xs:complexType>\r
- <xs:sequence>\r
- <xs:element name='Child' type='xs:string' />\r
- </xs:sequence>\r
- </xs:complexType>\r
- </xs:element>\r
- <xs:complexType name='unusedType'>\r
- <xs:sequence>\r
- <xs:element name='Orphan' type='xs:string' />\r
- </xs:sequence>\r
- </xs:complexType>\r
-</xs:schema>";\r
-\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- // Here "unusedType" table is never imported.\r
- AssertDataSet ("ds", ds, "hoge", 1, 0);\r
- AssertDataTable ("dt", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);\r
- }\r
-\r
- [Test]\r
- public void SimpleTypeComponentsIgnored ()\r
- {\r
- string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>\r
- <xs:element name='Root' type='xs:string'/>\r
- <xs:attribute name='Attr' type='xs:string'/>\r
-</xs:schema>";\r
-\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- // nothing is imported.\r
- AssertDataSet ("ds", ds, "NewDataSet", 0, 0);\r
- }\r
-\r
- [Test]\r
- public void IsDataSetAndTypeIgnored ()\r
- {\r
- string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>\r
- <xs:element name='Root' type='unusedType' msdata:IsDataSet='{0}'>\r
- </xs:element>\r
- <xs:complexType name='unusedType'>\r
- <xs:sequence>\r
- <xs:element name='Child' type='xs:string' />\r
- </xs:sequence>\r
- </xs:complexType>\r
-</xs:schema>";\r
-\r
- // Even if a global element uses a complexType, it will be\r
- // ignored if the element has msdata:IsDataSet='true'\r
- string xs = String.Format (xsbase, "true");\r
-\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertDataSet ("ds", ds, "Root", 0, 0); // name is "Root"\r
-\r
- // But when explicit msdata:IsDataSet value is "false", then\r
- // treat as usual.\r
- xs = String.Format (xsbase, "false");\r
-\r
- ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertDataSet ("ds", ds, "NewDataSet", 1, 0);\r
- }\r
-\r
- [Test]\r
- [ExpectedException (typeof (ArgumentException))]\r
- public void NestedReferenceNotAllowed ()\r
- {\r
- string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>\r
- <xs:element name='Root' type='unusedType' msdata:IsDataSet='true'>\r
- </xs:element>\r
- <xs:complexType name='unusedType'>\r
- <xs:sequence>\r
- <xs:element name='Child' type='xs:string' />\r
- </xs:sequence>\r
- </xs:complexType>\r
- <xs:element name='Foo'>\r
- <xs:complexType>\r
- <xs:sequence>\r
- <xs:element ref='Root' />\r
- </xs:sequence>\r
- </xs:complexType>\r
- </xs:element>\r
-</xs:schema>";\r
-\r
- // DataSet element cannot be converted into a DataTable.\r
- // (i.e. cannot be referenced in any other elements)\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- }\r
-\r
- [Test]\r
- public void IsDataSetOnLocalElementIgnored ()\r
- {\r
- string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>\r
- <xs:element name='Root' type='unusedType'>\r
- </xs:element>\r
- <xs:complexType name='unusedType'>\r
- <xs:sequence>\r
- <xs:element name='Child' type='xs:string' msdata:IsDataSet='True' />\r
- </xs:sequence>\r
- </xs:complexType>\r
-</xs:schema>";\r
-\r
- // msdata:IsDataSet does not affect even if the value is invalid\r
- string xs = String.Format (xsbase, "true");\r
-\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- // Child should not be regarded as DataSet element\r
- AssertDataSet ("ds", ds, "NewDataSet", 1, 0);\r
- }\r
-\r
- [Test]\r
- public void LocaleOnRootWithoutIsDataSet ()\r
- {\r
- string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>\r
- <xs:element name='Root' msdata:Locale='ja-JP'>\r
- <xs:complexType>\r
- <xs:sequence>\r
- <xs:element name='Child' type='xs:string' />\r
- </xs:sequence>\r
- <xs:attribute name='Attr' type='xs:integer' />\r
- </xs:complexType>\r
- </xs:element>\r
-</xs:schema>";\r
-\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertDataSet ("ds", ds, "NewDataSet", 1, 0);\r
- AssertEquals ("fi-FI", ds.Locale.Name); // DataSet's Locale comes from current thread\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("dt", dt, "Root", 2, 0, 0, 0, 0, 0);\r
- AssertEquals ("ja-JP", dt.Locale.Name); // DataTable's Locale comes from msdata:Locale\r
- AssertDataColumn ("col1", dt.Columns [0], "Attr", true, false, 0, 1, "Attr", MappingType.Attribute, typeof (Int64), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
- AssertDataColumn ("col2", dt.Columns [1], "Child", false, false, 0, 1, "Child", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);\r
- }\r
-\r
-\r
- [Test]\r
- public void ElementHasIdentityConstraint ()\r
- {\r
- string constraints = @"\r
- <xs:key name='key'>\r
- <xs:selector xpath='./any/string_is_OK/R1'/>\r
- <xs:field xpath='Child2'/>\r
- </xs:key>\r
- <xs:keyref name='kref' refer='key'>\r
- <xs:selector xpath='.//R2'/>\r
- <xs:field xpath='Child2'/>\r
- </xs:keyref>";\r
- string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>\r
- <xs:element name='DS' msdata:IsDataSet='true'>\r
- <xs:complexType>\r
- <xs:choice>\r
- <xs:element ref='R1' />\r
- <xs:element ref='R2' />\r
- </xs:choice>\r
- </xs:complexType>\r
- {0}\r
- </xs:element>\r
- <xs:element name='R1' type='RootType'>\r
- {1}\r
- </xs:element>\r
- <xs:element name='R2' type='RootType'>\r
- </xs:element>\r
- <xs:complexType name='RootType'>\r
- <xs:choice>\r
- <xs:element name='Child1' type='xs:string'>\r
- {2}\r
- </xs:element>\r
- <xs:element name='Child2' type='xs:string' />\r
- </xs:choice>\r
- <xs:attribute name='Attr' type='xs:integer' />\r
- </xs:complexType>\r
-</xs:schema>";\r
-\r
- // Constraints on DataSet element.\r
- // Note that in xs:key xpath is crazy except for the last step\r
- string xs = String.Format (xsbase, constraints, String.Empty, String.Empty);\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertEquals (1, ds.Relations.Count);\r
-\r
- // Constraints on another global element - just ignored\r
- xs = String.Format (xsbase, String.Empty, constraints, String.Empty);\r
- ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertEquals (0, ds.Relations.Count);\r
-\r
- // Constraints on local element - just ignored\r
- xs = String.Format (xsbase, String.Empty, String.Empty, constraints);\r
- ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertEquals (0, ds.Relations.Count);\r
- }\r
-\r
- [Test]\r
- public void PrefixedTargetNS ()\r
- {\r
- string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata' xmlns:x='urn:foo' targetNamespace='urn:foo' elementFormDefault='qualified'>\r
- <xs:element name='DS' msdata:IsDataSet='true'>\r
- <xs:complexType>\r
- <xs:choice>\r
- <xs:element ref='x:R1' />\r
- <xs:element ref='x:R2' />\r
- </xs:choice>\r
- </xs:complexType>\r
- <xs:key name='key'>\r
- <xs:selector xpath='./any/string_is_OK/x:R1'/>\r
- <xs:field xpath='x:Child2'/>\r
- </xs:key>\r
- <xs:keyref name='kref' refer='x:key'>\r
- <xs:selector xpath='.//x:R2'/>\r
- <xs:field xpath='x:Child2'/>\r
- </xs:keyref>\r
- </xs:element>\r
- <xs:element name='R3' type='x:RootType' />\r
- <xs:complexType name='extracted'>\r
- <xs:choice>\r
- <xs:element ref='x:R1' />\r
- <xs:element ref='x:R2' />\r
- </xs:choice>\r
- </xs:complexType>\r
- <xs:element name='R1' type='x:RootType'>\r
- <xs:unique name='Rkey'>\r
- <xs:selector xpath='.//x:Child1'/>\r
- <xs:field xpath='.'/>\r
- </xs:unique>\r
- <xs:keyref name='Rkref' refer='x:Rkey'>\r
- <xs:selector xpath='.//x:Child2'/>\r
- <xs:field xpath='.'/>\r
- </xs:keyref>\r
- </xs:element>\r
- <xs:element name='R2' type='x:RootType'>\r
- </xs:element>\r
- <xs:complexType name='RootType'>\r
- <xs:choice>\r
- <xs:element name='Child1' type='xs:string'>\r
- </xs:element>\r
- <xs:element name='Child2' type='xs:string' />\r
- </xs:choice>\r
- <xs:attribute name='Attr' type='xs:integer' />\r
- </xs:complexType>\r
-</xs:schema>";\r
- // No prefixes on tables and columns\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema (new StringReader (xs));\r
- AssertDataSet ("ds", ds, "DS", 3, 1);\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("R3", dt, "R3", 3, 0, 0, 0, 0, 0);\r
- AssertDataColumn ("col1", dt.Columns [0], "Attr", true, false, 0, 1, "Attr", MappingType.Attribute, typeof (Int64), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
- }\r
-\r
- [Test]\r
- public void ReadTest1 ()\r
- {\r
- DataSet ds = CreateTestSet ();\r
-\r
- StringWriter sw = new StringWriter ();\r
- ds.WriteXmlSchema (sw);\r
-\r
- string schema = sw.ToString ();\r
-\r
- // ReadXmlSchema()\r
- ds = new DataSet ();\r
- ds.ReadXmlSchema (new XmlTextReader (schema, XmlNodeType.Document, null));\r
- ReadTest1Check (ds);\r
-\r
- // ReadXml() should also be the same\r
- ds = new DataSet ();\r
- ds.ReadXml (new XmlTextReader (schema, XmlNodeType.Document, null));\r
- ReadTest1Check (ds);\r
- }\r
-\r
- private void ReadTest1Check (DataSet ds)\r
- {\r
- AssertDataSet ("dataset", ds, "NewDataSet", 2, 1);\r
- AssertDataTable ("tbl1", ds.Tables [0], "Table1", 3, 0, 0, 1, 1, 0);\r
- AssertDataTable ("tbl2", ds.Tables [1], "Table2", 3, 0, 1, 0, 1, 0);\r
-\r
- DataRelation rel = ds.Relations [0];\r
- AssertDataRelation ("rel", rel, "Rel1", false,\r
- new string [] {"Column1_3"},\r
- new string [] {"Column2_1"}, true, true);\r
- AssertUniqueConstraint ("uc", rel.ParentKeyConstraint, \r
- "Constraint1", false, new string [] {"Column1_3"});\r
- AssertForeignKeyConstraint ("fk", rel.ChildKeyConstraint, "Rel1",\r
- AcceptRejectRule.None, Rule.Cascade, Rule.Cascade,\r
- new string [] {"Column2_1"}, \r
- new string [] {"Column1_3"});\r
- }\r
-\r
- [Test]\r
- // 001-004\r
- public void TestSampleFileNoTables ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test001.xsd");\r
- AssertDataSet ("001", ds, "NewDataSet", 0, 0);\r
-\r
- ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test002.xsd");\r
- AssertDataSet ("002", ds, "NewDataSet", 0, 0);\r
-\r
- ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test003.xsd");\r
- AssertDataSet ("003", ds, "NewDataSet", 0, 0);\r
-\r
- ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test004.xsd");\r
- AssertDataSet ("004", ds, "NewDataSet", 0, 0);\r
- }\r
-\r
- [Test]\r
- public void TestSampleFileSimpleTables ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test005.xsd");\r
- AssertDataSet ("005", ds, "NewDataSet", 1, 0);\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("tab", dt, "foo", 2, 0, 0, 0, 0, 0);\r
- AssertDataColumn ("attr", dt.Columns [0], "attr", true, false, 0, 1, "attr", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
- AssertDataColumn ("text", dt.Columns [1], "foo_text", false, false, 0, 1, "foo_text", MappingType.SimpleContent, typeof (long), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);\r
-\r
- ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test006.xsd");\r
- AssertDataSet ("006", ds, "NewDataSet", 1, 0);\r
- dt = ds.Tables [0];\r
- AssertDataTable ("tab", dt, "foo", 2, 0, 0, 0, 0, 0);\r
- AssertDataColumn ("att1", dt.Columns ["att1"], "att1", true, false, 0, 1, "att1", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, /*0*/-1, String.Empty, false, false);\r
- AssertDataColumn ("att2", dt.Columns ["att2"], "att2", true, false, 0, 1, "att2", MappingType.Attribute, typeof (int), 2, String.Empty, -1, String.Empty, /*1*/-1, String.Empty, false, false);\r
- }\r
-\r
- [Test]\r
- public void TestSampleFileComplexTables ()\r
- {\r
- // Nested simple type element\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test007.xsd");\r
- AssertDataSet ("007", ds, "NewDataSet", 2, 1);\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("tab1", dt, "uno", 1, 0, 0, 1, 1, 1);\r
- AssertDataColumn ("id", dt.Columns [0], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "urn:foo", 0, String.Empty, false, true);\r
-\r
- dt = ds.Tables [1];\r
- AssertDataTable ("tab2", dt, "des", 2, 0, 1, 0, 1, 0);\r
- AssertDataColumn ("child", dt.Columns [0], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
- AssertDataColumn ("id", dt.Columns [1], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);\r
-\r
- // External simple type element\r
- ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test008.xsd");\r
- AssertDataSet ("008", ds, "NewDataSet", 2, 1);\r
- dt = ds.Tables [0];\r
- AssertDataTable ("tab1", dt, "uno", 1, 0, 0, 1, 1, 1);\r
- AssertDataColumn ("id", dt.Columns [0], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "urn:foo", 0, String.Empty, false, true);\r
-\r
- dt = ds.Tables [1];\r
- AssertDataTable ("tab2", dt, "des", 2, 0, 1, 0, 1, 0);\r
- AssertDataColumn ("child", dt.Columns [0], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, "urn:foo", 0, String.Empty, false, false);\r
- AssertDataColumn ("id", dt.Columns [1], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);\r
-\r
- }\r
-\r
- [Test]\r
- [Category ("NotDotNet")]\r
- // MS.NET has a bug on handling default value of referenced\r
- // attribute.\r
- public void TestSampleFileValueConstraints ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test009.xsd");\r
- AssertDataSet ("009", ds, "NewDataSet", 2, 1);\r
-\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("tab1", dt, "uno", 2, 0, 0, 1, 1, 1);\r
- AssertDataColumn ("global", dt.Columns [0], "global", true, false, 0, 1, "global", MappingType.Attribute, typeof (string), "er", String.Empty, -1, "urn:foo", 0, String.Empty, false, false);\r
- AssertDataColumn ("id", dt.Columns [1], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "urn:foo", 1, String.Empty, false, true);\r
-\r
- // Here "XmlSchemaComplexType.AttributeUses" does not \r
- // always return attribute uses in a certain order, thus\r
- // here Columns indexer is accessed by name (actually\r
- // MS.NET returns "global" in prior to "local" for\r
- // Columns[0], even though "local" is defined in prior.\r
- dt = ds.Tables [1];\r
- AssertDataTable ("dos", dt, "des", 4, 0, 1, 0, 1, 0);\r
- AssertDataColumn ("dos.child", dt.Columns ["local"], "local", true, false, 0, 1, "local", MappingType.Attribute, typeof (string), "san", String.Empty, -1, String.Empty, /*0*/-1, String.Empty, false, false);\r
- // LAMESPEC: (MS BUG) default value is overwritten, but MS.NET is ignorant of that.\r
-#if BUGGY_MS_COMPATIBLE\r
- AssertDataColumn ("dos.global", dt.Columns ["global"], "global", true, false, 0, 1, "global", MappingType.Attribute, typeof (string), "er", String.Empty, -1, "urn:foo", /*1*/-1, String.Empty, false, false);\r
-#else\r
- AssertDataColumn ("dos.global", dt.Columns ["global"], "global", true, false, 0, 1, "global", MappingType.Attribute, typeof (string), "si", String.Empty, -1, "urn:foo", /*1*/-1, String.Empty, false, false);\r
-#endif\r
- AssertDataColumn ("dos.tres", dt.Columns [2], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof (string), "yi", String.Empty, -1, "urn:foo", 2, String.Empty, false, false);\r
- AssertDataColumn ("uno.id", dt.Columns [3], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 3, String.Empty, false, false);\r
-\r
- AssertDataRelation ("rel", ds.Relations [0], "uno_des", true, new string [] {"uno_Id"}, new string [] {"uno_Id"}, true, true);\r
- }\r
-\r
- [Test]\r
- // FIXME: we can 1) use different schema to import and/or 2)\r
- // fix xml bug(?) thingy.\r
- [Category ("NotWorking")]\r
- public void TestSampleFileImportSimple ()\r
- {\r
- DataSet ds = new DataSet ();\r
+
+
+using System;
+using System.IO;
+using System.Data;
+using System.Globalization;
+using System.Text;
+using System.Threading;
+using System.Xml;
+using NUnit.Framework;
+
+namespace MonoTests.System.Data
+{
+ [TestFixture]
+ public class DataSetReadXmlSchemaTest : DataSetAssertion
+ {
+ private DataSet CreateTestSet ()
+ {
+ DataSet ds = new DataSet ();
+ ds.Tables.Add ("Table1");
+ ds.Tables.Add ("Table2");
+ ds.Tables [0].Columns.Add ("Column1_1");
+ ds.Tables [0].Columns.Add ("Column1_2");
+ ds.Tables [0].Columns.Add ("Column1_3");
+ ds.Tables [1].Columns.Add ("Column2_1");
+ ds.Tables [1].Columns.Add ("Column2_2");
+ ds.Tables [1].Columns.Add ("Column2_3");
+ ds.Tables [0].Rows.Add (new object [] {"ppp", "www", "xxx"});
+ ds.Relations.Add ("Rel1", ds.Tables [0].Columns [2], ds.Tables [1].Columns [0]);
+ return ds;
+ }
+
+ CultureInfo currentCultureBackup;
+
+ [SetUp]
+ public void Setup ()
+ {
+ currentCultureBackup = Thread.CurrentThread.CurrentCulture;
+ Thread.CurrentThread.CurrentCulture = new CultureInfo ("fi-FI");
+ }
+
+ [TearDown]
+ public void Teardown ()
+ {
+ Thread.CurrentThread.CurrentCulture = currentCultureBackup;
+ }
+
+ [Test]
+ public void SingleElementTreatmentDifference ()
+ {
+ // This is one of the most complicated case. When the content
+ // type particle of 'Root' element is a complex element, it
+ // is DataSet element. Otherwise, it is just a data table.
+ //
+ // But also note that there is another test named
+ // LocaleOnRootWithoutIsDataSet(), that tests if locale on
+ // the (mere) data table modifies *DataSet's* locale.
+
+ // Moreover, when the schema contains another element
+ // (regardless of its schema type), the elements will
+ // never be treated as a DataSet.
+ string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
+ <xs:element name='Root'> <!-- When simple, it becomes table. When complex, it becomes DataSet -->
+ <xs:complexType>
+ <xs:choice>
+ {0}
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>";
+
+ string xsbase2 = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
+ <xs:element name='Root'> <!-- When simple, it becomes table. When complex, it becomes DataSet -->
+ <xs:complexType>
+ <xs:choice>
+ {0}
+ </xs:choice>
+ </xs:complexType>
+ </xs:element>
+ <xs:element name='more' type='xs:string' />
+</xs:schema>";
+
+ string simple = "<xs:element name='Child' type='xs:string' />";
+ string complex = @"<xs:element name='Child'>
+ <xs:complexType>
+ <xs:attribute name='a1' />
+ <xs:attribute name='a2' type='xs:integer' />
+ </xs:complexType>
+</xs:element>";
+ string elref = "<xs:element ref='more' />";
+
+ string xs2 = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
+ <xs:element name='Root' type='RootType' />
+ <xs:complexType name='RootType'>
+ <xs:choice>
+ <xs:element name='Child'>
+ <xs:complexType>
+ <xs:attribute name='a1' />
+ <xs:attribute name='a2' type='xs:integer' />
+ </xs:complexType>
+ </xs:element>
+ </xs:choice>
+ </xs:complexType>
+</xs:schema>";
+
+ DataSet ds = new DataSet ();
+
+ string xs = String.Format (xsbase, simple);
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertDataSet ("simple", ds, "hoge", 1, 0);
+ AssertDataTable ("simple", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);
+
+ // reference to global complex type
+ ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs2));
+ AssertDataSet ("external complexType", ds, "hoge", 2, 1);
+ AssertDataTable ("external Tab1", ds.Tables [0], "Root", 1, 0, 0, 1, 1, 1);
+ AssertDataTable ("external Tab2", ds.Tables [1], "Child", 3, 0, 1, 0, 1, 0);
+
+ // xsbase2 + complex -> datatable
+ ds = new DataSet ();
+ xs = String.Format (xsbase2, complex);
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertDataSet ("complex", ds, "hoge", 2, 1);
+ AssertDataTable ("complex", ds.Tables [0], "Root", 1, 0, 0, 1, 1, 1);
+ DataTable dt = ds.Tables [1];
+ AssertDataTable ("complex", dt, "Child", 3, 0, 1, 0, 1, 0);
+ AssertDataColumn ("a1", dt.Columns ["a1"], "a1", true, false, 0, 1, "a1", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, /*0*/-1, String.Empty, false, false);
+ AssertDataColumn ("a2", dt.Columns ["a2"], "a2", true, false, 0, 1, "a2", MappingType.Attribute, typeof (long), DBNull.Value, String.Empty, -1, String.Empty, /*1*/-1, String.Empty, false, false);
+ AssertDataColumn ("Root_Id", dt.Columns [2], "Root_Id", true, false, 0, 1, "Root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 2, String.Empty, false, false);
+
+ // xsbase + complex -> dataset
+ ds = new DataSet ();
+ xs = String.Format (xsbase, complex);
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertDataSet ("complex", ds, "Root", 1, 0);
+
+ ds = new DataSet ();
+ xs = String.Format (xsbase2, elref);
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertDataSet ("complex", ds, "hoge", 1, 0);
+ AssertDataTable ("complex", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);
+ }
+
+ [Test]
+ public void SuspiciousDataSetElement ()
+ {
+ string schema = @"<?xml version='1.0'?>
+<xsd:schema xmlns:xsd='http://www.w3.org/2001/XMLSchema'>
+ <xsd:attribute name='foo' type='xsd:string'/>
+ <xsd:attribute name='bar' type='xsd:string'/>
+ <xsd:complexType name='attRef'>
+ <xsd:attribute name='att1' type='xsd:int'/>
+ <xsd:attribute name='att2' type='xsd:string'/>
+ </xsd:complexType>
+ <xsd:element name='doc'>
+ <xsd:complexType>
+ <xsd:choice>
+ <xsd:element name='elem' type='attRef'/>
+ </xsd:choice>
+ </xsd:complexType>
+ </xsd:element>
+</xsd:schema>";
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (schema));
+ AssertDataSet ("ds", ds, "doc", 1, 0);
+ AssertDataTable ("table", ds.Tables [0], "elem", 2, 0, 0, 0, 0, 0);
+ }
+
+ [Test]
+ public void UnusedComplexTypesIgnored ()
+ {
+ string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' id='hoge'>
+ <xs:element name='Root'>
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name='Child' type='xs:string' />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:complexType name='unusedType'>
+ <xs:sequence>
+ <xs:element name='Orphan' type='xs:string' />
+ </xs:sequence>
+ </xs:complexType>
+</xs:schema>";
+
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ // Here "unusedType" table is never imported.
+ AssertDataSet ("ds", ds, "hoge", 1, 0);
+ AssertDataTable ("dt", ds.Tables [0], "Root", 1, 0, 0, 0, 0, 0);
+ }
+
+ [Test]
+ public void SimpleTypeComponentsIgnored ()
+ {
+ string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema'>
+ <xs:element name='Root' type='xs:string'/>
+ <xs:attribute name='Attr' type='xs:string'/>
+</xs:schema>";
+
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ // nothing is imported.
+ AssertDataSet ("ds", ds, "NewDataSet", 0, 0);
+ }
+
+ [Test]
+ public void IsDataSetAndTypeIgnored ()
+ {
+ string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
+ <xs:element name='Root' type='unusedType' msdata:IsDataSet='{0}'>
+ </xs:element>
+ <xs:complexType name='unusedType'>
+ <xs:sequence>
+ <xs:element name='Child' type='xs:string' />
+ </xs:sequence>
+ </xs:complexType>
+</xs:schema>";
+
+ // Even if a global element uses a complexType, it will be
+ // ignored if the element has msdata:IsDataSet='true'
+ string xs = String.Format (xsbase, "true");
+
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertDataSet ("ds", ds, "Root", 0, 0); // name is "Root"
+
+ // But when explicit msdata:IsDataSet value is "false", then
+ // treat as usual.
+ xs = String.Format (xsbase, "false");
+
+ ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertDataSet ("ds", ds, "NewDataSet", 1, 0);
+ }
+
+ [Test]
+ [ExpectedException (typeof (ArgumentException))]
+ public void NestedReferenceNotAllowed ()
+ {
+ string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
+ <xs:element name='Root' type='unusedType' msdata:IsDataSet='true'>
+ </xs:element>
+ <xs:complexType name='unusedType'>
+ <xs:sequence>
+ <xs:element name='Child' type='xs:string' />
+ </xs:sequence>
+ </xs:complexType>
+ <xs:element name='Foo'>
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element ref='Root' />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+</xs:schema>";
+
+ // DataSet element cannot be converted into a DataTable.
+ // (i.e. cannot be referenced in any other elements)
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ }
+
+ [Test]
+ public void IsDataSetOnLocalElementIgnored ()
+ {
+ string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
+ <xs:element name='Root' type='unusedType'>
+ </xs:element>
+ <xs:complexType name='unusedType'>
+ <xs:sequence>
+ <xs:element name='Child' type='xs:string' msdata:IsDataSet='True' />
+ </xs:sequence>
+ </xs:complexType>
+</xs:schema>";
+
+ // msdata:IsDataSet does not affect even if the value is invalid
+ string xs = String.Format (xsbase, "true");
+
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ // Child should not be regarded as DataSet element
+ AssertDataSet ("ds", ds, "NewDataSet", 1, 0);
+ }
+
+ [Test]
+ public void LocaleOnRootWithoutIsDataSet ()
+ {
+ string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
+ <xs:element name='Root' msdata:Locale='ja-JP'>
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name='Child' type='xs:string' />
+ </xs:sequence>
+ <xs:attribute name='Attr' type='xs:integer' />
+ </xs:complexType>
+ </xs:element>
+</xs:schema>";
+
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertDataSet ("ds", ds, "NewDataSet", 1, 0);
+ AssertEquals ("fi-FI", ds.Locale.Name); // DataSet's Locale comes from current thread
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("dt", dt, "Root", 2, 0, 0, 0, 0, 0);
+ AssertEquals ("ja-JP", dt.Locale.Name); // DataTable's Locale comes from msdata:Locale
+ AssertDataColumn ("col1", dt.Columns [0], "Attr", true, false, 0, 1, "Attr", MappingType.Attribute, typeof (Int64), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+ AssertDataColumn ("col2", dt.Columns [1], "Child", false, false, 0, 1, "Child", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
+ }
+
+
+ [Test]
+ public void ElementHasIdentityConstraint ()
+ {
+ string constraints = @"
+ <xs:key name='key'>
+ <xs:selector xpath='./any/string_is_OK/R1'/>
+ <xs:field xpath='Child2'/>
+ </xs:key>
+ <xs:keyref name='kref' refer='key'>
+ <xs:selector xpath='.//R2'/>
+ <xs:field xpath='Child2'/>
+ </xs:keyref>";
+ string xsbase = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata'>
+ <xs:element name='DS' msdata:IsDataSet='true'>
+ <xs:complexType>
+ <xs:choice>
+ <xs:element ref='R1' />
+ <xs:element ref='R2' />
+ </xs:choice>
+ </xs:complexType>
+ {0}
+ </xs:element>
+ <xs:element name='R1' type='RootType'>
+ {1}
+ </xs:element>
+ <xs:element name='R2' type='RootType'>
+ </xs:element>
+ <xs:complexType name='RootType'>
+ <xs:choice>
+ <xs:element name='Child1' type='xs:string'>
+ {2}
+ </xs:element>
+ <xs:element name='Child2' type='xs:string' />
+ </xs:choice>
+ <xs:attribute name='Attr' type='xs:integer' />
+ </xs:complexType>
+</xs:schema>";
+
+ // Constraints on DataSet element.
+ // Note that in xs:key xpath is crazy except for the last step
+ string xs = String.Format (xsbase, constraints, String.Empty, String.Empty);
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertEquals (1, ds.Relations.Count);
+
+ // Constraints on another global element - just ignored
+ xs = String.Format (xsbase, String.Empty, constraints, String.Empty);
+ ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertEquals (0, ds.Relations.Count);
+
+ // Constraints on local element - just ignored
+ xs = String.Format (xsbase, String.Empty, String.Empty, constraints);
+ ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertEquals (0, ds.Relations.Count);
+ }
+
+ [Test]
+ public void PrefixedTargetNS ()
+ {
+ string xs = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:msdata='urn:schemas-microsoft-com:xml-msdata' xmlns:x='urn:foo' targetNamespace='urn:foo' elementFormDefault='qualified'>
+ <xs:element name='DS' msdata:IsDataSet='true'>
+ <xs:complexType>
+ <xs:choice>
+ <xs:element ref='x:R1' />
+ <xs:element ref='x:R2' />
+ </xs:choice>
+ </xs:complexType>
+ <xs:key name='key'>
+ <xs:selector xpath='./any/string_is_OK/x:R1'/>
+ <xs:field xpath='x:Child2'/>
+ </xs:key>
+ <xs:keyref name='kref' refer='x:key'>
+ <xs:selector xpath='.//x:R2'/>
+ <xs:field xpath='x:Child2'/>
+ </xs:keyref>
+ </xs:element>
+ <xs:element name='R3' type='x:RootType' />
+ <xs:complexType name='extracted'>
+ <xs:choice>
+ <xs:element ref='x:R1' />
+ <xs:element ref='x:R2' />
+ </xs:choice>
+ </xs:complexType>
+ <xs:element name='R1' type='x:RootType'>
+ <xs:unique name='Rkey'>
+ <xs:selector xpath='.//x:Child1'/>
+ <xs:field xpath='.'/>
+ </xs:unique>
+ <xs:keyref name='Rkref' refer='x:Rkey'>
+ <xs:selector xpath='.//x:Child2'/>
+ <xs:field xpath='.'/>
+ </xs:keyref>
+ </xs:element>
+ <xs:element name='R2' type='x:RootType'>
+ </xs:element>
+ <xs:complexType name='RootType'>
+ <xs:choice>
+ <xs:element name='Child1' type='xs:string'>
+ </xs:element>
+ <xs:element name='Child2' type='xs:string' />
+ </xs:choice>
+ <xs:attribute name='Attr' type='xs:integer' />
+ </xs:complexType>
+</xs:schema>";
+ // No prefixes on tables and columns
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema (new StringReader (xs));
+ AssertDataSet ("ds", ds, "DS", 3, 1);
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("R3", dt, "R3", 3, 0, 0, 0, 0, 0);
+ AssertDataColumn ("col1", dt.Columns [0], "Attr", true, false, 0, 1, "Attr", MappingType.Attribute, typeof (Int64), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void ReadTest1 ()
+ {
+ DataSet ds = CreateTestSet ();
+
+ StringWriter sw = new StringWriter ();
+ ds.WriteXmlSchema (sw);
+
+ string schema = sw.ToString ();
+
+ // ReadXmlSchema()
+ ds = new DataSet ();
+ ds.ReadXmlSchema (new XmlTextReader (schema, XmlNodeType.Document, null));
+ ReadTest1Check (ds);
+
+ // ReadXml() should also be the same
+ ds = new DataSet ();
+ ds.ReadXml (new XmlTextReader (schema, XmlNodeType.Document, null));
+ ReadTest1Check (ds);
+ }
+
+ private void ReadTest1Check (DataSet ds)
+ {
+ AssertDataSet ("dataset", ds, "NewDataSet", 2, 1);
+ AssertDataTable ("tbl1", ds.Tables [0], "Table1", 3, 0, 0, 1, 1, 0);
+ AssertDataTable ("tbl2", ds.Tables [1], "Table2", 3, 0, 1, 0, 1, 0);
+
+ DataRelation rel = ds.Relations [0];
+ AssertDataRelation ("rel", rel, "Rel1", false,
+ new string [] {"Column1_3"},
+ new string [] {"Column2_1"}, true, true);
+ AssertUniqueConstraint ("uc", rel.ParentKeyConstraint,
+ "Constraint1", false, new string [] {"Column1_3"});
+ AssertForeignKeyConstraint ("fk", rel.ChildKeyConstraint, "Rel1",
+ AcceptRejectRule.None, Rule.Cascade, Rule.Cascade,
+ new string [] {"Column2_1"},
+ new string [] {"Column1_3"});
+ }
+
+ [Test]
+ // 001-004
+ public void TestSampleFileNoTables ()
+ {
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test001.xsd");
+ AssertDataSet ("001", ds, "NewDataSet", 0, 0);
+
+ ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test002.xsd");
+ AssertDataSet ("002", ds, "NewDataSet", 0, 0);
+
+ ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test003.xsd");
+ AssertDataSet ("003", ds, "NewDataSet", 0, 0);
+
+ ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test004.xsd");
+ AssertDataSet ("004", ds, "NewDataSet", 0, 0);
+ }
+
+ [Test]
+ public void TestSampleFileSimpleTables ()
+ {
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test005.xsd");
+ AssertDataSet ("005", ds, "NewDataSet", 1, 0);
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("tab", dt, "foo", 2, 0, 0, 0, 0, 0);
+ AssertDataColumn ("attr", dt.Columns [0], "attr", true, false, 0, 1, "attr", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+ AssertDataColumn ("text", dt.Columns [1], "foo_text", false, false, 0, 1, "foo_text", MappingType.SimpleContent, typeof (long), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
+
+ ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test006.xsd");
+ AssertDataSet ("006", ds, "NewDataSet", 1, 0);
+ dt = ds.Tables [0];
+ AssertDataTable ("tab", dt, "foo", 2, 0, 0, 0, 0, 0);
+ AssertDataColumn ("att1", dt.Columns ["att1"], "att1", true, false, 0, 1, "att1", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, /*0*/-1, String.Empty, false, false);
+ AssertDataColumn ("att2", dt.Columns ["att2"], "att2", true, false, 0, 1, "att2", MappingType.Attribute, typeof (int), 2, String.Empty, -1, String.Empty, /*1*/-1, String.Empty, false, false);
+ }
+
+ [Test]
+ public void TestSampleFileComplexTables ()
+ {
+ // Nested simple type element
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test007.xsd");
+ AssertDataSet ("007", ds, "NewDataSet", 2, 1);
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("tab1", dt, "uno", 1, 0, 0, 1, 1, 1);
+ AssertDataColumn ("id", dt.Columns [0], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "urn:foo", 0, String.Empty, false, true);
+
+ dt = ds.Tables [1];
+ AssertDataTable ("tab2", dt, "des", 2, 0, 1, 0, 1, 0);
+ AssertDataColumn ("child", dt.Columns [0], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+ AssertDataColumn ("id", dt.Columns [1], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
+
+ // External simple type element
+ ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test008.xsd");
+ AssertDataSet ("008", ds, "NewDataSet", 2, 1);
+ dt = ds.Tables [0];
+ AssertDataTable ("tab1", dt, "uno", 1, 0, 0, 1, 1, 1);
+ AssertDataColumn ("id", dt.Columns [0], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "urn:foo", 0, String.Empty, false, true);
+
+ dt = ds.Tables [1];
+ AssertDataTable ("tab2", dt, "des", 2, 0, 1, 0, 1, 0);
+ AssertDataColumn ("child", dt.Columns [0], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, "urn:foo", 0, String.Empty, false, false);
+ AssertDataColumn ("id", dt.Columns [1], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
+
+ }
+
+ [Test]
+ [Category ("NotDotNet")]
+ // MS.NET has a bug on handling default value of referenced
+ // attribute.
+ public void TestSampleFileValueConstraints ()
+ {
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test009.xsd");
+ AssertDataSet ("009", ds, "NewDataSet", 2, 1);
+
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("tab1", dt, "uno", 2, 0, 0, 1, 1, 1);
+ AssertDataColumn ("global", dt.Columns [0], "global", true, false, 0, 1, "global", MappingType.Attribute, typeof (string), "er", String.Empty, -1, "urn:foo", 0, String.Empty, false, false);
+ AssertDataColumn ("id", dt.Columns [1], "uno_Id", false, true, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "urn:foo", 1, String.Empty, false, true);
+
+ // Here "XmlSchemaComplexType.AttributeUses" does not
+ // always return attribute uses in a certain order, thus
+ // here Columns indexer is accessed by name (actually
+ // MS.NET returns "global" in prior to "local" for
+ // Columns[0], even though "local" is defined in prior.
+ dt = ds.Tables [1];
+ AssertDataTable ("dos", dt, "des", 4, 0, 1, 0, 1, 0);
+ AssertDataColumn ("dos.child", dt.Columns ["local"], "local", true, false, 0, 1, "local", MappingType.Attribute, typeof (string), "san", String.Empty, -1, String.Empty, /*0*/-1, String.Empty, false, false);
+ // LAMESPEC: (MS BUG) default value is overwritten, but MS.NET is ignorant of that.
+#if BUGGY_MS_COMPATIBLE
+ AssertDataColumn ("dos.global", dt.Columns ["global"], "global", true, false, 0, 1, "global", MappingType.Attribute, typeof (string), "er", String.Empty, -1, "urn:foo", /*1*/-1, String.Empty, false, false);
+#else
+ AssertDataColumn ("dos.global", dt.Columns ["global"], "global", true, false, 0, 1, "global", MappingType.Attribute, typeof (string), "si", String.Empty, -1, "urn:foo", /*1*/-1, String.Empty, false, false);
+#endif
+ AssertDataColumn ("dos.tres", dt.Columns [2], "tres", false, false, 0, 1, "tres", MappingType.Element, typeof (string), "yi", String.Empty, -1, "urn:foo", 2, String.Empty, false, false);
+ AssertDataColumn ("uno.id", dt.Columns [3], "uno_Id", true, false, 0, 1, "uno_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 3, String.Empty, false, false);
+
+ AssertDataRelation ("rel", ds.Relations [0], "uno_des", true, new string [] {"uno_Id"}, new string [] {"uno_Id"}, true, true);
+ }
+
+ [Test]
+ // FIXME: we can 1) use different schema to import and/or 2)
+ // fix xml bug(?) thingy.
+ [Category ("NotWorking")]
+ public void TestSampleFileImportSimple ()
+ {
+ DataSet ds = new DataSet ();
XmlTextReader xtr = null;
try {
xtr = new XmlTextReader ("Test/System.Data/schemas/test010.xsd");
xtr.XmlResolver = null;
- ds.ReadXmlSchema (xtr);\r
+ ds.ReadXmlSchema (xtr);
} finally {
if (xtr != null)
xtr.Close ();
}
- AssertDataSet ("010", ds, "NewDataSet", 1, 0);\r
-\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("root", dt, "foo", 1, 0, 0, 0, 0, 0);\r
- AssertDataColumn ("simple", dt.Columns [0], "bar", false, false, 0, 1, "bar", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
- }\r
-\r
- [Test]\r
- public void TestSampleFileComplexTables2 ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test011.xsd");\r
- AssertDataSet ("011", ds, "NewDataSet", 2, 1);\r
-\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("root", dt, "e", 3, 0, 1, 0, 1, 0);\r
- AssertDataColumn ("attr", dt.Columns [0], "a", true, false, 0, 1, "a", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, "http://xsdtesting", 0, String.Empty, false, false);\r
- AssertDataColumn ("simple", dt.Columns [1], "e_text", false, false, 0, 1, "e_text", MappingType.SimpleContent, typeof (decimal), DBNull.Value, String.Empty, -1, "http://xsdtesting", 1, String.Empty, false, false);\r
- AssertDataColumn ("hidden", dt.Columns [2], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "http://xsdtesting", 2, String.Empty, false, false);\r
-\r
- dt = ds.Tables [1];\r
- AssertDataTable ("root", dt, "root", 1, 0, 0, 1, 1, 1);\r
- AssertDataColumn ("elem", dt.Columns [0], "root_Id", false, true, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "http://xsdtesting", 0, String.Empty, false, true);\r
-\r
- AssertDataRelation ("rel", ds.Relations [0], "root_e", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);\r
- }\r
-\r
- [Test]\r
- public void TestSampleFileComplexTables3 ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test013.xsd");\r
- AssertDataSet ("013", ds, "root", 1, 0);\r
-\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("root", dt, "e", 2, 0, 0, 0, 0, 0);\r
- AssertDataColumn ("attr", dt.Columns [0], "a", true, false, 0, 1, "a", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
- AssertDataColumn ("simple", dt.Columns [1], "e_text", false, false, 0, 1, "e_text", MappingType.SimpleContent, typeof (decimal), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);\r
- }\r
-\r
- // bug #58744\r
- [Test]\r
- public void TestSampleFileXPath ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test103.xsd");\r
- }\r
-\r
- [Test]\r
- public void TestAnnotatedRelation1 ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test101.xsd");\r
- AssertDataSet ("101", ds, "root", 2, 1);\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("parent_table", dt, "p", 2, 0, 0, 1, 0, 0);\r
- AssertDataColumn ("pk", dt.Columns [0], "pk", false, false, 0, 1, "pk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
-\r
- dt = ds.Tables [1];\r
- AssertDataTable ("child_table", dt, "c", 2, 0, 1, 0, 0, 0);\r
- AssertDataColumn ("fk", dt.Columns [0], "fk", false, false, 0, 1, "fk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
-\r
- AssertDataRelation ("rel", ds.Relations [0], "rel", false, new string [] {"pk"}, new string [] {"fk"}, false, false);\r
- }\r
-\r
- [Test]\r
- public void TestAnnotatedRelation2 ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test102.xsd");\r
- AssertDataSet ("102", ds, "ds", 2, 1);\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("parent_table", dt, "p", 2, 0, 0, 1, 0, 0);\r
- AssertDataColumn ("pk", dt.Columns [0], "pk", false, false, 0, 1, "pk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
-\r
- dt = ds.Tables [1];\r
- AssertDataTable ("child_table", dt, "c", 2, 0, 1, 0, 0, 0);\r
- AssertDataColumn ("fk", dt.Columns [0], "fk", false, false, 0, 1, "fk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
-\r
- AssertDataRelation ("rel", ds.Relations [0], "rel", true, new string [] {"pk"}, new string [] {"fk"}, false, false);\r
- }\r
-\r
- [Test]\r
- public void RepeatableSimpleElement ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test012.xsd");\r
- AssertDataSet ("012", ds, "NewDataSet", 2, 1);\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("parent", dt, "Foo", 1, 0, 0, 1, 1, 1);\r
- AssertDataColumn ("key", dt.Columns [0], "Foo_Id", false, true, 0, 1, "Foo_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, true);\r
-\r
- dt = ds.Tables [1];\r
- AssertDataTable ("repeated", dt, "Bar", 2, 0, 1, 0, 1, 0);\r
- AssertDataColumn ("data", dt.Columns [0], "Bar_Column", false, false, 0, 1, "Bar_Column", MappingType.SimpleContent, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
- AssertDataColumn ("refkey", dt.Columns [1], "Foo_Id", true, false, 0, 1, "Foo_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);\r
-\r
- AssertDataRelation ("rel", ds.Relations [0], "Foo_Bar", true, new string [] {"Foo_Id"}, new string [] {"Foo_Id"}, true, true);\r
- }\r
-\r
- [Test]\r
- public void TestMoreThanOneRepeatableColumns ()\r
- {\r
- DataSet ds = new DataSet ();\r
- ds.ReadXmlSchema ("Test/System.Data/schemas/test014.xsd");\r
- AssertDataSet ("014", ds, "NewDataSet", 3, 2);\r
-\r
- DataTable dt = ds.Tables [0];\r
- AssertDataTable ("parent", dt, "root", 1, 0, 0, 2, 1, 1);\r
- AssertDataColumn ("key", dt.Columns [0], "root_Id", false, true, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, true);\r
-\r
- dt = ds.Tables [1];\r
- AssertDataTable ("repeated", dt, "x", 2, 0, 1, 0, 1, 0);\r
- AssertDataColumn ("data_1", dt.Columns [0], "x_Column", false, false, 0, 1, "x_Column", MappingType.SimpleContent, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
- AssertDataColumn ("refkey_1", dt.Columns [1], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);\r
-\r
- dt = ds.Tables [2];\r
- AssertDataTable ("repeated", dt, "y", 2, 0, 1, 0, 1, 0);\r
- AssertDataColumn ("data", dt.Columns [0], "y_Column", false, false, 0, 1, "y_Column", MappingType.SimpleContent, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);\r
- AssertDataColumn ("refkey", dt.Columns [1], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);\r
-\r
- AssertDataRelation ("rel", ds.Relations [0], "root_x", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);\r
-\r
- AssertDataRelation ("rel", ds.Relations [1], "root_y", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);\r
- }\r
-\r
- [Test]\r
- public void AutoIncrementStep ()\r
- {\r
- DataSet ds = new DataSet("testds");\r
- DataTable tbl = ds.Tables.Add("testtbl");\r
- DataColumn col = tbl.Columns.Add("id", typeof(int));\r
- col.AutoIncrement = true;\r
- col.AutoIncrementSeed = -1;\r
- col.AutoIncrementStep = -1;\r
- tbl.Columns.Add("data", typeof(string));\r
- Assert (ds.GetXmlSchema ().IndexOf ("AutoIncrementStep") > 0);\r
- }\r
- }\r
-}\r
+ AssertDataSet ("010", ds, "NewDataSet", 1, 0);
+
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("root", dt, "foo", 1, 0, 0, 0, 0, 0);
+ AssertDataColumn ("simple", dt.Columns [0], "bar", false, false, 0, 1, "bar", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+ }
+
+ [Test]
+ [Category ("NotWorking")]
+ public void TestSampleFileComplexTables2 ()
+ {
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test011.xsd");
+ AssertDataSet ("011", ds, "NewDataSet", 2, 1);
+
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("root", dt, "e", 3, 0, 1, 0, 1, 0);
+ AssertDataColumn ("attr", dt.Columns [0], "a", true, false, 0, 1, "a", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, "http://xsdtesting", 0, String.Empty, false, false);
+ AssertDataColumn ("simple", dt.Columns [1], "e_text", false, false, 0, 1, "e_text", MappingType.SimpleContent, typeof (decimal), DBNull.Value, String.Empty, -1, "http://xsdtesting", 1, String.Empty, false, false);
+ AssertDataColumn ("hidden", dt.Columns [2], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "http://xsdtesting", 2, String.Empty, false, false);
+
+ dt = ds.Tables [1];
+ AssertDataTable ("root", dt, "root", 1, 0, 0, 1, 1, 1);
+ AssertDataColumn ("elem", dt.Columns [0], "root_Id", false, true, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, "http://xsdtesting", 0, String.Empty, false, true);
+
+ AssertDataRelation ("rel", ds.Relations [0], "root_e", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
+ }
+
+ [Test]
+ public void TestSampleFileComplexTables3 ()
+ {
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test013.xsd");
+ AssertDataSet ("013", ds, "root", 1, 0);
+
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("root", dt, "e", 2, 0, 0, 0, 0, 0);
+ AssertDataColumn ("attr", dt.Columns [0], "a", true, false, 0, 1, "a", MappingType.Attribute, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+ AssertDataColumn ("simple", dt.Columns [1], "e_text", false, false, 0, 1, "e_text", MappingType.SimpleContent, typeof (decimal), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
+ }
+
+ // bug #58744
+ [Test]
+ public void TestSampleFileXPath ()
+ {
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test103.xsd");
+ }
+
+ [Test]
+ public void TestAnnotatedRelation1 ()
+ {
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test101.xsd");
+ AssertDataSet ("101", ds, "root", 2, 1);
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("parent_table", dt, "p", 2, 0, 0, 1, 0, 0);
+ AssertDataColumn ("pk", dt.Columns [0], "pk", false, false, 0, 1, "pk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+
+ dt = ds.Tables [1];
+ AssertDataTable ("child_table", dt, "c", 2, 0, 1, 0, 0, 0);
+ AssertDataColumn ("fk", dt.Columns [0], "fk", false, false, 0, 1, "fk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+
+ AssertDataRelation ("rel", ds.Relations [0], "rel", false, new string [] {"pk"}, new string [] {"fk"}, false, false);
+ }
+
+ [Test]
+ public void TestAnnotatedRelation2 ()
+ {
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test102.xsd");
+ AssertDataSet ("102", ds, "ds", 2, 1);
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("parent_table", dt, "p", 2, 0, 0, 1, 0, 0);
+ AssertDataColumn ("pk", dt.Columns [0], "pk", false, false, 0, 1, "pk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+
+ dt = ds.Tables [1];
+ AssertDataTable ("child_table", dt, "c", 2, 0, 1, 0, 0, 0);
+ AssertDataColumn ("fk", dt.Columns [0], "fk", false, false, 0, 1, "fk", MappingType.Element, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+
+ AssertDataRelation ("rel", ds.Relations [0], "rel", true, new string [] {"pk"}, new string [] {"fk"}, false, false);
+ }
+
+ [Test]
+ public void RepeatableSimpleElement ()
+ {
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test012.xsd");
+ AssertDataSet ("012", ds, "NewDataSet", 2, 1);
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("parent", dt, "Foo", 1, 0, 0, 1, 1, 1);
+ AssertDataColumn ("key", dt.Columns [0], "Foo_Id", false, true, 0, 1, "Foo_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, true);
+
+ dt = ds.Tables [1];
+ AssertDataTable ("repeated", dt, "Bar", 2, 0, 1, 0, 1, 0);
+ AssertDataColumn ("data", dt.Columns [0], "Bar_Column", false, false, 0, 1, "Bar_Column", MappingType.SimpleContent, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+ AssertDataColumn ("refkey", dt.Columns [1], "Foo_Id", true, false, 0, 1, "Foo_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
+
+ AssertDataRelation ("rel", ds.Relations [0], "Foo_Bar", true, new string [] {"Foo_Id"}, new string [] {"Foo_Id"}, true, true);
+ }
+
+ [Test]
+ public void TestMoreThanOneRepeatableColumns ()
+ {
+ DataSet ds = new DataSet ();
+ ds.ReadXmlSchema ("Test/System.Data/schemas/test014.xsd");
+ AssertDataSet ("014", ds, "NewDataSet", 3, 2);
+
+ DataTable dt = ds.Tables [0];
+ AssertDataTable ("parent", dt, "root", 1, 0, 0, 2, 1, 1);
+ AssertDataColumn ("key", dt.Columns [0], "root_Id", false, true, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, true);
+
+ dt = ds.Tables [1];
+ AssertDataTable ("repeated", dt, "x", 2, 0, 1, 0, 1, 0);
+ AssertDataColumn ("data_1", dt.Columns [0], "x_Column", false, false, 0, 1, "x_Column", MappingType.SimpleContent, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+ AssertDataColumn ("refkey_1", dt.Columns [1], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
+
+ dt = ds.Tables [2];
+ AssertDataTable ("repeated", dt, "y", 2, 0, 1, 0, 1, 0);
+ AssertDataColumn ("data", dt.Columns [0], "y_Column", false, false, 0, 1, "y_Column", MappingType.SimpleContent, typeof (string), DBNull.Value, String.Empty, -1, String.Empty, 0, String.Empty, false, false);
+ AssertDataColumn ("refkey", dt.Columns [1], "root_Id", true, false, 0, 1, "root_Id", MappingType.Hidden, typeof (int), DBNull.Value, String.Empty, -1, String.Empty, 1, String.Empty, false, false);
+
+ AssertDataRelation ("rel", ds.Relations [0], "root_x", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
+
+ AssertDataRelation ("rel", ds.Relations [1], "root_y", true, new string [] {"root_Id"}, new string [] {"root_Id"}, true, true);
+ }
+
+ [Test]
+ public void AutoIncrementStep ()
+ {
+ DataSet ds = new DataSet("testds");
+ DataTable tbl = ds.Tables.Add("testtbl");
+ DataColumn col = tbl.Columns.Add("id", typeof(int));
+ col.AutoIncrement = true;
+ col.AutoIncrementSeed = -1;
+ col.AutoIncrementStep = -1;
+ tbl.Columns.Add("data", typeof(string));
+ Assert (ds.GetXmlSchema ().IndexOf ("AutoIncrementStep") > 0);
+ }
+ }
+}