/// <summary>
        /// Runs a query by calling the services directly (not using the test driver)
        /// </summary>
        public async Task RunQueryAsync(TestServerType serverType, string databaseName, string queryText, bool throwOnError = false)
        {
            string uri = "";

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                uri = queryTempFile.FilePath;

                ConnectionInfo connInfo = InitLiveConnectionInfo(serverType, databaseName, uri);
                Query          query    = new Query(queryText, connInfo, new QueryExecutionSettings(), MemoryFileSystem.GetFileStreamFactory());
                query.Execute();
                await query.ExecutionTask;

                if (throwOnError)
                {
                    IEnumerable <Batch> errorBatches = query.Batches.Where(b => b.HasError);
                    if (errorBatches.Count() > 0)
                    {
                        throw new InvalidOperationException(
                                  string.Format(
                                      "The query encountered and error. The batches with errors: {0}",
                                      string.Join(Environment.NewLine, errorBatches.Select(b => b.BatchText))));
                    }
                }
                DisconnectConnection(uri);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Runs a query by calling the services directly (not using the test driver)
 /// </summary>
 public void RunQuery(TestServerType serverType, string databaseName, string queryText)
 {
     using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
     {
         ConnectionInfo connInfo = InitLiveConnectionInfo(serverType, databaseName, queryTempFile.FilePath);
         Query          query    = new Query(queryText, connInfo, new QueryExecutionSettings(), GetFileStreamFactory(new Dictionary <string, byte[]>()));
         query.Execute();
         query.ExecutionTask.Wait();
     }
 }
Ejemplo n.º 3
0
 public void Cleanup()
 {
     if (!DoNotCleanupDb)
     {
         using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
         {
             string dropDatabaseQuery = string.Format(CultureInfo.InvariantCulture,
                                                      (ServerType == TestServerType.Azure ? Scripts.DropDatabaseIfExistAzure : Scripts.DropDatabaseIfExist), DatabaseName);
             TestServiceProvider.Instance.RunQuery(ServerType, MasterDatabaseName, dropDatabaseQuery);
         }
     }
 }
        public async Task RunQuery(TestServerType serverType, string databaseName, string query)
        {
            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                await ConnectForQuery(serverType, query, queryTempFile.FilePath, databaseName);

                var queryResult = await CalculateRunTime(() => RunQueryAndWaitToComplete(queryTempFile.FilePath, query, 50000));

                Assert.NotNull(queryResult);
                Assert.NotNull(queryResult.BatchSummaries);

                await Disconnect(queryTempFile.FilePath);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Create the test db if not already exists
        /// </summary>
        internal static async Task CreateTestDatabase(TestServerType serverType, string databaseName = null, string query = null)
        {
            using (TestServiceDriverProvider testService = new TestServiceDriverProvider())
                using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
                {
                    databaseName = databaseName ?? GetUniqueDBName("");
                    string createDatabaseQuery = Scripts.CreateDatabaseQuery.Replace("#DatabaseName#", databaseName);
                    await testService.RunQuery(serverType, MasterDatabaseName, createDatabaseQuery);

                    Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Verified test database '{0}' is created", databaseName));
                    if (!string.IsNullOrEmpty(query))
                    {
                        await testService.RunQuery(serverType, databaseName, query);// Scripts.CreateDatabaseObjectsQuery);

                        Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Verified test database '{0}' SQL types are created", databaseName));
                    }
                }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Create the test db if not already exists
        /// </summary>
        public static SqlTestDb CreateNew(TestServerType serverType, bool doNotCleanupDb = false, string databaseName = null, string query = null)
        {
            SqlTestDb testDb = new SqlTestDb();

            using (SelfCleaningTempFile queryTempFile = new SelfCleaningTempFile())
            {
                databaseName = databaseName ?? GetUniqueDBName("");
                string createDatabaseQuery = Scripts.CreateDatabaseQuery.Replace("#DatabaseName#", databaseName);
                TestServiceProvider.Instance.RunQuery(serverType, MasterDatabaseName, createDatabaseQuery);
                Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test database '{0}' is created", databaseName));
                if (!string.IsNullOrEmpty(query))
                {
                    TestServiceProvider.Instance.RunQuery(serverType, databaseName, query);
                    Console.WriteLine(string.Format(CultureInfo.InvariantCulture, "Test database '{0}' SQL types are created", databaseName));
                }
                testDb.DatabaseName   = databaseName;
                testDb.ServerType     = serverType;
                testDb.DoNotCleanupDb = doNotCleanupDb;
            }

            return(testDb);
        }