SqlCommandBuilder_DeriveParameters_S.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 (con == null)
  37. {
  38. con = new SqlConnection(ConnectedDataProvider.ConnectionStringSQLClient);
  39. con.Open();
  40. }
  41. }
  42. [TearDown]
  43. public void tearDown()
  44. {
  45. if (con.State == ConnectionState.Open)
  46. {
  47. con.Close();
  48. }
  49. }
  50. public void run()
  51. {
  52. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer)
  53. {
  54. //All tests in this class are only for MSSQLServer.
  55. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  56. return;
  57. }
  58. setUp();
  59. test();
  60. tearDown();
  61. }
  62. [Test]
  63. public void test()
  64. {
  65. if (ConnectedDataProvider.GetDbType() != DataBaseServer.SQLServer)
  66. {
  67. //All tests in this class are only for MSSQLServer.
  68. Log(string.Format("All tests in this class are only for MSSQLServer and cannot be tested on {0}", ConnectedDataProvider.GetDbType()));
  69. return;
  70. }
  71. Exception exp = null;
  72. BeginCase("Checking with sp that doesn't exsits ");
  73. try
  74. {
  75. cmd = new SqlCommand("NotExists",con);
  76. cmd.CommandType = CommandType.StoredProcedure;
  77. SqlCommandBuilder.DeriveParameters(cmd);
  78. }
  79. catch(InvalidOperationException ex)
  80. {
  81. ExpectedExceptionCaught(ex);
  82. exp = ex;
  83. }
  84. finally
  85. {
  86. if (exp == null)
  87. {
  88. ExpectedExceptionNotCaught("InvalidOperationException");
  89. }
  90. EndCase(null);
  91. exp = null;
  92. }
  93. }
  94. //Activate This Construntor to log All To Standard output
  95. //public TestClass():base(true){}
  96. //Activate this constructor to log Failures to a log file
  97. //public TestClass(System.IO.TextWriter tw):base(tw, false){}
  98. //Activate this constructor to log All to a log file
  99. //public TestClass(System.IO.TextWriter tw):base(tw, true){}
  100. //BY DEFAULT LOGGING IS DONE TO THE STANDARD OUTPUT ONLY FOR FAILURES
  101. }
  102. }