<commit_before>namespace Cedar.EventStore
{
    using System;
    using System.Data.SqlClient;
    using System.Data.SqlLocalDb;
    using System.Threading.Tasks;
    using Cedar.EventStore.Subscriptions;

    public class MsSqlEventStoreFixture : EventStoreAcceptanceTestFixture
    {
        public readonly string ConnectionString;
        private readonly string _schema;
        private readonly ISqlLocalDbInstance _localDbInstance;
        private readonly string _databaseName;

        public MsSqlEventStoreFixture(string schema)
        {
            _schema = schema;
            var localDbProvider = new SqlLocalDbProvider
            {
                Version = "11.0"
            };
            _localDbInstance = localDbProvider.GetOrCreateInstance("CedarEventStoreTests");
            _localDbInstance.Start();

            var uniqueName = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString().PadLeft(20, '0');
            _databaseName = $"CedarEventStoreTests_{uniqueName}";

            ConnectionString = CreateConnectionString();
        }

        public override async Task<IEventStore> GetEventStore()
        {
            await CreateDatabase();

            var eventStore = new MsSqlEventStore(ConnectionString, Poller.CreateEventStoreNotifier(), _schema);
            await eventStore.DropAll(ignoreErrors: true);
            await eventStore.InitializeStore();

            return eventStore;
        }

        public async Task<IEventStore> GetEventStore(string schema)
        {
            var eventStore = new MsSqlEventStore(ConnectionString, Poller.CreateEventStoreNotifier(), schema);
            await eventStore.InitializeStore();

            return eventStore;
        }

        public override void Dispose()
        {
            using(var sqlConnection = new SqlConnection(ConnectionString))
            {
                // Fixes: "Cannot drop database because it is currently in use"
                SqlConnection.ClearPool(sqlConnection);
            }

            using (var connection = _localDbInstance.CreateConnection())
            {
                connection.Open();
                using (var command = new SqlCommand($"DROP DATABASE {_databaseName}", connection))
                {
                    command.ExecuteNonQuery();
                }
            }
        }

        private async Task CreateDatabase()
        {
            using(var connection = _localDbInstance.CreateConnection())
            {
                await connection.OpenAsync();
                using(var command = new SqlCommand($"CREATE DATABASE {_databaseName}", connection))
                {
                    await command.ExecuteNonQueryAsync();
                }
            }
        }

        private string CreateConnectionString()
        {
            var connectionStringBuilder = _localDbInstance.CreateConnectionStringBuilder();
            connectionStringBuilder.MultipleActiveResultSets = true;
            connectionStringBuilder.IntegratedSecurity = true;
            connectionStringBuilder.InitialCatalog = _databaseName;

            return connectionStringBuilder.ToString();
        }
    }
}<commit_msg>Use SqlLocaldb verson 10.5 (SqlServer 2008 R2)<commit_after>namespace Cedar.EventStore
{
    using System;
    using System.Data.SqlClient;
    using System.Data.SqlLocalDb;
    using System.Threading.Tasks;
    using Cedar.EventStore.Subscriptions;

    public class MsSqlEventStoreFixture : EventStoreAcceptanceTestFixture
    {
        public readonly string ConnectionString;
        private readonly string _schema;
        private readonly ISqlLocalDbInstance _localDbInstance;
        private readonly string _databaseName;

        public MsSqlEventStoreFixture(string schema)
        {
            _schema = schema;
            var localDbProvider = new SqlLocalDbProvider
            {
                Version = "10.5"
            };
            _localDbInstance = localDbProvider.GetOrCreateInstance("CedarEventStoreTests");
            _localDbInstance.Start();

            var uniqueName = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString().PadLeft(20, '0');
            _databaseName = $"CedarEventStoreTests_{uniqueName}";

            ConnectionString = CreateConnectionString();
        }

        public override async Task<IEventStore> GetEventStore()
        {
            await CreateDatabase();

            var eventStore = new MsSqlEventStore(ConnectionString, Poller.CreateEventStoreNotifier(), _schema);
            await eventStore.DropAll(ignoreErrors: true);
            await eventStore.InitializeStore();

            return eventStore;
        }

        public async Task<IEventStore> GetEventStore(string schema)
        {
            var eventStore = new MsSqlEventStore(ConnectionString, Poller.CreateEventStoreNotifier(), schema);
            await eventStore.InitializeStore();

            return eventStore;
        }

        public override void Dispose()
        {
            using(var sqlConnection = new SqlConnection(ConnectionString))
            {
                // Fixes: "Cannot drop database because it is currently in use"
                SqlConnection.ClearPool(sqlConnection);
            }

            using (var connection = _localDbInstance.CreateConnection())
            {
                connection.Open();
                using (var command = new SqlCommand($"DROP DATABASE {_databaseName}", connection))
                {
                    command.ExecuteNonQuery();
                }
            }
        }

        private async Task CreateDatabase()
        {
            using(var connection = _localDbInstance.CreateConnection())
            {
                await connection.OpenAsync();
                using(var command = new SqlCommand($"CREATE DATABASE {_databaseName}", connection))
                {
                    await command.ExecuteNonQueryAsync();
                }
            }
        }

        private string CreateConnectionString()
        {
            var connectionStringBuilder = _localDbInstance.CreateConnectionStringBuilder();
            connectionStringBuilder.MultipleActiveResultSets = true;
            connectionStringBuilder.IntegratedSecurity = true;
            connectionStringBuilder.InitialCatalog = _databaseName;

            return connectionStringBuilder.ToString();
        }
    }
}
{'fraction_non_alphanumeric': 0.07211012044423588, 'fraction_numerical': 0.003128421711246676, 'mean_word_length': 2.044761904761905, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2275143', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1441, 'n_words': 316}