SqlCommandBuilder_DeriveParameters_S.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. using MonoTests.System.Data.Utils;
  5. using NUnit.Framework;
  6. namespace MonoTests.System.Data.SqlClient
  7. {
  8. [TestFixture]
  9. public class SqlCommandBuilder_DeriveParameters_S : GHTBase
  10. {
  11. SqlConnection con;
  12. SqlCommand cmd;
  13. public static void Main()
  14. {
  15. SqlCommandBuilder_DeriveParameters_S tc = new SqlCommandBuilder_DeriveParameters_S();
  16. Exception exp = null;
  17. try
  18. {
  19. // Every Test must begin with BeginTest
  20. tc.BeginTest("DeriveParameters");
  21. tc.run();
  22. }
  23. catch(Exception ex)
  24. {
  25. exp=ex;
  26. }
  27. finally
  28. {
  29. // Every Test must End with EndTest
  30. tc.EndTest(exp);
  31. }
  32. }
  33. [SetUp]
  34. public void setUp()
  35. {
  36. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer) {
  37. //All tests in this class are only for MSSQLServer.
  38. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  39. return;
  40. }
  41. if (con == null)
  42. {
  43. con = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  44. con.Open();
  45. }
  46. }
  47. [TearDown]
  48. public void tearDown()
  49. {
  50. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer) {
  51. //All tests in this class are only for MSSQLServer.
  52. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  53. return;
  54. }
  55. if (con.State == ConnectionState.Open)
  56. {
  57. con.Close();
  58. }
  59. }
  60. public void run()
  61. {
  62. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer)
  63. {
  64. //All tests in this class are only for MSSQLServer.
  65. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  66. return;
  67. }
  68. setUp();
  69. test();
  70. tearDown();
  71. }
  72. [Test]
  73. public void test()
  74. {
  75. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer)
  76. {
  77. //All tests in this class are only for MSSQLServer.
  78. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  79. return;
  80. }
  81. Exception exp = null;
  82. BeginCase("Checking with sp that doesn't exsits ");
  83. try
  84. {
  85. cmd = new SqlCommand("NotExists",con);
  86. cmd.CommandType = CommandType.StoredProcedure;
  87. SqlCommandBuilder.DeriveParameters(cmd);
  88. }
  89. catch(InvalidOperationException ex)
  90. {
  91. ExpectedExceptionCaught(ex);
  92. exp = ex;
  93. }
  94. finally
  95. {
  96. if (exp == null)
  97. {
  98. ExpectedExceptionNotCaught("InvalidOperationException");
  99. }
  100. EndCase(null);
  101. exp = null;
  102. }
  103. }
  104. //Activate This Construntor to log All To Standard output
  105. //public TestClass():base(true){}
  106. //Activate this constructor to log Failures to a log file
  107. //public TestClass(System.IO.TextWriter tw):base(tw, false){}
  108. //Activate this constructor to log All to a log file
  109. //public TestClass(System.IO.TextWriter tw):base(tw, true){}
  110. //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
  111. }
  112. }