Addressing code review feedback

This commit is contained in:
Mitchell Sternke
2016-08-31 16:04:04 -07:00
parent 3fe6e330fe
commit a30ff33187
3 changed files with 142 additions and 65 deletions

View File

@@ -15,15 +15,42 @@ namespace Microsoft.SqlTools.ServiceLayer.Connection.Contracts
/// <summary>
/// Check that the fields in ConnectParams are all valid
/// </summary>
public static bool IsValid(this ConnectParams parameters)
public static bool IsValid(this ConnectParams parameters, out string errorMessage)
{
return !(
String.IsNullOrEmpty(parameters.OwnerUri) ||
parameters.Connection == null ||
String.IsNullOrEmpty(parameters.Connection.Password) ||
String.IsNullOrEmpty(parameters.Connection.ServerName) ||
String.IsNullOrEmpty(parameters.Connection.UserName)
);
errorMessage = string.Empty;
if (string.IsNullOrEmpty(parameters.OwnerUri))
{
errorMessage = "Error: OwnerUri cannot be null or empty.";
}
else if (parameters.Connection == null)
{
errorMessage = "Error: Connection details object cannot be null.";
}
else if (string.IsNullOrEmpty(parameters.Connection.ServerName))
{
errorMessage = "Error: ServerName cannot be null or empty.";
}
else if (string.IsNullOrEmpty(parameters.Connection.AuthenticationType) || parameters.Connection.AuthenticationType == "SqlLogin")
{
// For SqlLogin, username/password cannot be empty
if (string.IsNullOrEmpty(parameters.Connection.UserName))
{
errorMessage = "Error: UserName cannot be null or empty when using SqlLogin authentication.";
}
else if( string.IsNullOrEmpty(parameters.Connection.Password))
{
errorMessage = "Error: Password cannot be null or empty when using SqlLogin authentication.";
}
}
if (string.IsNullOrEmpty(errorMessage))
{
return true;
}
else
{
return false;
}
}
}
}