SqlCommand_ExecuteXmlReader_.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using System.Xml;
  5. using System.Text;
  6. using System.IO;
  7. using MonoTests.System.Data.Utils;
  8. using NUnit.Framework;
  9. namespace MonoTests.System.Data.SqlClient
  10. {
  11. [TestFixture]
  12. public class SqlCommand_ExecuteXmlReader_ : ADONetTesterClass
  13. {
  14. public static void Main()
  15. {
  16. SqlCommand_ExecuteXmlReader_ tc = new SqlCommand_ExecuteXmlReader_();
  17. Exception exp = null;
  18. try
  19. {
  20. // Every Test must begin with BeginTest
  21. tc.BeginTest("SqlCommand_ExecuteXmlReader");
  22. //testing only on SQLServer
  23. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer) return ;
  24. tc.run();
  25. }
  26. catch(Exception ex)
  27. {
  28. exp = ex;
  29. }
  30. finally
  31. {
  32. // Every Test must End with EndTest
  33. tc.EndTest(exp);
  34. }
  35. }
  36. [Test]
  37. [Category("NotWorking")]
  38. public void run()
  39. {
  40. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer) {
  41. //All tests in this class are only for MSSQLServer.
  42. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  43. return;
  44. }
  45. Exception exp = null;
  46. // Start Sub Test
  47. try
  48. {
  49. // Every Sub Test must begin with BeginCase
  50. BeginCase("ExecuteXmlReader 1");
  51. SqlConnection con = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  52. con.Open();
  53. string selectStr = "SELECT * FROM Products WHERE PRODUCTID=1 FOR XML AUTO, XMLDATA;" +
  54. "SELECT * FROM Orders WHERE ORDERID=1 FOR XML AUTO, XMLDATA;" +
  55. "SELECT * FROM Customers WHERE CustomerID like 'A%' FOR XML AUTO, XMLDATA";
  56. SqlCommand comm = new SqlCommand(selectStr,con);
  57. // ExecuteXmlReader is not supported yet
  58. XmlReader xr = null; // = comm.ExecuteXmlReader();
  59. StringBuilder sb = new StringBuilder();
  60. while(xr.Read())
  61. {
  62. sb.Append(xr.ReadOuterXml());
  63. }
  64. // Every Sub Test must have a Compare
  65. string strXml = null;
  66. Compare(sb.ToString().Length,4391);
  67. }
  68. catch(Exception ex)
  69. {
  70. exp = ex;
  71. }
  72. finally
  73. {
  74. // Every Sub Test must end with EndCase
  75. EndCase(exp);
  76. exp = null;
  77. }
  78. // End Sub Test
  79. }
  80. }
  81. }