예제 #1
0
        public void TestDbHelperForInsertAllViaTableName()
        {
            // 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.InsertAll(ClassMappedNameCache.Get <DataEntityForDbHelper>(),
                                 new[] { new { Id = 1, Name = "Name" } });

            // 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
        public void TestDbHelperForInsertAll()
        {
            // 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.InsertAll <DataEntityForDbHelper>(new[] { new DataEntityForDbHelper {
                                                                     Id = 1, Name = "Name"
                                                                 } });

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