rendered paste body [Test]
//[Category ("NotWorking")]
// WriteXmlSchema doesn't have overload wityh 2 parameters in System.Data
// and is commented-out TWICE below
public void ReadWriteXmlSchema () {
DataSet ds = new DataSet ();
ds.ReadXmlSchema ("Test/System.Data/store.xsd");
// check dataset properties before testing write
AssertDataSet ("ds", ds, "NewDataSet", 3, 2);
AssertDataTable ("tab1", ds.Tables[0], "bookstore", 1, 0, 0, 1, 1, 1);
AssertDataTable ("tab2", ds.Tables[1], "book", 5, 0, 1, 1, 2, 1);
AssertDataTable ("tab3", ds.Tables[2], "author", 3, 0, 1, 0, 1, 0);
// FIXME: currently order is not compatible. Use name as index
AssertDataRelation ("rel1", ds.Relations["book_author"], "book_author", true, new string[] { "book_Id" }, new string[] { "book_Id" }, true, true);
AssertDataRelation ("rel2", ds.Relations["bookstore_book"], "bookstore_book", true, new string[] { "bookstore_Id" }, new string[] { "bookstore_Id" }, true, true);
ds.ReadXml ("Test/System.Data/region.xml", XmlReadMode.InferSchema);
ds.Relations.Clear (); // because can not call WriteXmlSchema with nested relations.
TextWriter writer1 = new StringWriter ();
ds.Tables[0].WriteXmlSchema (writer1);
string TextString1 = GetNormalizedSchema (writer1.ToString ());
string expected1 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
@"<xs:schema id=""NewDataSet"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
@"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""bookstore"" msdata:UseCurrentLocale=""true"" name=""NewDataSet"">" +
@"<xs:complexType>" +
@"<xs:element name=""bookstore"" type=""bookstoreType"" />" +
@"<xs:complexType>" +
@"<xs:choice minOccurs=""0"" maxOccurs=""unbounded"" minOccurs=""0"">" +
@"<xs:element ref=""bookstore"" />" +
@"</xs:choice>" +
@"</xs:complexType>" +
@"</xs:element>" +
@"</xs:schema>";
AssertEquals ("#1", expected1.Replace ("\n", ""), TextString1.Replace("\r\n","").Replace(" ","").Replace ("\n", ""));
TextWriter writer2 = new StringWriter ();
ds.Tables[1].WriteXmlSchema (writer2,false);
string TextString2 = GetNormalizedSchema (writer2.ToString ());
string expected2 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
@"<xs:schema id=""Root"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
@"<xs:complexType name=""bookType"">" +
@"<xs:sequence>" +
@"<xs:element msdata:Ordinal=""1"" name=""title"" type=""xs:string"" />" +
@"<xs:element msdata:Ordinal=""2"" name=""price"" type=""xs:decimal"" />" +
@"</xs:sequence>" +
@"<xs:attribute name=""genre"" type=""xs:string"" />" +
@"<xs:attribute name=""bookstore_Id"" type=""xs:int"" use=""prohibited"" />" +
@"</xs:complexType>" +
@"<xs:element name=""book"" type=""bookType"" />" +
@"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""book"" msdata:UseCurrentLocale=""true"" name=""Root"">" +
@"<xs:complexType>" +
@"<xs:choice minOccurs=""0"" maxOccurs=""unbounded"" minOccurs=""0"">" +
@"<xs:element ref=""book"" />" +
@"</xs:choice>" +
@"</xs:complexType>" +
@"</xs:element>" +
@"</xs:schema>";
AssertEquals ("#2", expected2, TextString2.Replace ("\r\n", "").Replace (" ", ""));
TextWriter writer3 = new StringWriter ();
ds.Tables[2].WriteXmlSchema (writer3);
string TextString3 = GetNormalizedSchema (writer3.ToString ());
string expected3 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
@"<xs:schema id=""Root"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
@"<xs:complexType name=""authorName"">" +
@"<xs:sequence>" +
@"<xs:element msdata:Ordinal=""0"" name=""first-name"" type=""xs:string"" />" +
@"<xs:element msdata:Ordinal=""1"" name=""last-name"" type=""xs:string"" />" +
@"</xs:sequence>" +
@"<xs:attribute name=""book_Id"" type=""xs:int"" use=""prohibited"" />" +
@"</xs:complexType>" +
@"<xs:element name=""author"" type=""authorName"" />" +
@"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""author"" msdata:UseCurrentLocale=""true"" name=""Root"">" +
@"<xs:complexType>" +
@"<xs:choice minOccurs=""0"" maxOccurs=""unbounded"" minOccurs=""0"">" +
@"<xs:element ref=""author"" />" +
@"</xs:choice>" +
@"</xs:complexType>" +
@"</xs:element>" +
@"</xs:schema>";
AssertEquals ("#3", expected3, TextString3.Replace ("\r\n", "").Replace (" ", ""));
TextWriter writer4 = new StringWriter ();
ds.Tables[3].WriteXmlSchema (writer4);
string TextString4 = GetNormalizedSchema (writer4.ToString ());
string expected4 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
@"<xs:schema id=""Root"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"" xmlns:xs=""http://www.w3.org/2001/XMLSchema"">" +
@"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""Region"" msdata:UseCurrentLocale=""true"" name=""Root"">" +
@"<xs:complexType>" +
@"<xs:choice minOccurs=""0"" maxOccurs=""unbounded"" minOccurs=""0"">" +
@"<xs:element name=""Region"">" +
@"<xs:complexType>" +
@"<xs:sequence>" +
@"<xs:element minOccurs=""0"" name=""RegionID"" type=""xs:string"" />" +
@"<xs:element minOccurs=""0"" name=""RegionDescription"" type=""xs:string"" />" +
@"</xs:sequence>" +
@"</xs:complexType>" +
@"</xs:element>" +
@"</xs:choice>" +
@"</xs:complexType>" +
@"</xs:element>" +
@"</xs:schema>";
AssertEquals ("#4", expected4, TextString4.Replace ("\r\n", "").Replace (" ", ""));
}