SqlCommand_ExecuteXmlReader_.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. public void run()
  38. {
  39. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer) {
  40. //All tests in this class are only for MSSQLServer.
  41. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  42. return;
  43. }
  44. Exception exp = null;
  45. // Start Sub Test
  46. try
  47. {
  48. // Every Sub Test must begin with BeginCase
  49. BeginCase("ExecuteXmlReader 1");
  50. SqlConnection con = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  51. con.Open();
  52. string selectStr = "SELECT * FROM Products WHERE PRODUCTID=1 FOR XML AUTO, XMLDATA;" +
  53. "SELECT * FROM Orders WHERE ORDERID=1 FOR XML AUTO, XMLDATA;" +
  54. "SELECT * FROM Customers WHERE CustomerID like 'A%' FOR XML AUTO, XMLDATA";
  55. SqlCommand comm = new SqlCommand(selectStr,con);
  56. // ExecuteXmlReader is not supported yet
  57. XmlReader xr = comm.ExecuteXmlReader();
  58. StringBuilder sb = new StringBuilder();
  59. while(xr.Read())
  60. {
  61. sb.Append(xr.ReadOuterXml());
  62. }
  63. // Every Sub Test must have a Compare
  64. string strXml = null;
  65. Compare(sb.ToString().Length,4391);
  66. }
  67. catch(Exception ex)
  68. {
  69. exp = ex;
  70. }
  71. finally
  72. {
  73. // Every Sub Test must end with EndCase
  74. EndCase(exp);
  75. exp = null;
  76. }
  77. // End Sub Test
  78. }
  79. }
  80. }