Return to Snippet

Revision: 66827
at July 10, 2014 01:45 by heathbo


Updated Code
[TestMethod]
public void GetBiAutoProcessConfigByKeys_Test()
{
    using (var scope = new TransactionScope())
    {
        // Setup
        var topMx = (int)ExecuteScalar(string.Format("SELECT TOP 1 [mx_company_id] FROM [dbo].[bi_broker_invoice_number]"));
        ExecuteNonQuery(string.Format("INSERT INTO [dbo].[bi_auto_process_config] VALUES(39, 15, 1, 0, 1)"));

        // Action
        var result = _target.GetProcessConfigByKeys(15, 39, null);

        // Assert
        Assert.IsNotNull(result);
        Assert.IsTrue(result.BusinessUnitId==39);
        Assert.IsTrue(result.TransactionTypeId==15);
    }
 }

Revision: 66826
at July 10, 2014 00:20 by heathbo


Initial Code
[TestMethod]
public void GetBiAutoProcessConfigByKeys_Test()
{
    using (var scope = new TransactionScope())
    {
        // Setup
        ExecuteNonQuery(string.Format("INSERT INTO [dbo].[bi_auto_process_config] VALUES(39, 15, 1, 0, 1)"));

        // Action
        var result = _target.GetProcessConfigByKeys(15, 39, null);

        // Assert
        Assert.IsNotNull(result);
        Assert.IsTrue(result.BusinessUnitId==39);
        Assert.IsTrue(result.TransactionTypeId==15);
    }
 }

Initial URL

                                

Initial Description
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.

Initial Title
Moq: Creating an integration test with database access

Initial Tags

                                

Initial Language
C#