how to test DbProviderFactories using Nuint /Rihno mocks

66 views
Skip to first unread message

Sambasiva konduri

unread,
Jul 30, 2015, 12:06:23 PM7/30/15
to Moq Discussions
hi kudos , 

i wanna test  this peace of code , 


private DbConnection GetConnection()
{
var dbProviderFactory = DbProviderFactories.GetFactory(_name);
try
{
var dbConnection = dbProviderFactory.CreateConnection();
if (dbConnection == null) return null;
dbConnection.ConnectionString = _connectionString;
return dbConnection;
}
catch (Exception)
{
return null;
}
}
I wanna mock to DbProviderFactories , how can  i do that ?
 

alejandro miralles

unread,
Jul 30, 2015, 12:33:56 PM7/30/15
to moq...@googlegroups.com
DbProviderFactories is a static class. You can’t mock that. (At least not with moq).

~ Ale Miralles.


From: <moq...@googlegroups.com> on behalf of Sambasiva konduri <nani.k...@gmail.com>
Reply-To: <moq...@googlegroups.com>
Date: Thursday, July 30, 2015 at 9:30 AM
To: Moq Discussions <moq...@googlegroups.com>
Subject: [Moq] how to test DbProviderFactories using Nuint /Rihno mocks

DbProviderFactories.GetFactory
Reply all
Reply to author
Forward
0 new messages