コード例 #1
0
ファイル: DbHelperTest.cs プロジェクト: bank2u/RepoDb
        public void TestDbHelperForQueryViaTableName()
        {
            // Prepare
            var dbHelper   = new Mock <IDbHelper>();
            var connection = new CustomDbConnectionForDbHelper();

            // Setup
            dbHelper.Setup(builder =>
                           builder.GetFields(
                               It.Is <IDbConnection>(s => s == connection),
                               It.Is <string>(s => s == ClassMappedNameCache.Get <DataEntityForDbHelper>()),
                               It.IsAny <IDbTransaction>())
                           ).Returns(GetDbFields());

            // Act
            CommandTextCache.Flush();
            DbFieldCache.Flush();
            StatementBuilderMapper.Add(typeof(CustomDbConnectionForDbHelper), new SqlServerStatementBuilder(), true);
            DbHelperMapper.Add(typeof(CustomDbConnectionForDbHelper), dbHelper.Object, true);

            // Act
            connection.Query(ClassMappedNameCache.Get <DataEntityForDbHelper>(),
                             (object)null);

            // Assert
            dbHelper.Verify(builder =>
                            builder.GetFields(
                                It.Is <IDbConnection>(s => s == connection),
                                It.Is <string>(s => s == ClassMappedNameCache.Get <DataEntityForDbHelper>()),
                                It.IsAny <IDbTransaction>()), Times.Exactly(1));
        }
コード例 #2
0
ファイル: DbHelperTest.cs プロジェクト: crazyants/RepoDb
        public void TestDbHelperForQuery()
        {
            // Prepare
            var dbHelper   = new Mock <IDbHelper>();
            var connection = new CustomDbConnectionForDbHelper();

            // Act
            CommandTextCache.Flush();
            DbFieldCache.Flush();
            StatementBuilderMapper.Add(typeof(CustomDbConnectionForDbHelper), new SqlStatementBuilder(), true);
            DbHelperMapper.Add(typeof(CustomDbConnectionForDbHelper), dbHelper.Object, true);

            // Act
            connection.Query <DataEntityForDbHelper>((object)null);

            // Assert
            dbHelper.Verify(builder =>
                            builder.GetFields(
                                It.Is <string>(s => s == connection.ConnectionString),
                                It.Is <string>(s => s == ClassMappedNameCache.Get <DataEntityForDbHelper>())), Times.Exactly(1));
        }