示例#1
0
        /// <summary>
        /// Will configure the fixture on first test launch
        /// </summary>
        internal void Configure()
        {
            // Pattern double check to be sur one instance is not trying to create the databse during an other trying to delete the same one.
            lock (locker)
            {
                if (isConfigured)
                {
                    return;
                }

                lock (locker)
                {
                    if (isConfigured)
                    {
                        return;
                    }

                    // gets the server provider
                    this.ServerProvider = this.NewServerProvider(HelperDB.GetConnectionString(this.ProviderType, this.DatabaseName));

                    // create the server database
                    this.ServerDatabaseEnsureCreated();


                    // Get all provider fixture
                    var listOfBs = (from assemblyType in typeof(ProviderFixture).Assembly.DefinedTypes
                                    where typeof(ProviderFixture).IsAssignableFrom(assemblyType) &&
                                    assemblyType.BaseType == typeof(ProviderFixture)
                                    select assemblyType).ToArray();

                    foreach (var t in listOfBs)
                    {
                        var c        = GetDefaultConstructor(t);
                        var instance = c.Invoke(null) as ProviderFixture;
                        RegisterProvider(instance.ProviderType, instance);
                    }

                    // create the clients database
                    this.ClientDatabasesEnsureCreated();

                    isConfigured = true;
                }
            }
        }
示例#2
0
        internal virtual void ClientDatabasesEnsureCreated()
        {
            // foreach server provider to test, there is a list of client / network
            foreach (var serverKey in this.lstClientsType)
            {
                // get the the network we want to use
                var networkType = serverKey.Key;

                // create all the client databases based in the flags we set
                foreach (var cpt in serverKey.Value.GetFlags())
                {
                    // cast (wait for C# 7.3 to be able to set an extension method where a generic T can be marked as Enum compliant :)
                    var clientProviderType = (ProviderType)cpt;

                    // check if we have the fixture provider to be able to create a client provider
                    if (!registeredProviders.ContainsKey(clientProviderType))
                    {
                        continue;
                    }

                    // generate a new database name
                    var dbName = GetRandomDatabaseName();

                    Console.WriteLine("Create client database called " + dbName + " for provider " + clientProviderType);

                    // get the connection string
                    var connectionString = HelperDB.GetConnectionString(clientProviderType, dbName);

                    // create the database on the client provider
                    HelperDB.CreateDatabase(clientProviderType, dbName);

                    // generate the client provider
                    var clientProvider = registeredProviders[clientProviderType].NewServerProvider(connectionString);

                    // then add the run
                    this.ClientRuns.Add(new ProviderRun(dbName, clientProvider, clientProviderType, networkType));
                }
            }
        }