I am just beginning to use Simple.Data for unit testing purposes and I am in the process of building some examples to get familiar with the use and sintax...
I create this test method for a SP that receives just 1 parameter:
[Test]
public void GetById_ShouldWork()
{
// arrange
var adapter = new InMemoryAdapter();
var account = new Account // I want to pass an object instead of a dictionary.
{
Id = 10053,
Name = "Test"
};
adapter.AddFunction<int // Params expected by SP
, IDictionary<string, object>[]>("usp_GetAccount", // SP name
id // Parameters definition
=> new[]
{
// Here I define the records to record by the SP call
account.AsDictionary() // This is in order so we can pass an object instead of a dictionary
});
Database.UseMockAdapter(adapter);
dynamic db = Database.Open();
// Act
List<SimpleRecord> records = db.usp_GetAccount(10053); // SP call using parameter
// Assert
Assert.IsTrue(records.Count > 0);
}
And its working great, but the problem comes with a complex test for an SP that receives many parameters:
[Test]
public void Insert_ShouldWork_And_ReturnInteger()
{
// arrange
var adapter = new InMemoryAdapter();
var account = new Account // I want to pass an object instead of a dictionary.
{
Id = 10053,
Name = "Test"
};
adapter.AddFunction<int, string, string, string, string, string, string, string, string, string, bool, string, string, int, string, DateTime, string // Params expected by SP
, IDictionary<string, object>[]>("usp_CreateAccount", // SP name
(
Id,
Name,
AddressLine1,
AddressLine2,
City,
State,
PostalCode,
Country,
Currency,
TaxId,
IsTaxExempt,
TaxExemptReason,
CreatedBy,
ParentAccountId,
SalesforceId,
CreatedDate,
Status
) // Parameters definition
=> new[]
{
// Here I define the records to record by the SP call
new Dictionary<string, object> {{"Return", 1}}
});
Database.UseMockAdapter(adapter);
dynamic db = Database.Open();
// Act
List<SimpleRecord> records = db.usp_CreateAccount(
Id: account.Id,
Name: account.Name,
AddressLine1: account.AddressLine1,
AddressLine2: account.AddressLine2,
City: account.City,
State: account.State,
PostalCode: account.PostalCode,
Country: account.Country,
Currency: account.Currency,
TaxId: account.TaxId,
IsTaxExempt: account.IsTaxExempt,
TaxExemptReason: account.TaxExemptReason,
CreatedBy: account.CreatedBy,
ParentAccountId: null,
SalesforceId: account.SalesforceId,
CreatedDate: account.CreatedDate,
Status: account.Status
); // SP call using parameter
dynamic recordAffected = records[0];
// Assert
Assert.IsTrue(recordAffected.Return > 0);
}
With this definition Visual Studio bagins to pop up a massage telling me "Incorrect number of type parameters".
If someone knows whats the problem, please help me.
Thanks in advance!.