mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Adding TestDbResultSet for Better Mocking (#231)
* Replacing the awful and inflexible Dictionary<string, string>[][] with a much better test data set class * Applying all changes * Removing unused RequestParamTests
This commit is contained in:
@@ -19,10 +19,6 @@ using Microsoft.SqlTools.Test.Utility;
|
|||||||
using Moq;
|
using Moq;
|
||||||
using Moq.Protected;
|
using Moq.Protected;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Test.QueryExecution;
|
|
||||||
using Microsoft.SqlTools.ServiceLayer.Workspace.Contracts;
|
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
||||||
{
|
{
|
||||||
@@ -34,7 +30,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a mock db command that returns a predefined result set
|
/// Creates a mock db command that returns a predefined result set
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static DbCommand CreateTestCommand(Dictionary<string, string>[][] data)
|
public static DbCommand CreateTestCommand(TestResultSet[] data)
|
||||||
{
|
{
|
||||||
var commandMock = new Mock<DbCommand> { CallBase = true };
|
var commandMock = new Mock<DbCommand> { CallBase = true };
|
||||||
var commandMockSetup = commandMock.Protected()
|
var commandMockSetup = commandMock.Protected()
|
||||||
@@ -48,7 +44,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a mock db connection that returns predefined data when queried for a result set
|
/// Creates a mock db connection that returns predefined data when queried for a result set
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DbConnection CreateMockDbConnection(Dictionary<string, string>[][] data)
|
public DbConnection CreateMockDbConnection(TestResultSet[] data)
|
||||||
{
|
{
|
||||||
var connectionMock = new Mock<DbConnection> { CallBase = true };
|
var connectionMock = new Mock<DbConnection> { CallBase = true };
|
||||||
connectionMock.Protected()
|
connectionMock.Protected()
|
||||||
@@ -61,13 +57,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void CanCancelConnectRequest()
|
public void CanCancelConnectRequest()
|
||||||
{
|
{
|
||||||
var testFile = "file:///my/test/file.sql";
|
const string testFile = "file:///my/test/file.sql";
|
||||||
|
|
||||||
// Given a connection that times out and responds to cancellation
|
// Given a connection that times out and responds to cancellation
|
||||||
var mockConnection = new Mock<DbConnection> { CallBase = true };
|
var mockConnection = new Mock<DbConnection> { CallBase = true };
|
||||||
CancellationToken token;
|
CancellationToken token;
|
||||||
bool ready = false;
|
bool ready = false;
|
||||||
mockConnection.Setup(x => x.OpenAsync(Moq.It.IsAny<CancellationToken>()))
|
mockConnection.Setup(x => x.OpenAsync(It.IsAny<CancellationToken>()))
|
||||||
.Callback<CancellationToken>(t =>
|
.Callback<CancellationToken>(t =>
|
||||||
{
|
{
|
||||||
// Pass the token to the return handler and signal the main thread to cancel
|
// Pass the token to the return handler and signal the main thread to cancel
|
||||||
@@ -80,10 +76,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
{
|
{
|
||||||
throw new OperationCanceledException();
|
throw new OperationCanceledException();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var mockFactory = new Mock<ISqlConnectionFactory>();
|
var mockFactory = new Mock<ISqlConnectionFactory>();
|
||||||
@@ -95,15 +88,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
|
|
||||||
// Connect the connection asynchronously in a background thread
|
// Connect the connection asynchronously in a background thread
|
||||||
var connectionDetails = TestObjects.GetTestConnectionDetails();
|
var connectionDetails = TestObjects.GetTestConnectionDetails();
|
||||||
var connectTask = Task.Run(async () =>
|
var connectTask = Task.Run(async () => await connectionService
|
||||||
{
|
.Connect(new ConnectParams
|
||||||
return await connectionService
|
|
||||||
.Connect(new ConnectParams()
|
|
||||||
{
|
{
|
||||||
OwnerUri = testFile,
|
OwnerUri = testFile,
|
||||||
Connection = connectionDetails
|
Connection = connectionDetails
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
// Wait for the connection to call OpenAsync()
|
// Wait for the connection to call OpenAsync()
|
||||||
Assert.True(TestUtils.WaitFor(() => ready));
|
Assert.True(TestUtils.WaitFor(() => ready));
|
||||||
@@ -128,13 +118,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
[Fact]
|
[Fact]
|
||||||
public async Task CanCancelConnectRequestByConnecting()
|
public async Task CanCancelConnectRequestByConnecting()
|
||||||
{
|
{
|
||||||
var testFile = "file:///my/test/file.sql";
|
const string testFile = "file:///my/test/file.sql";
|
||||||
|
|
||||||
// Given a connection that times out and responds to cancellation
|
// Given a connection that times out and responds to cancellation
|
||||||
var mockConnection = new Mock<DbConnection> { CallBase = true };
|
var mockConnection = new Mock<DbConnection> { CallBase = true };
|
||||||
CancellationToken token;
|
CancellationToken token;
|
||||||
bool ready = false;
|
bool ready = false;
|
||||||
mockConnection.Setup(x => x.OpenAsync(Moq.It.IsAny<CancellationToken>()))
|
mockConnection.Setup(x => x.OpenAsync(It.IsAny<CancellationToken>()))
|
||||||
.Callback<CancellationToken>(t =>
|
.Callback<CancellationToken>(t =>
|
||||||
{
|
{
|
||||||
// Pass the token to the return handler and signal the main thread to cancel
|
// Pass the token to the return handler and signal the main thread to cancel
|
||||||
@@ -147,15 +137,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
{
|
{
|
||||||
throw new OperationCanceledException();
|
throw new OperationCanceledException();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Given a second connection that succeeds
|
// Given a second connection that succeeds
|
||||||
var mockConnection2 = new Mock<DbConnection> { CallBase = true };
|
var mockConnection2 = new Mock<DbConnection> { CallBase = true };
|
||||||
mockConnection2.Setup(x => x.OpenAsync(Moq.It.IsAny<CancellationToken>()))
|
mockConnection2.Setup(x => x.OpenAsync(It.IsAny<CancellationToken>()))
|
||||||
.Returns(() => Task.Run(() => {}));
|
.Returns(() => Task.Run(() => {}));
|
||||||
|
|
||||||
var mockFactory = new Mock<ISqlConnectionFactory>();
|
var mockFactory = new Mock<ISqlConnectionFactory>();
|
||||||
@@ -168,15 +155,12 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
|
|
||||||
// Connect the first connection asynchronously in a background thread
|
// Connect the first connection asynchronously in a background thread
|
||||||
var connectionDetails = TestObjects.GetTestConnectionDetails();
|
var connectionDetails = TestObjects.GetTestConnectionDetails();
|
||||||
var connectTask = Task.Run(async () =>
|
var connectTask = Task.Run(async () => await connectionService
|
||||||
{
|
|
||||||
return await connectionService
|
|
||||||
.Connect(new ConnectParams()
|
.Connect(new ConnectParams()
|
||||||
{
|
{
|
||||||
OwnerUri = testFile,
|
OwnerUri = testFile,
|
||||||
Connection = connectionDetails
|
Connection = connectionDetails
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
// Wait for the connection to call OpenAsync()
|
// Wait for the connection to call OpenAsync()
|
||||||
Assert.True(TestUtils.WaitFor(() => ready));
|
Assert.True(TestUtils.WaitFor(() => ready));
|
||||||
@@ -202,13 +186,13 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
[Fact]
|
[Fact]
|
||||||
public void CanCancelConnectRequestByDisconnecting()
|
public void CanCancelConnectRequestByDisconnecting()
|
||||||
{
|
{
|
||||||
var testFile = "file:///my/test/file.sql";
|
const string testFile = "file:///my/test/file.sql";
|
||||||
|
|
||||||
// Given a connection that times out and responds to cancellation
|
// Given a connection that times out and responds to cancellation
|
||||||
var mockConnection = new Mock<DbConnection> { CallBase = true };
|
var mockConnection = new Mock<DbConnection> { CallBase = true };
|
||||||
CancellationToken token;
|
CancellationToken token;
|
||||||
bool ready = false;
|
bool ready = false;
|
||||||
mockConnection.Setup(x => x.OpenAsync(Moq.It.IsAny<CancellationToken>()))
|
mockConnection.Setup(x => x.OpenAsync(It.IsAny<CancellationToken>()))
|
||||||
.Callback<CancellationToken>(t =>
|
.Callback<CancellationToken>(t =>
|
||||||
{
|
{
|
||||||
// Pass the token to the return handler and signal the main thread to cancel
|
// Pass the token to the return handler and signal the main thread to cancel
|
||||||
@@ -221,10 +205,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
{
|
{
|
||||||
throw new OperationCanceledException();
|
throw new OperationCanceledException();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return Task.FromResult(true);
|
return Task.FromResult(true);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
var mockFactory = new Mock<ISqlConnectionFactory>();
|
var mockFactory = new Mock<ISqlConnectionFactory>();
|
||||||
@@ -236,22 +217,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
|
|
||||||
// Connect the first connection asynchronously in a background thread
|
// Connect the first connection asynchronously in a background thread
|
||||||
var connectionDetails = TestObjects.GetTestConnectionDetails();
|
var connectionDetails = TestObjects.GetTestConnectionDetails();
|
||||||
var connectTask = Task.Run(async () =>
|
var connectTask = Task.Run(async () => await connectionService
|
||||||
{
|
.Connect(new ConnectParams
|
||||||
return await connectionService
|
|
||||||
.Connect(new ConnectParams()
|
|
||||||
{
|
{
|
||||||
OwnerUri = testFile,
|
OwnerUri = testFile,
|
||||||
Connection = connectionDetails
|
Connection = connectionDetails
|
||||||
});
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
// Wait for the connection to call OpenAsync()
|
// Wait for the connection to call OpenAsync()
|
||||||
Assert.True(TestUtils.WaitFor(() => ready));
|
Assert.True(TestUtils.WaitFor(() => ready));
|
||||||
|
|
||||||
// Send a cancellation by trying to disconnect
|
// Send a cancellation by trying to disconnect
|
||||||
var disconnectResult = connectionService
|
var disconnectResult = connectionService
|
||||||
.Disconnect(new DisconnectParams()
|
.Disconnect(new DisconnectParams
|
||||||
{
|
{
|
||||||
OwnerUri = testFile
|
OwnerUri = testFile
|
||||||
});
|
});
|
||||||
@@ -382,16 +360,19 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
public async Task ConnectingWithInvalidCredentialsYieldsErrorMessage()
|
public async Task ConnectingWithInvalidCredentialsYieldsErrorMessage()
|
||||||
{
|
{
|
||||||
var testConnectionDetails = TestObjects.GetTestConnectionDetails();
|
var testConnectionDetails = TestObjects.GetTestConnectionDetails();
|
||||||
var invalidConnectionDetails = new ConnectionDetails();
|
var invalidConnectionDetails = new ConnectionDetails
|
||||||
invalidConnectionDetails.ServerName = testConnectionDetails.ServerName;
|
{
|
||||||
invalidConnectionDetails.DatabaseName = testConnectionDetails.DatabaseName;
|
ServerName = testConnectionDetails.ServerName,
|
||||||
invalidConnectionDetails.UserName = "invalidUsername"; // triggers exception when opening mock connection
|
DatabaseName = testConnectionDetails.DatabaseName,
|
||||||
invalidConnectionDetails.Password = "invalidPassword";
|
UserName = "invalidUsername",
|
||||||
|
Password = "invalidPassword"
|
||||||
|
};
|
||||||
|
// triggers exception when opening mock connection
|
||||||
|
|
||||||
// Connect to test db with invalid credentials
|
// Connect to test db with invalid credentials
|
||||||
var connectionResult = await
|
var connectionResult = await
|
||||||
TestObjects.GetTestConnectionService()
|
TestObjects.GetTestConnectionService()
|
||||||
.Connect(new ConnectParams()
|
.Connect(new ConnectParams
|
||||||
{
|
{
|
||||||
OwnerUri = "file://my/sample/file.sql",
|
OwnerUri = "file://my/sample/file.sql",
|
||||||
Connection = invalidConnectionDetails
|
Connection = invalidConnectionDetails
|
||||||
@@ -563,7 +544,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
connectionService.ServiceHost = serviceHostMock.Object;
|
connectionService.ServiceHost = serviceHostMock.Object;
|
||||||
|
|
||||||
// Set up an initial connection
|
// Set up an initial connection
|
||||||
string ownerUri = "file://my/sample/file.sql";
|
const string ownerUri = "file://my/sample/file.sql";
|
||||||
var connectionResult = await
|
var connectionResult = await
|
||||||
connectionService
|
connectionService
|
||||||
.Connect(new ConnectParams()
|
.Connect(new ConnectParams()
|
||||||
@@ -578,11 +559,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
ConnectionInfo info;
|
ConnectionInfo info;
|
||||||
Assert.True(connectionService.TryFindConnection(ownerUri, out info));
|
Assert.True(connectionService.TryFindConnection(ownerUri, out info));
|
||||||
|
|
||||||
// Tell the connection manager that the database change ocurred
|
// Tell the connection manager that the database change occurred
|
||||||
connectionService.ChangeConnectionDatabaseContext(ownerUri, "myOtherDb");
|
connectionService.ChangeConnectionDatabaseContext(ownerUri, "myOtherDb");
|
||||||
|
|
||||||
// Verify that the connection changed event was fired
|
// Verify that the connection changed event was fired
|
||||||
serviceHostMock.Verify(x => x.SendEvent<ConnectionChangedParams>(ConnectionChangedNotification.Type, It.IsAny<ConnectionChangedParams>()), Times.Once());
|
serviceHostMock.Verify(x => x.SendEvent(ConnectionChangedNotification.Type, It.IsAny<ConnectionChangedParams>()), Times.Once());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -606,7 +587,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Verify that we can disconnect from an active connection succesfully
|
/// Verify that we can disconnect from an active connection successfully
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task DisconnectFromDatabaseTest()
|
public async Task DisconnectFromDatabaseTest()
|
||||||
@@ -758,14 +739,16 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
public async Task ListDatabasesOnServerForCurrentConnectionReturnsDatabaseNames()
|
public async Task ListDatabasesOnServerForCurrentConnectionReturnsDatabaseNames()
|
||||||
{
|
{
|
||||||
// Result set for the query of database names
|
// Result set for the query of database names
|
||||||
Dictionary<string, string>[] data =
|
TestDbColumn[] cols = {new TestDbColumn("name")};
|
||||||
|
object[][] rows =
|
||||||
{
|
{
|
||||||
new Dictionary<string, string> { {"name", "master" } },
|
new object[] {"master"},
|
||||||
new Dictionary<string, string> { {"name", "model" } },
|
new object[] {"model"},
|
||||||
new Dictionary<string, string> { {"name", "msdb" } },
|
new object[] {"msdb"},
|
||||||
new Dictionary<string, string> { {"name", "tempdb" } },
|
new object[] {"tempdb"},
|
||||||
new Dictionary<string, string> { {"name", "mydatabase" } },
|
new object[] {"mydatabase"}
|
||||||
};
|
};
|
||||||
|
TestResultSet data = new TestResultSet(cols, rows);
|
||||||
|
|
||||||
// Setup mock connection factory to inject query results
|
// Setup mock connection factory to inject query results
|
||||||
var mockFactory = new Mock<ISqlConnectionFactory>();
|
var mockFactory = new Mock<ISqlConnectionFactory>();
|
||||||
@@ -787,8 +770,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
Assert.NotEmpty(connectionResult.ConnectionId);
|
Assert.NotEmpty(connectionResult.ConnectionId);
|
||||||
|
|
||||||
// list databases for the connection
|
// list databases for the connection
|
||||||
ListDatabasesParams parameters = new ListDatabasesParams();
|
ListDatabasesParams parameters = new ListDatabasesParams {OwnerUri = ownerUri};
|
||||||
parameters.OwnerUri = ownerUri;
|
|
||||||
var listDatabasesResult = connectionService.ListDatabases(parameters);
|
var listDatabasesResult = connectionService.ListDatabases(parameters);
|
||||||
string[] databaseNames = listDatabasesResult.DatabaseNames;
|
string[] databaseNames = listDatabasesResult.DatabaseNames;
|
||||||
|
|
||||||
@@ -818,7 +800,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
);
|
);
|
||||||
|
|
||||||
// connect to a database instance
|
// connect to a database instance
|
||||||
var connectionResult = await connectionService.Connect(TestObjects.GetTestConnectionParams());
|
await connectionService.Connect(TestObjects.GetTestConnectionParams());
|
||||||
|
|
||||||
// verify that a valid connection id was returned
|
// verify that a valid connection id was returned
|
||||||
Assert.True(callbackInvoked);
|
Assert.True(callbackInvoked);
|
||||||
@@ -869,7 +851,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
|
|
||||||
// verify that a valid connection id was returned
|
// verify that a valid connection id was returned
|
||||||
Assert.NotNull(connectionResult.ConnectionId);
|
Assert.NotNull(connectionResult.ConnectionId);
|
||||||
Assert.NotEqual(String.Empty, connectionResult.ConnectionId);
|
Assert.NotEqual(string.Empty, connectionResult.ConnectionId);
|
||||||
Assert.NotNull(new Guid(connectionResult.ConnectionId));
|
Assert.NotNull(new Guid(connectionResult.ConnectionId));
|
||||||
|
|
||||||
// verify that the (URI -> connection) mapping was created
|
// verify that the (URI -> connection) mapping was created
|
||||||
@@ -885,16 +867,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
/// and remove the code block specific to Linux/OSX.
|
/// and remove the code block specific to Linux/OSX.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
public void TestThatLinuxAndOSXSqlExceptionHasNoErrorCode()
|
public void TestThatLinuxAndOsxSqlExceptionHasNoErrorCode()
|
||||||
{
|
{
|
||||||
TestUtils.RunIfLinuxOrOSX(() =>
|
TestUtils.RunIfLinuxOrOSX(() =>
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder();
|
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder
|
||||||
builder.DataSource = "bad-server-name";
|
{
|
||||||
builder.UserID = "sa";
|
DataSource = "bad-server-name",
|
||||||
builder.Password = "bad password";
|
UserID = "sa",
|
||||||
|
Password = "bad password"
|
||||||
|
};
|
||||||
|
|
||||||
SqlConnection connection = new SqlConnection(builder.ConnectionString);
|
SqlConnection connection = new SqlConnection(builder.ConnectionString);
|
||||||
connection.Open(); // This should fail
|
connection.Open(); // This should fail
|
||||||
@@ -907,7 +891,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
/// <summary>
|
||||||
/// Test that cancel connection with a null connection parameter
|
/// Test that cancel connection with a null connection parameter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -917,7 +901,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
Assert.False(service.CancelConnect(null));
|
Assert.False(service.CancelConnect(null));
|
||||||
}
|
}
|
||||||
|
|
||||||
// <summary>
|
/// <summary>
|
||||||
/// Test that cancel connection with a null connection parameter
|
/// Test that cancel connection with a null connection parameter
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Fact]
|
[Fact]
|
||||||
@@ -941,7 +925,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Test that the connection summary comparer creates a hash code correctly
|
/// Test that the connection summary comparer creates a hash code correctly
|
||||||
/// <summary>
|
/// </summary>
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(true, null, null ,null)]
|
[InlineData(true, null, null ,null)]
|
||||||
[InlineData(false, null, null, null)]
|
[InlineData(false, null, null, null)]
|
||||||
@@ -985,9 +969,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
public void ConnectParamsAreInvalidIfConnectionIsNull()
|
public void ConnectParamsAreInvalidIfConnectionIsNull()
|
||||||
{
|
{
|
||||||
// Given connection parameters where the connection property is null
|
// Given connection parameters where the connection property is null
|
||||||
ConnectParams parameters = new ConnectParams();
|
ConnectParams parameters = new ConnectParams
|
||||||
parameters.OwnerUri = "my/sql/file.sql";
|
{
|
||||||
parameters.Connection = null;
|
OwnerUri = "my/sql/file.sql",
|
||||||
|
Connection = null
|
||||||
|
};
|
||||||
|
|
||||||
string errorMessage;
|
string errorMessage;
|
||||||
|
|
||||||
@@ -1044,11 +1030,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
await service.Connect(connectParamsDifferent);
|
await service.Connect(connectParamsDifferent);
|
||||||
Assert.Equal(2, ownerToConnectionMap.Count);
|
Assert.Equal(2, ownerToConnectionMap.Count);
|
||||||
|
|
||||||
// If we disconenct with the unique URI, there should be 1 connection
|
// If we disconnect with the unique URI, there should be 1 connection
|
||||||
service.Disconnect(disconnectParamsDifferent);
|
service.Disconnect(disconnectParamsDifferent);
|
||||||
Assert.Equal(1, ownerToConnectionMap.Count);
|
Assert.Equal(1, ownerToConnectionMap.Count);
|
||||||
|
|
||||||
// If we disconenct with the duplicate URI, there should be 0 connections
|
// If we disconnect with the duplicate URI, there should be 0 connections
|
||||||
service.Disconnect(disconnectParamsSame);
|
service.Disconnect(disconnectParamsSame);
|
||||||
Assert.Equal(0, ownerToConnectionMap.Count);
|
Assert.Equal(0, ownerToConnectionMap.Count);
|
||||||
}
|
}
|
||||||
@@ -1138,7 +1124,6 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
|
|||||||
|
|
||||||
// If I connect a Default and a Query connection
|
// If I connect a Default and a Query connection
|
||||||
var service = TestObjects.GetTestConnectionService();
|
var service = TestObjects.GetTestConnectionService();
|
||||||
Dictionary<string, ConnectionInfo> ownerToConnectionMap = service.OwnerToConnectionMap;
|
|
||||||
await service.Connect(connectParamsDefault);
|
await service.Connect(connectParamsDefault);
|
||||||
await service.Connect(connectParamsQuery);
|
await service.Connect(connectParamsQuery);
|
||||||
ConnectionInfo connectionInfo = service.OwnerToConnectionMap[connectParamsDefault.OwnerUri];
|
ConnectionInfo connectionInfo = service.OwnerToConnectionMap[connectParamsDefault.OwnerUri];
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using System.Collections.Generic;
|
|||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
@@ -59,9 +60,18 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public static Dictionary<string, string>[] StandardTestData
|
public static TestResultSet StandardTestResultSet => new TestResultSet(StandardColumns, StandardRows);
|
||||||
|
|
||||||
|
public static TestResultSet[] StandardTestDataSet => new[] {StandardTestResultSet};
|
||||||
|
|
||||||
|
public static TestResultSet[] ExecutionPlanTestDataSet
|
||||||
{
|
{
|
||||||
get { return GetTestData(StandardRows, StandardColumns); }
|
get
|
||||||
|
{
|
||||||
|
DbColumn[] columns = { new TestDbColumn("Microsoft SQL Server 2005 XML Showplan") };
|
||||||
|
object[][] rows = { new object[] { "Execution Plan" } };
|
||||||
|
return new[] {new TestResultSet(columns, rows)};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Public Methods
|
#region Public Methods
|
||||||
@@ -69,20 +79,20 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
public static Batch GetBasicExecutedBatch()
|
public static Batch GetBasicExecutedBatch()
|
||||||
{
|
{
|
||||||
Batch batch = new Batch(StandardQuery, SubsectionDocument, 1, GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
Batch batch = new Batch(StandardQuery, SubsectionDocument, 1, GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
||||||
batch.Execute(CreateTestConnection(new[] {StandardTestData}, false), CancellationToken.None).Wait();
|
batch.Execute(CreateTestConnection(StandardTestDataSet, false), CancellationToken.None).Wait();
|
||||||
return batch;
|
return batch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Batch GetExecutedBatchWithExecutionPlan()
|
public static Batch GetExecutedBatchWithExecutionPlan()
|
||||||
{
|
{
|
||||||
Batch batch = new Batch(StandardQuery, SubsectionDocument, 1, GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
Batch batch = new Batch(StandardQuery, SubsectionDocument, 1, GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
||||||
batch.Execute(CreateTestConnection(new[] {GetExecutionPlanTestData()}, false), CancellationToken.None).Wait();
|
batch.Execute(CreateTestConnection(ExecutionPlanTestDataSet, false), CancellationToken.None).Wait();
|
||||||
return batch;
|
return batch;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Query GetBasicExecutedQuery()
|
public static Query GetBasicExecutedQuery()
|
||||||
{
|
{
|
||||||
ConnectionInfo ci = CreateTestConnectionInfo(new[] {StandardTestData}, false);
|
ConnectionInfo ci = CreateTestConnectionInfo(StandardTestDataSet, false);
|
||||||
|
|
||||||
// Query won't be able to request a new query DbConnection unless the ConnectionService has a
|
// Query won't be able to request a new query DbConnection unless the ConnectionService has a
|
||||||
// ConnectionInfo with the same URI as the query, so we will manually set it
|
// ConnectionInfo with the same URI as the query, so we will manually set it
|
||||||
@@ -96,7 +106,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
public static Query GetBasicExecutedQuery(QueryExecutionSettings querySettings)
|
public static Query GetBasicExecutedQuery(QueryExecutionSettings querySettings)
|
||||||
{
|
{
|
||||||
ConnectionInfo ci = CreateTestConnectionInfo(new[] {StandardTestData}, false);
|
ConnectionInfo ci = CreateTestConnectionInfo(StandardTestDataSet, false);
|
||||||
|
|
||||||
// Query won't be able to request a new query DbConnection unless the ConnectionService has a
|
// Query won't be able to request a new query DbConnection unless the ConnectionService has a
|
||||||
// ConnectionInfo with the same URI as the query, so we will manually set it
|
// ConnectionInfo with the same URI as the query, so we will manually set it
|
||||||
@@ -108,43 +118,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Dictionary<string, string>[] GetTestData(int columns, int rows)
|
public static TestResultSet[] GetTestDataSet(int dataSets)
|
||||||
{
|
{
|
||||||
Dictionary<string, string>[] output = new Dictionary<string, string>[rows];
|
return Enumerable.Repeat(StandardTestResultSet, dataSets).ToArray();
|
||||||
for (int row = 0; row < rows; row++)
|
|
||||||
{
|
|
||||||
Dictionary<string, string> rowDictionary = new Dictionary<string, string>();
|
|
||||||
for (int column = 0; column < columns; column++)
|
|
||||||
{
|
|
||||||
rowDictionary.Add(string.Format("column{0}", column), string.Format("val{0}{1}", column, row));
|
|
||||||
}
|
|
||||||
output[row] = rowDictionary;
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static Dictionary<string, string>[] GetExecutionPlanTestData()
|
|
||||||
{
|
|
||||||
Dictionary<string, string>[] output = new Dictionary<string, string>[1];
|
|
||||||
int col = 0;
|
|
||||||
int row = 0;
|
|
||||||
Dictionary<string, string> rowDictionary = new Dictionary<string, string>();
|
|
||||||
rowDictionary.Add(string.Format("Microsoft SQL Server 2005 XML Showplan", col), string.Format("Execution Plan", col, row));
|
|
||||||
output[row] = rowDictionary;
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Dictionary<string, string>[][] GetTestDataSet(int dataSets)
|
|
||||||
{
|
|
||||||
List<Dictionary<string, string>[]> output = new List<Dictionary<string, string>[]>();
|
|
||||||
for(int dataSet = 0; dataSet < dataSets; dataSet++)
|
|
||||||
{
|
|
||||||
output.Add(StandardTestData);
|
|
||||||
}
|
|
||||||
return output.ToArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task AwaitExecution(QueryExecutionService service, ExecuteDocumentSelectionParams qeParams,
|
public static async Task AwaitExecution(QueryExecutionService service, ExecuteDocumentSelectionParams qeParams,
|
||||||
@@ -183,7 +159,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
#region DbConnection Mocking
|
#region DbConnection Mocking
|
||||||
|
|
||||||
public static DbCommand CreateTestCommand(Dictionary<string, string>[][] data, bool throwOnRead)
|
public static DbCommand CreateTestCommand(TestResultSet[] data, bool throwOnRead)
|
||||||
{
|
{
|
||||||
var commandMock = new Mock<DbCommand> { CallBase = true };
|
var commandMock = new Mock<DbCommand> { CallBase = true };
|
||||||
var commandMockSetup = commandMock.Protected()
|
var commandMockSetup = commandMock.Protected()
|
||||||
@@ -205,7 +181,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
return commandMock.Object;
|
return commandMock.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DbConnection CreateTestConnection(Dictionary<string, string>[][] data, bool throwOnRead)
|
public static DbConnection CreateTestConnection(TestResultSet[] data, bool throwOnRead)
|
||||||
{
|
{
|
||||||
var connectionMock = new Mock<DbConnection> { CallBase = true };
|
var connectionMock = new Mock<DbConnection> { CallBase = true };
|
||||||
connectionMock.Protected()
|
connectionMock.Protected()
|
||||||
@@ -219,7 +195,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
return connectionMock.Object;
|
return connectionMock.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ISqlConnectionFactory CreateMockFactory(Dictionary<string, string>[][] data, bool throwOnRead)
|
public static ISqlConnectionFactory CreateMockFactory(TestResultSet[] data, bool throwOnRead)
|
||||||
{
|
{
|
||||||
var mockFactory = new Mock<ISqlConnectionFactory>();
|
var mockFactory = new Mock<ISqlConnectionFactory>();
|
||||||
mockFactory.Setup(factory => factory.CreateSqlConnection(It.IsAny<string>()))
|
mockFactory.Setup(factory => factory.CreateSqlConnection(It.IsAny<string>()))
|
||||||
@@ -228,21 +204,21 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
return mockFactory.Object;
|
return mockFactory.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectionInfo CreateTestConnectionInfo(Dictionary<string, string>[][] data, bool throwOnRead)
|
public static ConnectionInfo CreateTestConnectionInfo(TestResultSet[] data, bool throwOnRead)
|
||||||
{
|
{
|
||||||
return new ConnectionInfo(CreateMockFactory(data, throwOnRead), OwnerUri, StandardConnectionDetails);
|
return new ConnectionInfo(CreateMockFactory(data, throwOnRead), OwnerUri, StandardConnectionDetails);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConnectionInfo CreateConnectedConnectionInfo(Dictionary<string, string>[][] data, bool throwOnRead, string type = ConnectionType.Default)
|
public static ConnectionInfo CreateConnectedConnectionInfo(TestResultSet[] data, bool throwOnRead, string type = ConnectionType.Default)
|
||||||
{
|
{
|
||||||
ConnectionService connectionService = ConnectionService.Instance;
|
ConnectionService connectionService = ConnectionService.Instance;
|
||||||
connectionService.OwnerToConnectionMap.Clear();
|
connectionService.OwnerToConnectionMap.Clear();
|
||||||
connectionService.ConnectionFactory = CreateMockFactory(data, throwOnRead);
|
connectionService.ConnectionFactory = CreateMockFactory(data, throwOnRead);
|
||||||
|
|
||||||
ConnectParams connectParams = new ConnectParams()
|
ConnectParams connectParams = new ConnectParams
|
||||||
{
|
{
|
||||||
Connection = StandardConnectionDetails,
|
Connection = StandardConnectionDetails,
|
||||||
OwnerUri = Common.OwnerUri,
|
OwnerUri = OwnerUri,
|
||||||
Type = type
|
Type = type
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -254,7 +230,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
#region Service Mocking
|
#region Service Mocking
|
||||||
|
|
||||||
public static QueryExecutionService GetPrimedExecutionService(Dictionary<string, string>[][] data,
|
public static QueryExecutionService GetPrimedExecutionService(TestResultSet[] data,
|
||||||
bool isConnected, bool throwOnRead, WorkspaceService<SqlToolsSettings> workspaceService,
|
bool isConnected, bool throwOnRead, WorkspaceService<SqlToolsSettings> workspaceService,
|
||||||
out Dictionary<string, byte[]> storage)
|
out Dictionary<string, byte[]> storage)
|
||||||
{
|
{
|
||||||
@@ -273,7 +249,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
return new QueryExecutionService(connectionService.Object, workspaceService) { BufferFileStreamFactory = GetFileStreamFactory(storage) };
|
return new QueryExecutionService(connectionService.Object, workspaceService) { BufferFileStreamFactory = GetFileStreamFactory(storage) };
|
||||||
}
|
}
|
||||||
|
|
||||||
public static QueryExecutionService GetPrimedExecutionService(Dictionary<string, string>[][] data, bool isConnected, bool throwOnRead, WorkspaceService<SqlToolsSettings> workspaceService)
|
public static QueryExecutionService GetPrimedExecutionService(TestResultSet[] data, bool isConnected, bool throwOnRead, WorkspaceService<SqlToolsSettings> workspaceService)
|
||||||
{
|
{
|
||||||
Dictionary<string, byte[]> storage;
|
Dictionary<string, byte[]> storage;
|
||||||
return GetPrimedExecutionService(data, isConnected, throwOnRead, workspaceService, out storage);
|
return GetPrimedExecutionService(data, isConnected, throwOnRead, workspaceService, out storage);
|
||||||
|
|||||||
@@ -29,6 +29,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
this.DataTypeName = dataTypeName;
|
this.DataTypeName = dataTypeName;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.DataTypeName = "int";
|
||||||
|
this.DataType = typeof(int);
|
||||||
|
}
|
||||||
|
|
||||||
if (columnSize.HasValue)
|
if (columnSize.HasValue)
|
||||||
{
|
{
|
||||||
@@ -63,6 +68,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// check various properties are either null or not null
|
// check various properties are either null or not null
|
||||||
var column = new TestColumn();
|
var column = new TestColumn();
|
||||||
var wrapper = new DbColumnWrapper(column);
|
var wrapper = new DbColumnWrapper(column);
|
||||||
|
Assert.NotNull(wrapper.DataTypeName);
|
||||||
Assert.NotNull(wrapper.DataType);
|
Assert.NotNull(wrapper.DataType);
|
||||||
Assert.Null(wrapper.AllowDBNull);
|
Assert.Null(wrapper.AllowDBNull);
|
||||||
Assert.Null(wrapper.BaseCatalogName);
|
Assert.Null(wrapper.BaseCatalogName);
|
||||||
@@ -77,12 +83,11 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
Assert.Null(wrapper.IsHidden);
|
Assert.Null(wrapper.IsHidden);
|
||||||
Assert.Null(wrapper.IsIdentity);
|
Assert.Null(wrapper.IsIdentity);
|
||||||
Assert.Null(wrapper.IsKey);
|
Assert.Null(wrapper.IsKey);
|
||||||
Assert.Null(wrapper. IsReadOnly);
|
Assert.Null(wrapper.IsReadOnly);
|
||||||
Assert.Null(wrapper.IsUnique);
|
Assert.Null(wrapper.IsUnique);
|
||||||
Assert.Null(wrapper.NumericPrecision);
|
Assert.Null(wrapper.NumericPrecision);
|
||||||
Assert.Null(wrapper.NumericScale);
|
Assert.Null(wrapper.NumericScale);
|
||||||
Assert.Null(wrapper.UdtAssemblyQualifiedName);
|
Assert.Null(wrapper.UdtAssemblyQualifiedName);
|
||||||
Assert.Null(wrapper.DataTypeName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -6,11 +6,13 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.SqlTools.ServiceLayer.Connection;
|
using Microsoft.SqlTools.ServiceLayer.Connection;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
||||||
@@ -63,7 +65,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a new resultset with a valid db data reader that has data
|
// ... I create a new resultset with a valid db data reader that has data
|
||||||
// ... and I read it to the end
|
// ... and I read it to the end
|
||||||
DbDataReader mockReader = GetReader(new [] {Common.StandardTestData}, false, Common.StandardQuery);
|
DbDataReader mockReader = GetReader(Common.StandardTestDataSet, false, Common.StandardQuery);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||||
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
||||||
resultSet.ResultCompletion += callback;
|
resultSet.ResultCompletion += callback;
|
||||||
@@ -92,13 +94,9 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
{
|
{
|
||||||
// Setup:
|
// Setup:
|
||||||
// ... Build a FOR XML or FOR JSON data set
|
// ... Build a FOR XML or FOR JSON data set
|
||||||
string columnName = string.Format("{0}_F52E2B61-18A1-11d1-B105-00805F49916B", forType);
|
DbColumn[] columns = {new TestDbColumn(string.Format("{0}_F52E2B61-18A1-11d1-B105-00805F49916B", forType))};
|
||||||
List<Dictionary<string, string>> data = new List<Dictionary<string, string>>();
|
object[][] rows = Enumerable.Repeat(new object[] {"test data"}, Common.StandardRows).ToArray();
|
||||||
for(int i = 0; i < Common.StandardRows; i++)
|
TestResultSet[] dataSets = {new TestResultSet(columns, rows) };
|
||||||
{
|
|
||||||
data.Add(new Dictionary<string, string> { { columnName, "test data"} });
|
|
||||||
}
|
|
||||||
Dictionary<string, string>[][] dataSets = {data.ToArray()};
|
|
||||||
|
|
||||||
// ... Create a callback for resultset completion
|
// ... Create a callback for resultset completion
|
||||||
ResultSetSummary resultSummary = null;
|
ResultSetSummary resultSummary = null;
|
||||||
@@ -158,7 +156,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a new result set with a valid db data reader
|
// ... I create a new result set with a valid db data reader
|
||||||
// ... And execute the result
|
// ... And execute the result
|
||||||
DbDataReader mockReader = GetReader(new[] {Common.StandardTestData}, false, Common.StandardQuery);
|
DbDataReader mockReader = GetReader(Common.StandardTestDataSet, false, Common.StandardQuery);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||||
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
||||||
await resultSet.ReadResultToEnd(CancellationToken.None);
|
await resultSet.ReadResultToEnd(CancellationToken.None);
|
||||||
@@ -179,7 +177,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I create a new result set with a valid db data reader
|
// ... I create a new result set with a valid db data reader
|
||||||
// ... And execute the result set
|
// ... And execute the result set
|
||||||
DbDataReader mockReader = GetReader(new[] { Common.StandardTestData }, false, Common.StandardQuery);
|
DbDataReader mockReader = GetReader(Common.StandardTestDataSet, false, Common.StandardQuery);
|
||||||
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
var fileStreamFactory = Common.GetFileStreamFactory(new Dictionary<string, byte[]>());
|
||||||
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
ResultSet resultSet = new ResultSet(mockReader, Common.Ordinal, Common.Ordinal, fileStreamFactory);
|
||||||
await resultSet.ReadResultToEnd(CancellationToken.None);
|
await resultSet.ReadResultToEnd(CancellationToken.None);
|
||||||
@@ -197,7 +195,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
Assert.Equal(resultSet.Columns.Length, subset.Rows[0].Length);
|
Assert.Equal(resultSet.Columns.Length, subset.Rows[0].Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DbDataReader GetReader(Dictionary<string, string>[][] dataSet, bool throwOnRead, string query)
|
private static DbDataReader GetReader(TestResultSet[] dataSet, bool throwOnRead, string query)
|
||||||
{
|
{
|
||||||
var info = Common.CreateTestConnectionInfo(dataSet, throwOnRead);
|
var info = Common.CreateTestConnectionInfo(dataSet, throwOnRead);
|
||||||
var connection = info.Factory.CreateSqlConnection(ConnectionService.BuildConnectionString(info.ConnectionDetails));
|
var connection = info.Factory.CreateSqlConnection(ConnectionService.BuildConnectionString(info.ConnectionDetails));
|
||||||
|
|||||||
@@ -217,7 +217,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I request to execute a valid query with results
|
// ... I request to execute a valid query with results
|
||||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(new[] {Common.StandardTestData}, true, false,
|
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false,
|
||||||
workspaceService);
|
workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||||
|
|
||||||
@@ -245,7 +245,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I request to execute a valid query with one batch and multiple result sets
|
// ... I request to execute a valid query with one batch and multiple result sets
|
||||||
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
var workspaceService = GetDefaultWorkspaceService(Common.StandardQuery);
|
||||||
var dataset = new[] {Common.StandardTestData, Common.StandardTestData};
|
var dataset = new[] {Common.StandardTestResultSet, Common.StandardTestResultSet};
|
||||||
var queryService = Common.GetPrimedExecutionService(dataset, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(dataset, true, false, workspaceService);
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||||
|
|
||||||
@@ -273,8 +273,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.Execution
|
|||||||
// If:
|
// If:
|
||||||
// ... I request a to execute a valid query with multiple batches
|
// ... I request a to execute a valid query with multiple batches
|
||||||
var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Common.StandardQuery));
|
var workspaceService = GetDefaultWorkspaceService(string.Format("{0}\r\nGO\r\n{0}", Common.StandardQuery));
|
||||||
var dataSet = new[] {Common.StandardTestData};
|
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, workspaceService);
|
||||||
var queryService = Common.GetPrimedExecutionService(dataSet, true, false, workspaceService);
|
|
||||||
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
var queryParams = new ExecuteDocumentSelectionParams { OwnerUri = Common.OwnerUri, QuerySelection = Common.WholeDocument};
|
||||||
|
|
||||||
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
var efv = new EventFlowValidator<ExecuteRequestResult>()
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
// If:
|
// If:
|
||||||
// ... I have a query that has results in the form of an execution plan
|
// ... I have a query that has results in the form of an execution plan
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(new[] {Common.GetExecutionPlanTestData()}, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams
|
var executeParams = new ExecuteDocumentSelectionParams
|
||||||
{
|
{
|
||||||
QuerySelection = null,
|
QuerySelection = null,
|
||||||
@@ -185,7 +185,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
// If:
|
// If:
|
||||||
// ... I have a query that hasn't finished executing (doesn't matter what)
|
// ... I have a query that hasn't finished executing (doesn't matter what)
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(new[] { Common.GetExecutionPlanTestData() }, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams
|
var executeParams = new ExecuteDocumentSelectionParams
|
||||||
{
|
{
|
||||||
QuerySelection = null,
|
QuerySelection = null,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using Microsoft.SqlTools.ServiceLayer.Connection;
|
|||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
|
using Microsoft.SqlTools.ServiceLayer.Test.Utility;
|
||||||
using Moq;
|
using Moq;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
@@ -66,7 +67,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// Setup:
|
// Setup:
|
||||||
// ... Create a result set that has been executed
|
// ... Create a result set that has been executed
|
||||||
ResultSet rs = new ResultSet(
|
ResultSet rs = new ResultSet(
|
||||||
GetReader(new[] { Common.StandardTestData }, false, Common.StandardQuery),
|
GetReader(Common.StandardTestDataSet, false, Common.StandardQuery),
|
||||||
Common.Ordinal, Common.Ordinal,
|
Common.Ordinal, Common.Ordinal,
|
||||||
Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
Common.GetFileStreamFactory(new Dictionary<string, byte[]>()));
|
||||||
|
|
||||||
@@ -93,7 +94,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
|
|
||||||
// ... Create a result set with dummy data and read to the end
|
// ... Create a result set with dummy data and read to the end
|
||||||
ResultSet rs = new ResultSet(
|
ResultSet rs = new ResultSet(
|
||||||
GetReader(new[] {Common.StandardTestData}, false, Common.StandardQuery),
|
GetReader(Common.StandardTestDataSet, false, Common.StandardQuery),
|
||||||
Common.Ordinal, Common.Ordinal,
|
Common.Ordinal, Common.Ordinal,
|
||||||
resultFactory);
|
resultFactory);
|
||||||
await rs.ReadResultToEnd(CancellationToken.None);
|
await rs.ReadResultToEnd(CancellationToken.None);
|
||||||
@@ -129,7 +130,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
|
|
||||||
// ... Create a result set with dummy data and read to the end
|
// ... Create a result set with dummy data and read to the end
|
||||||
ResultSet rs = new ResultSet(
|
ResultSet rs = new ResultSet(
|
||||||
GetReader(new[] { Common.StandardTestData }, false, Common.StandardQuery),
|
GetReader(Common.StandardTestDataSet, false, Common.StandardQuery),
|
||||||
Common.Ordinal, Common.Ordinal,
|
Common.Ordinal, Common.Ordinal,
|
||||||
resultFactory);
|
resultFactory);
|
||||||
await rs.ReadResultToEnd(CancellationToken.None);
|
await rs.ReadResultToEnd(CancellationToken.None);
|
||||||
@@ -178,7 +179,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
return mockFactory.Object;
|
return mockFactory.Object;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DbDataReader GetReader(Dictionary<string, string>[][] dataSet, bool throwOnRead, string query)
|
private static DbDataReader GetReader(TestResultSet[] dataSet, bool throwOnRead, string query)
|
||||||
{
|
{
|
||||||
var info = Common.CreateTestConnectionInfo(dataSet, throwOnRead);
|
var info = Common.CreateTestConnectionInfo(dataSet, throwOnRead);
|
||||||
var connection = info.Factory.CreateSqlConnection(ConnectionService.BuildConnectionString(info.ConnectionDetails));
|
var connection = info.Factory.CreateSqlConnection(ConnectionService.BuildConnectionString(info.ConnectionDetails));
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
Dictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(new[] {Common.StandardTestData}, true, false, ws, out storage);
|
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, ws, out storage);
|
||||||
|
|
||||||
// ... The query execution service has executed a query with results
|
// ... The query execution service has executed a query with results
|
||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||||
@@ -103,7 +103,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
Dictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(new[] {Common.StandardTestData}, true, false, ws, out storage);
|
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, ws, out storage);
|
||||||
|
|
||||||
// ... The query execution service has executed a query with results
|
// ... The query execution service has executed a query with results
|
||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
||||||
@@ -174,7 +174,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
Dictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(new[] { Common.StandardTestData }, true, false, ws, out storage);
|
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, ws, out storage);
|
||||||
|
|
||||||
// ... The query execution service has executed a query with results
|
// ... The query execution service has executed a query with results
|
||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||||
@@ -220,7 +220,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution.SaveResults
|
|||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
Dictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(new[] { Common.StandardTestData }, true, false, ws, out storage);
|
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, ws, out storage);
|
||||||
|
|
||||||
// ... The query execution service has executed a query with results
|
// ... The query execution service has executed a query with results
|
||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// ... I should get the requested number of rows back
|
// ... I should get the requested number of rows back
|
||||||
Assert.Equal(Math.Min(rowCount, Common.StandardTestData.Length), subset.RowCount);
|
Assert.Equal(Math.Min(rowCount, Common.StandardTestResultSet.Count()), subset.RowCount);
|
||||||
Assert.Equal(Math.Min(rowCount, Common.StandardTestData.Length), subset.Rows.Length);
|
Assert.Equal(Math.Min(rowCount, Common.StandardTestResultSet.Count()), subset.Rows.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@@ -85,8 +85,8 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
|
|
||||||
// Then:
|
// Then:
|
||||||
// I should get the requested number of rows
|
// I should get the requested number of rows
|
||||||
Assert.Equal(Math.Min(rowCount, Common.StandardTestData.Length), subset.RowCount);
|
Assert.Equal(Math.Min(rowCount, Common.StandardTestResultSet.Count()), subset.RowCount);
|
||||||
Assert.Equal(Math.Min(rowCount, Common.StandardTestData.Length), subset.Rows.Length);
|
Assert.Equal(Math.Min(rowCount, Common.StandardTestResultSet.Count()), subset.Rows.Length);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
@@ -131,7 +131,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
// If:
|
// If:
|
||||||
// ... I have a query that has results (doesn't matter what)
|
// ... I have a query that has results (doesn't matter what)
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(new[] {Common.StandardTestData}, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
var executeParams = new ExecuteDocumentSelectionParams {QuerySelection = null, OwnerUri = Common.OwnerUri};
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
@@ -175,7 +175,7 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.QueryExecution
|
|||||||
// If:
|
// If:
|
||||||
// ... I have a query that hasn't finished executing (doesn't matter what)
|
// ... I have a query that hasn't finished executing (doesn't matter what)
|
||||||
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
var workspaceService = Common.GetPrimedWorkspaceService(Common.StandardQuery);
|
||||||
var queryService = Common.GetPrimedExecutionService(new[] { Common.StandardTestData }, true, false, workspaceService);
|
var queryService = Common.GetPrimedExecutionService(Common.StandardTestDataSet, true, false, workspaceService);
|
||||||
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
var executeParams = new ExecuteDocumentSelectionParams { QuerySelection = null, OwnerUri = Common.OwnerUri };
|
||||||
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
var executeRequest = RequestContextMocks.Create<ExecuteRequestResult>(null);
|
||||||
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
await queryService.HandleExecuteRequest(executeParams, executeRequest.Object);
|
||||||
|
|||||||
@@ -16,100 +16,116 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
|||||||
|
|
||||||
#region Test Specific Implementations
|
#region Test Specific Implementations
|
||||||
|
|
||||||
private Dictionary<string, string>[][] Data { get; set; }
|
private IEnumerable<TestResultSet> Data { get; }
|
||||||
|
|
||||||
public IEnumerator<Dictionary<string, string>[]> ResultSet { get; private set; }
|
public IEnumerator<TestResultSet> ResultSetEnumerator { get; }
|
||||||
|
|
||||||
private IEnumerator<Dictionary<string, string>> Rows { get; set; }
|
private IEnumerator<object[]> RowEnumerator { get; set; }
|
||||||
|
|
||||||
public TestDbDataReader(Dictionary<string, string>[][] data)
|
public TestDbDataReader(IEnumerable<TestResultSet> data)
|
||||||
{
|
{
|
||||||
Data = data;
|
Data = data;
|
||||||
if (Data != null)
|
if (Data != null)
|
||||||
{
|
{
|
||||||
ResultSet = ((IEnumerable<Dictionary<string, string>[]>) Data).GetEnumerator();
|
ResultSetEnumerator = Data.GetEnumerator();
|
||||||
ResultSet.MoveNext();
|
ResultSetEnumerator.MoveNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public override bool HasRows
|
#region Properties
|
||||||
{
|
|
||||||
get { return ResultSet != null && ResultSet.Current.Length > 0; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public override int FieldCount => ResultSetEnumerator?.Current.Columns.Count ?? 0;
|
||||||
|
|
||||||
|
public override bool HasRows => ResultSetEnumerator?.Current.Rows.Count > 0;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Mimicks the behavior of SqlDbDataReader
|
||||||
|
/// </summary>
|
||||||
|
public override int RecordsAffected => RowEnumerator != null ? -1 : 1;
|
||||||
|
|
||||||
|
public override object this[int ordinal] => RowEnumerator.Current[ordinal];
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Implemented Methods
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// If the row enumerator hasn't been initialized for the current result set, the
|
||||||
|
/// enumerator for the current result set is defined. Increments the enumerator
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>True if tere were more rows, false otherwise</returns>
|
||||||
public override bool Read()
|
public override bool Read()
|
||||||
{
|
{
|
||||||
if (Rows == null)
|
if (RowEnumerator == null)
|
||||||
{
|
{
|
||||||
Rows = ((IEnumerable<Dictionary<string, string>>) ResultSet.Current).GetEnumerator();
|
RowEnumerator = ResultSetEnumerator.Current.GetEnumerator();
|
||||||
}
|
}
|
||||||
return Rows.MoveNext();
|
return RowEnumerator.MoveNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Increments the result set enumerator and initializes the row enumerator
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
public override bool NextResult()
|
public override bool NextResult()
|
||||||
{
|
{
|
||||||
if (Data == null || !ResultSet.MoveNext())
|
if (Data == null || !ResultSetEnumerator.MoveNext())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Rows = ((IEnumerable<Dictionary<string, string>>)ResultSet.Current).GetEnumerator();
|
RowEnumerator = ResultSetEnumerator.Current.GetEnumerator();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the value for the cell of the current row in the given column
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ordinal">Ordinal of the column</param>
|
||||||
|
/// <returns>The object in the cell</returns>
|
||||||
public override object GetValue(int ordinal)
|
public override object GetValue(int ordinal)
|
||||||
{
|
{
|
||||||
return this[ordinal];
|
return this[ordinal];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stores the values of all cells in this row in the given object array
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="values">Destination for all cell values</param>
|
||||||
|
/// <returns>Number of cells in the current row</returns>
|
||||||
public override int GetValues(object[] values)
|
public override int GetValues(object[] values)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < Rows.Current.Count; i++)
|
for (int i = 0; i < RowEnumerator.Current.Count(); i++)
|
||||||
{
|
{
|
||||||
values[i] = this[i];
|
values[i] = this[i];
|
||||||
}
|
}
|
||||||
return Rows.Current.Count;
|
return RowEnumerator.Current.Count();
|
||||||
}
|
|
||||||
|
|
||||||
public override object this[string name]
|
|
||||||
{
|
|
||||||
get { return Rows.Current[name]; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object this[int ordinal]
|
|
||||||
{
|
|
||||||
get { return Rows.Current[Rows.Current.Keys.AsEnumerable().ToArray()[ordinal]]; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public ReadOnlyCollection<DbColumn> GetColumnSchema()
|
|
||||||
{
|
|
||||||
if (ResultSet?.Current == null || ResultSet.Current.Length <= 0)
|
|
||||||
{
|
|
||||||
return new ReadOnlyCollection<DbColumn>(new List<DbColumn>());
|
|
||||||
}
|
|
||||||
|
|
||||||
List<DbColumn> columns = new List<DbColumn>();
|
|
||||||
for (int i = 0; i < ResultSet.Current[0].Count; i++)
|
|
||||||
{
|
|
||||||
columns.Add(new TestDbColumn(ResultSet.Current[0].Keys.ToArray()[i]));
|
|
||||||
}
|
|
||||||
return new ReadOnlyCollection<DbColumn>(columns);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whether or not a given cell in the current row is null
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="ordinal">Ordinal of the column</param>
|
||||||
|
/// <returns>True if the cell is null, false otherwise</returns>
|
||||||
public override bool IsDBNull(int ordinal)
|
public override bool IsDBNull(int ordinal)
|
||||||
{
|
{
|
||||||
return this[ordinal] == null;
|
return this[ordinal] == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int FieldCount { get { return Rows?.Current.Count ?? 0; } }
|
/// <returns>Collection of test columns in the current result set</returns>
|
||||||
|
public ReadOnlyCollection<DbColumn> GetColumnSchema()
|
||||||
public override int RecordsAffected
|
|
||||||
{
|
{
|
||||||
// Mimics the behavior of SqlDataReader
|
if (ResultSetEnumerator?.Current == null || ResultSetEnumerator.Current.Rows.Count <= 0)
|
||||||
get { return Rows != null ? -1 : 1; }
|
{
|
||||||
|
return new ReadOnlyCollection<DbColumn>(new List<DbColumn>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return new ReadOnlyCollection<DbColumn>(ResultSetEnumerator.Current.Columns);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Not Implemented
|
#region Not Implemented
|
||||||
|
|
||||||
public override bool GetBoolean(int ordinal)
|
public override bool GetBoolean(int ordinal)
|
||||||
@@ -207,8 +223,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
|||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int Depth { get; }
|
public override object this[string name]
|
||||||
public override bool IsClosed { get; }
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int Depth { get { throw new NotImplementedException(); } }
|
||||||
|
|
||||||
|
public override bool IsClosed { get { throw new NotImplementedException(); } }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
//
|
||||||
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
//
|
||||||
|
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Data.Common;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Microsoft.SqlTools.ServiceLayer.Test.Utility
|
||||||
|
{
|
||||||
|
public class TestResultSet : IEnumerable<object[]>
|
||||||
|
{
|
||||||
|
public List<DbColumn> Columns;
|
||||||
|
public List<object[]> Rows;
|
||||||
|
|
||||||
|
public TestResultSet(int columns, int rows)
|
||||||
|
{
|
||||||
|
Columns = Enumerable.Range(0, columns).Select(i => new TestDbColumn($"Col{i}")).Cast<DbColumn>().ToList();
|
||||||
|
Rows = new List<object[]>(rows);
|
||||||
|
for (int i = 0; i < rows; i++)
|
||||||
|
{
|
||||||
|
var row = Enumerable.Range(0, columns).Select(j => $"Cell{i}.{j}").Cast<object>().ToArray();
|
||||||
|
Rows.Add(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public TestResultSet(IEnumerable<DbColumn> columns, IEnumerable<object[]> rows)
|
||||||
|
{
|
||||||
|
Columns = new List<DbColumn>(columns);
|
||||||
|
Rows = new List<object[]>(rows);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IEnumerable<object[]> Impementation
|
||||||
|
|
||||||
|
public IEnumerator<object[]> GetEnumerator()
|
||||||
|
{
|
||||||
|
return (IEnumerator<object[]>) Rows.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
using System.Data.SqlClient;
|
using System.Data.SqlClient;
|
||||||
@@ -199,12 +198,12 @@ namespace Microsoft.SqlTools.Test.Utility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TestSqlCommand : DbCommand
|
public class TestSqlCommand : DbCommand
|
||||||
{
|
{
|
||||||
internal TestSqlCommand(Dictionary<string, string>[][] data)
|
internal TestSqlCommand(TestResultSet[] data)
|
||||||
{
|
{
|
||||||
Data = data;
|
Data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Dictionary<string, string>[][] Data { get; set; }
|
internal TestResultSet[] Data { get; set; }
|
||||||
|
|
||||||
public override void Cancel()
|
public override void Cancel()
|
||||||
{
|
{
|
||||||
@@ -251,12 +250,12 @@ namespace Microsoft.SqlTools.Test.Utility
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class TestSqlConnection : DbConnection
|
public class TestSqlConnection : DbConnection
|
||||||
{
|
{
|
||||||
internal TestSqlConnection(Dictionary<string, string>[][] data)
|
internal TestSqlConnection(TestResultSet[] data)
|
||||||
{
|
{
|
||||||
Data = data;
|
Data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Dictionary<string, string>[][] Data { get; set; }
|
internal TestResultSet[] Data { get; set; }
|
||||||
|
|
||||||
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
|
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user