Guys,

 

I'm not sure if I'm going about this the right way, but I found myself
testing complex processing stored procedures in SQL and I had a need for
an AssertExecuteScalar.

 

So I wrote one ... ish.

 

What are your thoughts?

 

    [Test()]

    public void Import()

    {

 

      string SQL = (@"INSERT INTO TestingTable

SELECT *

FROM SampleData");

      ExecuteSQL(SQL);

 

      SQL = ("EXEC ComplexSQL");

      ExecuteSQL(SQL);

 

      SQL = ("SELECT Count(*) From OtherTestingTable");

      int Count = Convert.ToInt32(ExecuteScalar(SQL));

 

      AssertScalar(SQL, 3);

 

    }

 

    private void AssertScalar(string SQL, object ExpectedValue)

    {

      object o = ExecuteScalar(SQL);

      Assert.AreEqual(ExpectedValue, o);

    }

 

    private object ExecuteScalar(string SQL)

    {

      using (SqlConnection Conn = new SqlConnection(_ConnectionString))

      using (SqlCommand Comm = new SqlCommand(SQL, Conn))

      {

        Conn.Open();

        return Comm.ExecuteScalar();

      }

    }

 

 

Cheers,

 

Phil.



------------------------------------------------------------------------

This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they are
addressed.

If you have received this email in error please notify the originator of
the message. This footer also confirms that this email message has been
scanned for the presence of computer viruses, though it is not
guaranteed virus free.

Original Recipient: [email protected]
Original Sender   : [EMAIL PROTECTED]
Original Send Date: 12/12/2006  - 14:52:01



--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"MbUnit.User" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/MbUnitUser?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to