Posted By

heathbo on 07/10/14


Tagged

test integration Moq


Versions (?)

Using Moq, Creating an integration test with database access


 / Published in: C#
 

using (var scope = new TransactionScope()) makes sure that any changes to the database are temporary and only last as long as the test is running.

The ExecuteScalar is used to get a value from the table.

The ExecuteNonQuery is used to insert a record that the test will use.

_target is the class that is accessing the database.

  1. [TestMethod]
  2. public void GetBiAutoProcessConfigByKeys_Test()
  3. {
  4. using (var scope = new TransactionScope())
  5. {
  6. // Setup
  7. var topMx = (int)ExecuteScalar(string.Format("SELECT TOP 1 [mx_company_id] FROM [dbo].[bi_broker_invoice_number]"));
  8. ExecuteNonQuery(string.Format("INSERT INTO [dbo].[bi_auto_process_config] VALUES(39, 15, 1, 0, 1)"));
  9.  
  10. // Action
  11. var result = _target.GetProcessConfigByKeys(15, 39, null);
  12.  
  13. // Assert
  14. Assert.IsNotNull(result);
  15. Assert.IsTrue(result.BusinessUnitId==39);
  16. Assert.IsTrue(result.TransactionTypeId==15);
  17. }
  18. }

Report this snippet  

You need to login to post a comment.