Convert Async to sync (SqlClient apis) and cleanup async usage (#2167)

This commit is contained in:
Cheena Malhotra
2023-08-09 15:03:02 -07:00
committed by GitHub
parent 65a7406063
commit 0820d9796a
20 changed files with 64 additions and 83 deletions

View File

@@ -1498,7 +1498,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
}
[Test]
public async Task GetOrOpenNullOwnerUri([Values(null, "")] string ownerUri)
public void GetOrOpenNullOwnerUri([Values(null, "")] string ownerUri)
{
// If: I have a connection service and I ask for a connection with an invalid ownerUri
// Then: An exception should be thrown
@@ -1508,7 +1508,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
}
[Test]
public async Task GetOrOpenNullConnectionType([Values(null, "")] string connType)
public void GetOrOpenNullConnectionType([Values(null, "")] string connType)
{
// If: I have a connection service and I ask for a connection with an invalid connectionType
// Then: An exception should be thrown
@@ -1518,7 +1518,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
}
[Test]
public async Task GetOrOpenNoConnection()
public void GetOrOpenNoConnection()
{
// If: I have a connection service and I ask for a connection for an unconnected uri
// Then: An exception should be thrown
@@ -1528,7 +1528,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
}
[Test]
public async Task GetOrOpenNoDefaultConnection()
public void GetOrOpenNoDefaultConnection()
{
// Setup: Create a connection service with an empty connection info obj
var service = TestObjects.GetTestConnectionService();
@@ -1542,7 +1542,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
}
[Test]
public async Task GetOrOpenAdminDefaultConnection()
public void GetOrOpenAdminDefaultConnection()
{
// Setup: Create a connection service with an empty connection info obj
var service = TestObjects.GetTestConnectionService();
@@ -1883,7 +1883,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
/// Verify that providing an empty password to change password will fire an error.
/// </summary>
[Test]
public async Task ConnectionEmptyPasswordChange()
public void ConnectionEmptyPasswordChange()
{
var serviceHostMock = new Mock<IProtocolEndpoint>();
@@ -1905,7 +1905,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
/// Verify that providing an invalid connection parameter value to change password will fire an error.
/// </summary>
[Test]
public async Task ConnectionInvalidParamPasswordChange()
public void ConnectionInvalidParamPasswordChange()
{
var serviceHostMock = new Mock<IProtocolEndpoint>();
@@ -1927,7 +1927,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
/// Verify that providing a non actual connection and a fake password to change password will throw an error.
/// </summary>
[Test]
public async Task InvalidConnectionPasswordChange()
public void InvalidConnectionPasswordChange()
{
var serviceHostMock = new Mock<IProtocolEndpoint>();

View File

@@ -180,7 +180,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
// If: I ask for the change to be applied
var rc = new RowCreate(rowId, rs, data.TableMetadata);
await rc.ApplyChanges(newRowReader);
rc.ApplyChanges(newRowReader);
// Then: The result set should have an additional row in it
Assert.AreEqual(2, rs.RowCount);

View File

@@ -69,7 +69,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
// If: I ask for the change to be applied
RowDelete rd = new RowDelete(0, rs, data.TableMetadata);
await rd.ApplyChanges(null); // Reader not used, can be null
rd.ApplyChanges(null); // Reader not used, can be null
// Then : The result set should have one less row in it
Assert.AreEqual(0, rs.RowCount);
@@ -209,7 +209,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
};
var testResultSet = new TestResultSet(data.DbColumns, rows);
var newRowReader = new TestDbDataReader(new[] { testResultSet }, false);
await ru.ApplyChanges(newRowReader);
ru.ApplyChanges(newRowReader);
// ... Create a row delete.
RowDelete rd = new RowDelete(0, rs, data.TableMetadata);

View File

@@ -349,7 +349,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
throw new NotImplementedException();
}
public override Task ApplyChanges(DbDataReader reader)
public override void ApplyChanges(DbDataReader reader)
{
throw new NotImplementedException();
}

View File

@@ -403,7 +403,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
var newRowReader = Common.GetNewRowDataReader(data.DbColumns, includeIdentity);
// If: I ask for the change to be applied
await ru.ApplyChanges(newRowReader);
ru.ApplyChanges(newRowReader);
// Then:
// ... The result set should have the same number of rows as before
@@ -422,7 +422,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
// If: I ask for the changes to be applied with a null db reader
// Then: I should get an exception
Assert.ThrowsAsync<ArgumentNullException>(() => ru.ApplyChanges(null));
Assert.Throws<ArgumentNullException>(() => ru.ApplyChanges(null));
}
#endregion

View File

@@ -269,7 +269,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
#region Initialize Tests
[Test]
[Sequential]
public async Task InitializeNullParams([Values(null, Common.OwnerUri, Common.OwnerUri)] string ownerUri,
public void InitializeNullParams([Values(null, Common.OwnerUri, Common.OwnerUri)] string ownerUri,
[Values("table", null, "table")] string objName,
[Values("table", "table", null)] string objType)
{

View File

@@ -803,7 +803,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
#region SubSet Tests
[Test]
public async Task SubsetNotInitialized()
public void SubsetNotInitialized()
{
// Setup:
// ... Create a session without initializing
@@ -1108,7 +1108,6 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.EditData
// ... Add a mock commands for fun
var edit = new Mock<RowEditBase>();
edit.Setup(e => e.GetCommand(It.IsAny<DbConnection>())).Returns<DbConnection>(dbc => dbc.CreateCommand());
edit.Setup(e => e.ApplyChanges(It.IsAny<DbDataReader>())).Returns(Task.FromResult(0));
s.EditCache[0] = edit.Object;
// If: I commit these changes (and await completion)

View File

@@ -120,9 +120,9 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
Query query = new Query(Constants.StandardQuery, ci, querySettings, MemoryFileSystem.GetFileStreamFactory());
string errorMessage = null;
Query.QueryAsyncErrorEventHandler failureCallback = async (q, e) =>
{
Query.QueryAsyncErrorEventHandler failureCallback = (q, e) => {
errorMessage = "Error Occured";
return Task.CompletedTask;
};
query.QueryFailed += failureCallback;

View File

@@ -45,7 +45,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
}
[Test]
public async Task ReadToEndNullReader()
public void ReadToEndNullReader()
{
// If: I create a new result set with a null db data reader
// Then: I should get an exception
@@ -169,8 +169,8 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
get
{
yield return new object[] {new Action<ResultSet>(rs => rs.GetSubset(0, 0).Wait())};
yield return new object[] {new Action<ResultSet>(rs => rs.UpdateRow(0, null).Wait())};
yield return new object[] {new Action<ResultSet>(rs => rs.AddRow(null).Wait())};
yield return new object[] {new Action<ResultSet>(rs => rs.UpdateRow(0, null))};
yield return new object[] {new Action<ResultSet>(rs => rs.AddRow(null))};
yield return new object[] {new Action<ResultSet>(rs => rs.RemoveRow(0))};
yield return new object[] {new Action<ResultSet>(rs => rs.GetRow(0))};
yield return new object[] {new Action<ResultSet>(rs => rs.GetExecutionPlan().Wait())};
@@ -399,7 +399,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
{
yield return (rs, id) => rs.RemoveRow(id);
yield return (rs, id) => rs.GetRow(id);
yield return (rs, id) => rs.UpdateRow(id, null).Wait();
yield return (rs, id) => rs.UpdateRow(id, null);
}
}
@@ -438,7 +438,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
// If: I add a row with a reader that has no rows
// Then:
// ... I should get an exception
Assert.ThrowsAsync<InvalidOperationException>(() => resultSet.AddRow(emptyReader));
Assert.Throws<InvalidOperationException>(() => resultSet.AddRow(emptyReader));
// ... The row count should not have changed
Assert.AreEqual(Common.StandardRows, resultSet.RowCount);
@@ -457,7 +457,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
// ... Create a mock reader that will throw on read
var throwingReader = GetReader(new[] {new TestResultSet(5, 0)}, true, Constants.StandardQuery);
Assert.ThrowsAsync<TestDbException>(() => resultSet.AddRow(throwingReader), "I add a row with a reader that throws on read. I should get an exception");
Assert.Throws<TestDbException>(() => resultSet.AddRow(throwingReader), "I add a row with a reader that throws on read. I should get an exception");
// ... The row count should not have changed
Assert.AreEqual(Common.StandardRows, resultSet.RowCount);
@@ -480,7 +480,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
var newRowReader = GetReader(results, false, Constants.StandardQuery);
// If: I add a new row to the result set
await resultSet.AddRow(newRowReader);
resultSet.AddRow(newRowReader);
// Then:
// ... There should be a new row in the list of rows
@@ -505,7 +505,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
// If: I add a row with a reader that has no rows
// Then:
// ... I should get an exception
Assert.ThrowsAsync<InvalidOperationException>(() => resultSet.UpdateRow(0, emptyReader));
Assert.Throws<InvalidOperationException>(() => resultSet.UpdateRow(0, emptyReader));
// ... The row count should not have changed
Assert.AreEqual(Common.StandardRows, resultSet.RowCount);
@@ -528,7 +528,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
var newRowReader = GetReader(results, false, Constants.StandardQuery);
// If: I add a new row to the result set
await resultSet.UpdateRow(0, newRowReader);
resultSet.UpdateRow(0, newRowReader);
// Then:
// ... There should be the same number of rows

View File

@@ -148,7 +148,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
#region Inter-Service API Tests
[Test]
public async Task InterServiceExecuteNullExecuteParams()
public void InterServiceExecuteNullExecuteParams()
{
// Setup: Create a query service
var qes = new QueryExecutionService(null, null);
@@ -162,7 +162,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
}
[Test]
public async Task InterServiceExecuteNullEventSender()
public void InterServiceExecuteNullEventSender()
{
// Setup: Create a query service, and execute params
var qes = new QueryExecutionService(null, null);
@@ -175,7 +175,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
}
[Test]
public async Task InterServiceDisposeNullSuccessFunc()
public void InterServiceDisposeNullSuccessFunc()
{
// Setup: Create a query service and dispose params
var qes = new QueryExecutionService(null, null);
@@ -188,7 +188,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.Execution
}
[Test]
public async Task InterServiceDisposeNullFailureFunc()
public void InterServiceDisposeNullFailureFunc()
{
// Setup: Create a query service and dispose params
var qes = new QueryExecutionService(null, null);

View File

@@ -38,7 +38,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
}
[Test]
public async Task ExecutionPlanInvalid()
public void ExecutionPlanInvalid()
{
// Setup:
// ... I have a batch that has been executed
@@ -71,7 +71,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
}
[Test]
public async Task BatchExecutionPlanInvalidTest()
public void BatchExecutionPlanInvalidTest()
{
// Setup:
// ... I have a batch that has been executed without an execution plan
@@ -83,7 +83,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
}
[Test]
public async Task BatchExecutionPlanInvalidParamsTest([Values(-1,2)] int resultSetIndex)
public void BatchExecutionPlanInvalidParamsTest([Values(-1,2)] int resultSetIndex)
{
// If I have an executed batch which has an execution plan
Batch b = Common.GetExecutedBatchWithExecutionPlan();
@@ -99,7 +99,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
#region Query Class Tests
[Test]
public async Task QueryExecutionPlanInvalidParamsTest([Values(-1,2)]int batchIndex)
public void QueryExecutionPlanInvalidParamsTest([Values(-1,2)]int batchIndex)
{
// Setup query settings
QueryExecutionSettings querySettings = new QueryExecutionSettings

View File

@@ -158,7 +158,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
}
[Test]
public async Task SubsetServiceMissingQueryTest()
public void SubsetServiceMissingQueryTest()
{
// If:
// ... I ask for a set of results for a file that hasn't executed a query

View File

@@ -24,7 +24,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
public class FirewallRuleServiceTest
{
[Test]
public async Task CreateShouldThrowExceptionGivenNullServerName()
public void CreateShouldThrowExceptionGivenNullServerName()
{
string serverName = null;
@@ -34,7 +34,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateShouldThrowExceptionGivenNullStartIp()
public void CreateShouldThrowExceptionGivenNullStartIp()
{
string serverName = "serverName";
@@ -44,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateShouldThrowExceptionGivenInvalidEndIp()
public void CreateShouldThrowExceptionGivenInvalidEndIp()
{
string serverName = "serverName";
@@ -54,7 +54,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateShouldThrowExceptionGivenInvalidStartIp()
public void CreateShouldThrowExceptionGivenInvalidStartIp()
{
string serverName = "serverName";
@@ -64,7 +64,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateShouldThrowExceptionGivenNullEndIp()
public void CreateShouldThrowExceptionGivenNullEndIp()
{
ServiceTestContext testContext = new ServiceTestContext();
testContext.EndIpAddress = null;
@@ -72,7 +72,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateShouldThrowExceptionIfUserIsNotLoggedIn()
public void CreateShouldThrowExceptionIfUserIsNotLoggedIn()
{
var applicationAuthenticationManagerMock = new Mock<IAzureAuthenticationManager>();
applicationAuthenticationManagerMock.Setup(x => x.GetUserNeedsReauthenticationAsync()).Throws(new ApplicationException());
@@ -89,7 +89,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateShouldThrowExceptionIfUserDoesNotHaveSubscriptions()
public void CreateShouldThrowExceptionIfUserDoesNotHaveSubscriptions()
{
var applicationAuthenticationManagerMock =
new Mock<IAzureAuthenticationManager>();
@@ -109,7 +109,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateShouldThrowExceptionIfAuthenticationManagerFailsToReturnSubscription()
public void CreateShouldThrowExceptionIfAuthenticationManagerFailsToReturnSubscription()
{
var applicationAuthenticationManagerMock = new Mock<IAzureAuthenticationManager>();
applicationAuthenticationManagerMock.Setup(x => x.GetUserNeedsReauthenticationAsync()).Returns(Task.FromResult(false));
@@ -127,7 +127,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateShouldThrowExceptionGivenNoSubscriptionFound()
public void CreateShouldThrowExceptionGivenNoSubscriptionFound()
{
ServiceTestContext testContext = new ServiceTestContext();
testContext = CreateMocks(testContext);
@@ -242,7 +242,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateThrowExceptionIfResourceNotFound()
public void CreateThrowExceptionIfResourceNotFound()
{
ServiceTestContext testContext = new ServiceTestContext();
var resources = new List<IAzureSqlServerResource>
@@ -258,7 +258,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateThrowExceptionIfResourcesIsEmpty()
public void CreateThrowExceptionIfResourcesIsEmpty()
{
ServiceTestContext testContext = new ServiceTestContext();
@@ -269,7 +269,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
}
[Test]
public async Task CreateShouldThrowExceptionIfThereIsNoSubscriptionForUser()
public void CreateShouldThrowExceptionIfThereIsNoSubscriptionForUser()
{
ServiceTestContext testContext = new ServiceTestContext();
testContext.Subscriptions = new List<IAzureUserAccountSubscriptionContext>();
@@ -281,7 +281,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ResourceProvider
[Test]
public async Task CreateShouldThrowExceptionIfSubscriptionIsInAnotherAccount()
public void CreateShouldThrowExceptionIfSubscriptionIsInAnotherAccount()
{
ServiceTestContext testContext = new ServiceTestContext();
testContext.Subscriptions = new List<IAzureUserAccountSubscriptionContext>