Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test | Improving Exceptions to get better messages on test lab in ExtUtilities #1004

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;

namespace Microsoft.Data.SqlClient.ExtUtilities
{
Expand All @@ -16,9 +17,9 @@ public static class Runner
/// [0] = CreateDatabase, DropDatabase
/// [1] = Name of Database
/// </param>
public static void Main(string [] args)
public static void Main(string[] args)
{
if (args == null || args.Length < 1)
if (!args.Any() || args.Length < 1)
{
throw new ArgumentException("Utility name not provided.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Data.SqlClient.TestUtilities;
using Microsoft.SqlServer.Management.Common;

Expand Down Expand Up @@ -35,7 +36,7 @@ public static class SqlDbManager
/// </param>
public static void Run(string[] args)
{
if (args == null || args.Length < 2)
if (!args.Any() || args.Length < 2)
{
throw new InvalidArgumentException("Incomplete arguments provided.");
}
Expand Down Expand Up @@ -162,9 +163,9 @@ private static void DropIfExistsDatabase(string dbName, ServerConnection context
string dropScript = $"IF EXISTS (select * from sys.databases where name = '{dbName}') BEGIN DROP DATABASE [{dbName}] END;";
context.ExecuteNonQuery(dropScript);
}
catch
catch (ExecutionFailureException ex)
{
Console.WriteLine($"FAILED to drop database '{dbName}'");
Console.WriteLine($"FAILED to drop database '{dbName}'. Error message: {ex.Message}");
}
}

Expand All @@ -176,7 +177,15 @@ private static void CreateDatabase(string dbName, ServerConnection context)
try
{
createScript = createScript.Replace(DB_Northwind, dbName);
context.ExecuteNonQuery(createScript);
try
{
context.ExecuteNonQuery(createScript);
}
catch (ExecutionFailureException ex)
{
Console.WriteLine(ex.Message);
throw;
}
}
catch (Exception)
{
Expand Down