private void CheckQueryCache()
        {
            using var context = new TestContext(ContextUtil.GetOptions());
            var compiledQueryCache = ((MemoryCache)context.GetService <IMemoryCache>());

            Assert.Equal(0, compiledQueryCache.Count);
        }
        private static async Task BulkOperationShouldNotCloseOpenConnectionAsync(DbServer dbServer, Func <TestContext, Task> bulkOperation, string tableSufix)
        {
            ContextUtil.DbServer = dbServer;
            using var context    = new TestContext(ContextUtil.GetOptions());

            var sqlHelper = context.GetService <ISqlGenerationHelper>();
            await context.Database.OpenConnectionAsync();

            try
            {
                // we use a temp table to verify whether the connection has been closed (and re-opened) inside BulkUpdate(Async)
                var columnName     = sqlHelper.DelimitIdentifier("Id");
                var tableName      = sqlHelper.DelimitIdentifier("#MyTempTable" + tableSufix);
                var createTableSql = $" TABLE {tableName} ({columnName} INTEGER);";

                createTableSql = dbServer switch
                {
                    DbServer.SQLite => $"CREATE TEMPORARY {createTableSql}",
                    DbServer.SQLServer => $"CREATE {createTableSql}",
                    _ => throw new ArgumentException($"Unknown database type: '{dbServer}'.", nameof(dbServer)),
                };
                await context.Database.ExecuteSqlRawAsync(createTableSql);

                await bulkOperation(context);

                await context.Database.ExecuteSqlRawAsync($"SELECT {columnName} FROM {tableName}");
            }
            finally
            {
                await context.Database.CloseConnectionAsync();
            }
        }
        private static void BulkOperationShouldNotCloseOpenConnection(
            DbServer databaseType,
            Action <TestContext> bulkOperation)
        {
            ContextUtil.DbServer = databaseType;

            using (var context = new TestContext(ContextUtil.GetOptions()))
            {
                var entities  = new List <Item>();
                var sqlHelper = context.GetService <ISqlGenerationHelper>();
                context.Database.OpenConnection();

                try
                {
                    // we use a temp table to verify whether the connection has been closed (and re-opened) inside BulkUpdate(Async)
                    var columnName     = sqlHelper.DelimitIdentifier("Id");
                    var tableName      = sqlHelper.DelimitIdentifier("#MyTempTable");
                    var createTableSql = $" TABLE {tableName} ({columnName} INTEGER);";

                    switch (databaseType)
                    {
                    case DbServer.Sqlite:
                        createTableSql = $"CREATE TEMPORARY {createTableSql}";
                        break;

                    case DbServer.SqlServer:
                        createTableSql = $"CREATE {createTableSql}";
                        break;

                    default:
                        throw new ArgumentException($"Unknown database type: '{databaseType}'.", nameof(databaseType));
                    }

                    context.Database.ExecuteSqlRaw(createTableSql);

                    bulkOperation(context);

                    context.Database.ExecuteSqlRaw($"SELECT {columnName} FROM {tableName}");
                }
                finally
                {
                    context.Database.CloseConnection();
                }
            }
        }