rendered paste body [Test]
//[Category ("NotWorking")]
public void ReadWriteXmlSchema_IgnoreSchema () {
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.IgnoreSchema);
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 TextString1 = writer1.ToString ();
string expected1 = @"<?xml version=""1.0"" encoding=""utf-16""?>" +
@"<xs:schema id=""NewDataSet"" xmlns="""" xmlns:xs=""http://www.w3.org/2001/XMLSchema"" xmlns:msdata=""urn:schemas-microsoft-com:xml-msdata"">" +
@"<xs:complexType name=""bookstoreType"">" +
@"</xs:complexType>" +
@"<xs:element name=""bookstore"" type=""bookstoreType"" />" +
@"<xs:element msdata:IsDataSet=""true"" msdata:MainDataTable=""bookstore"" msdata:UseCurrentLocale=""true"" name=""NewDataSet"">" +
@"<xs:complexType>" +
@"<xs:choice minOccurs=""0"" maxOccurs=""unbounded"" minOccurs=""0"">" +
@"<xs:element ref=""bookstore"" />" +
@"</xs:choice>" +
@"</xs:complexType>" +
@"</xs:element>" +
@"</xs:schema>";
Console.WriteLine ("{0} - {1}", TextString1, expected1);
AssertEquals ("#1", expected1, 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=""NewDataSet"" 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=""NewDataSet"">" +
@"<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=""NewDataSet"" 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=""NewDataSet"">" +
@"<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 ();
string expStr = "";
try {
ds.Tables[3].WriteXmlSchema (writer4);
}
catch (Exception ex) {
expStr = ex.Message;
}
AssertEquals ("#4", "Cannot find table 3.", expStr);
}