mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-17 02:51:45 -05:00
Use a concurrent dict when mocking file stream factory (#465)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
||||||
@@ -12,17 +13,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
|||||||
|
|
||||||
public static IFileStreamFactory GetFileStreamFactory()
|
public static IFileStreamFactory GetFileStreamFactory()
|
||||||
{
|
{
|
||||||
return GetFileStreamFactory(new Dictionary<string, byte[]>());
|
return GetFileStreamFactory(new ConcurrentDictionary<string, byte[]>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IFileStreamFactory GetFileStreamFactory(Dictionary<string, byte[]> storage)
|
public static IFileStreamFactory GetFileStreamFactory(ConcurrentDictionary<string, byte[]> storage)
|
||||||
{
|
{
|
||||||
Mock<IFileStreamFactory> mock = new Mock<IFileStreamFactory>();
|
Mock<IFileStreamFactory> mock = new Mock<IFileStreamFactory>();
|
||||||
mock.Setup(fsf => fsf.CreateFile())
|
mock.Setup(fsf => fsf.CreateFile())
|
||||||
.Returns(() =>
|
.Returns(() =>
|
||||||
{
|
{
|
||||||
string fileName = Guid.NewGuid().ToString();
|
string fileName = Guid.NewGuid().ToString();
|
||||||
storage.Add(fileName, new byte[8192]);
|
storage.TryAdd(fileName, new byte[8192]);
|
||||||
return fileName;
|
return fileName;
|
||||||
});
|
});
|
||||||
mock.Setup(fsf => fsf.GetReader(It.IsAny<string>()))
|
mock.Setup(fsf => fsf.GetReader(It.IsAny<string>()))
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
// Copyright (c) Microsoft. All rights reserved.
|
// Copyright (c) Microsoft. All rights reserved.
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Data;
|
using System.Data;
|
||||||
using System.Data.Common;
|
using System.Data.Common;
|
||||||
@@ -212,10 +213,10 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
|
|
||||||
public static QueryExecutionService GetPrimedExecutionService(TestResultSet[] 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 ConcurrentDictionary<string, byte[]> storage)
|
||||||
{
|
{
|
||||||
// Create a place for the temp "files" to be written
|
// Create a place for the temp "files" to be written
|
||||||
storage = new Dictionary<string, byte[]>();
|
storage = new ConcurrentDictionary<string, byte[]>();
|
||||||
|
|
||||||
// Mock the connection service
|
// Mock the connection service
|
||||||
var connectionService = new Mock<ConnectionService>();
|
var connectionService = new Mock<ConnectionService>();
|
||||||
@@ -231,7 +232,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution
|
|||||||
|
|
||||||
public static QueryExecutionService GetPrimedExecutionService(TestResultSet[] 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;
|
ConcurrentDictionary<string, byte[]> storage;
|
||||||
return GetPrimedExecutionService(data, isConnected, throwOnRead, workspaceService, out storage);
|
return GetPrimedExecutionService(data, isConnected, throwOnRead, workspaceService, out storage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@@ -52,7 +53,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
// Given:
|
// Given:
|
||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
ConcurrentDictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, 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
|
||||||
@@ -97,7 +98,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
// Given:
|
// Given:
|
||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
ConcurrentDictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.ExecutionPlanTestDataSet, 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
|
||||||
@@ -164,7 +165,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
// Given:
|
// Given:
|
||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
ConcurrentDictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, 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
|
||||||
@@ -207,7 +208,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
// Given:
|
// Given:
|
||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
ConcurrentDictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, 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
|
||||||
@@ -273,7 +274,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
// Given:
|
// Given:
|
||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
ConcurrentDictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, 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
|
||||||
@@ -316,7 +317,7 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.QueryExecution.SaveResults
|
|||||||
// Given:
|
// Given:
|
||||||
// ... A working query and workspace service
|
// ... A working query and workspace service
|
||||||
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
WorkspaceService<SqlToolsSettings> ws = Common.GetPrimedWorkspaceService(Constants.StandardQuery);
|
||||||
Dictionary<string, byte[]> storage;
|
ConcurrentDictionary<string, byte[]> storage;
|
||||||
QueryExecutionService qes = Common.GetPrimedExecutionService(Common.StandardTestDataSet, 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
|
||||||
|
|||||||
Reference in New Issue
Block a user