mercredi 12 août 2015

Using Moq with SQLiteConnection in C#

I am trying to understand how to use Moq with SQLiteConnection. The problem is that since I am quite new to Moq and I have not found any relevant tutorial on my problem.

I would like some tips on how to use it.

The error:

    SetUp : Castle.DynamicProxy.InvalidProxyConstructorArgumentsException : Can not instantiate proxy of class: SQLite.Net.SQLiteConnection.
    Could not find a constructor that would match given arguments:
    SQLite.Net.Platform.Win32.SQLitePlatformWin32
    System.String
at Castle.DynamicProxy.ProxyGenerator.CreateClassProxyInstance(Type proxyType, List`1 proxyArguments, Type classToProxy, Object[] constructorArguments)
   at Moq.Proxy.CastleProxyFactory.CreateProxy(Type mockType, ICallInterceptor interceptor, Type[] interfaces, Object[] arguments)
   at Moq.Mock`1.<InitializeInstance>b__2()
   at Moq.Mock`1.OnGetObject()
   at Moq.Mock`1.get_Object()
   at Silje.Synchronization.Test.AktoerSynchronizationTest.SetUp()

The code sample:

        private SQLiteConnection _sqLiteConnection;

        [SetUp]
        public void SetUp()
        {
            Mock<SQLiteConnection> 
            mockSQLiteconnection = new Mock<SQLiteConnection>(MockBehavior.Loose, 
                 new SQLitePlatformWin32(),
                 "TestDb");
            var t = mockSQLiteconnection.Object; // fails!!!
        }

Aucun commentaire:

Enregistrer un commentaire