Exemplo n.º 1
0
        public void TestDbHelperForUpdateAllViaTableName()
        {
            // 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.UpdateAll(ClassMappedNameCache.Get <DataEntityForDbHelper>(),
                                 new[] { new DataEntityForDbHelper {
                                             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));
        }
Exemplo n.º 2
0
        public void TestDbHelperForBatchQueryViaTableName()
        {
            // Prepare
            var dbHelper   = GetMockedDbHelper();
            var connection = new DbHelperDbConnection();

            // Act
            CommandTextCache.Flush();
            DbFieldCache.Flush();
            DbHelperMapper.Add(typeof(DbHelperDbConnection), dbHelper.Object, true);

            // Act
            connection.BatchQuery(ClassMappedNameCache.Get <DbHelperDataEntity>(),
                                  0,
                                  10,
                                  OrderField.Ascending <DbHelperDataEntity>(e => e.Id).AsEnumerable(),
                                  new { Id = 1 });

            // Assert
            dbHelper.Verify(builder =>
                            builder.GetFields(
                                It.Is <IDbConnection>(s => s == connection),
                                It.Is <string>(s => s == ClassMappedNameCache.Get <DbHelperDataEntity>()),
                                It.IsAny <IDbTransaction>()), Times.Exactly(1));
        }
Exemplo n.º 3
0
        public void TestDbHelperForBatchQuery()
        {
            // 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.BatchQuery <DataEntityForDbHelper>(0,
                                                          10,
                                                          OrderField.Ascending <DataEntityForDbHelper>(e => e.Id).AsEnumerable(),
                                                          e => e.Id == 1);

            // 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));
        }
Exemplo n.º 4
0
        public void TestDbHelperForQueryAllViaTableName()
        {
            // Prepare
            var dbHelper   = new Mock <IDbHelper>();
            var connection = new DbHelperDbConnection();

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

            // Act
            CommandTextCache.Flush();
            DbFieldCache.Flush();
            DbHelperMapper.Add(typeof(DbHelperDbConnection), dbHelper.Object, true);

            // Act
            connection.QueryAll(ClassMappedNameCache.Get <DbHelperDataEntity>());

            // Assert
            dbHelper.Verify(builder =>
                            builder.GetFields(
                                It.Is <IDbConnection>(s => s == connection),
                                It.Is <string>(s => s == ClassMappedNameCache.Get <DbHelperDataEntity>()),
                                It.IsAny <IDbTransaction>()), Times.Exactly(1));
        }
Exemplo n.º 5
0
        public void TestDbHelperForQueryViaTableName()
        {
            // Prepare
            var dbHelper   = new Mock <IDbHelper>();
            var connection = new CustomDbConnectionForDbHelper();

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

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

            // Act
            connection.Query(ClassMappedNameCache.Get <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));
        }
Exemplo n.º 6
0
 /// <summary>
 /// database import as an asynchronous operation.
 /// </summary>
 /// <param name="parameters">The parameters.</param>
 /// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
 public async Task <ICollectionImportResult> DatabaseImportAsync(ModCollectionExporterParams parameters)
 {
     // Caching sucks in this ORM
     DbFieldCache.Flush();
     FieldCache.Flush();
     IdentityCache.Flush();
     PrimaryCache.Flush();
     if (await IsV4Async(parameters))
     {
         return(await DatabaseImportv3Async(parameters));
     }
     return(await DatabaseImportv2Async(parameters));
 }
Exemplo n.º 7
0
        public void TestDbHelperForQuery()
        {
            // Prepare
            var dbHelper   = GetMockedDbHelper();
            var connection = new DbHelperDbConnection();

            // Act
            CommandTextCache.Flush();
            DbFieldCache.Flush();
            DbHelperMapper.Add(typeof(DbHelperDbConnection), dbHelper.Object, true);

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

            // Assert
            dbHelper.Verify(builder =>
                            builder.GetFields(
                                It.Is <IDbConnection>(s => s == connection),
                                It.Is <string>(s => s == ClassMappedNameCache.Get <DbHelperDataEntity>()),
                                It.IsAny <IDbTransaction>()), Times.Exactly(1));
        }
Exemplo n.º 8
0
        public void TestDbHelperForQueryAll()
        {
            // Prepare
            var dbHelper   = new Mock <IDbHelper>();
            var connection = new CustomDbConnectionForDbHelper();

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

            // Act
            connection.QueryAll <DataEntityForDbHelper>();

            // 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));
        }
Exemplo n.º 9
0
        public void TestDbHelperForInsertAllViaTableName()
        {
            // Prepare
            var dbHelper   = GetMockedDbHelper();
            var connection = new DbHelperDbConnection();

            // Act
            CommandTextCache.Flush();
            DbFieldCache.Flush();
            DbHelperMapper.Add(typeof(DbHelperDbConnection), dbHelper.Object, true);

            // Act
            connection.InsertAll(ClassMappedNameCache.Get <DbHelperDataEntity>(),
                                 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 <DbHelperDataEntity>()),
                                It.IsAny <IDbTransaction>()), Times.Exactly(1));
        }
Exemplo n.º 10
0
        public void TestDbHelperForInsert()
        {
            // 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.Insert <DataEntityForDbHelper>(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));
        }