Hi,
I am using OAConnection and OACommand to return multiple result sets.
This is working fine. However, I am trying to unit test my code and am having problems mocking them.
I would rather not have to actually connect to the database, I just want to mock the connections and dbDataReader to return pre defined values set by mocking. If the only way to do this is to connect to the database I will do that, but I would still want to mock call for the stored proc.
I think I can use IngnoreInstance to mock the calls, but I am having two issues.
The first issue, is that I am not able to mock the OAConnection.
I might be able to get around this my setting the the connection info in the App.Config file and create an actual instance of the Entity model.
Of course this wil create an actual connection to the database, but I will do it if there is no other way.
Then I hope to be able to mock the OACommand and dbDataReader .
The second issue is that I am not sure how to mock the OACommand and dbDataReader .
Heres is a sample of the code I am trying to mock. Any help would be greatly appreciated.
I am using OAConnection and OACommand to return multiple result sets.
This is working fine. However, I am trying to unit test my code and am having problems mocking them.
I would rather not have to actually connect to the database, I just want to mock the connections and dbDataReader to return pre defined values set by mocking. If the only way to do this is to connect to the database I will do that, but I would still want to mock call for the stored proc.
I think I can use IngnoreInstance to mock the calls, but I am having two issues.
The first issue, is that I am not able to mock the OAConnection.
I might be able to get around this my setting the the connection info in the App.Config file and create an actual instance of the Entity model.
Of course this wil create an actual connection to the database, but I will do it if there is no other way.
Then I hope to be able to mock the OACommand and dbDataReader .
The second issue is that I am not sure how to mock the OACommand and dbDataReader .
Heres is a sample of the code I am trying to mock. Any help would be greatly appreciated.
EntitiesModel dbContext =
new
EntitiesModel();
if
(dbContext !=
null
)
{
EntityName myEntity = EntityName();
using
(OAConnection connection = dbContext.Connection)
{
using
(OACommand command = connection.CreateCommand())
{
command.CommandType = System.Data.CommandType.StoredProcedure;
command.CommandText =
"SpName"
;
using
(DbDataReader dataReader = command.ExecuteReader())
{
if
(dataReader.HasRows)
{
IEnumerable<EntityName> entityname = dbContext.Translate<EntityName>(dataReader);
foreach
EntityName c
in
entityname
{
myEntity = dbContext.AttachCopy<EntityName>(c);
}
}
dataReader.NextResult();
if
(dataReader.HasRows)
{
while
(dataReader.Read())
{
this
._myField = dataReader.GetString(1);
}
}
if
(!dataReader.IsClosed)
dataReader.Close();
}
}
}
}