mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
* Make nullable warnings a per file opt-in * Remove unneeded compiler directives * Remove compiler directive for User Data
47 lines
1.8 KiB
C#
47 lines
1.8 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
#nullable disable
|
|
|
|
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts;
|
|
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
|
|
using Microsoft.SqlTools.ServiceLayer.SqlContext;
|
|
using Moq;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.Test.Common
|
|
{
|
|
public class MemoryFileSystem
|
|
{
|
|
|
|
public static IFileStreamFactory GetFileStreamFactory(int sizeFactor=1)
|
|
{
|
|
return GetFileStreamFactory(new ConcurrentDictionary<string, byte[]>(), sizeFactor);
|
|
}
|
|
|
|
public static IFileStreamFactory GetFileStreamFactory(ConcurrentDictionary<string, byte[]> storage, int sizeFactor=1)
|
|
{
|
|
Mock<IFileStreamFactory> mock = new Mock<IFileStreamFactory>();
|
|
mock.Setup(fsf => fsf.CreateFile())
|
|
.Returns(() =>
|
|
{
|
|
string fileName = Guid.NewGuid().ToString();
|
|
storage.TryAdd(fileName, new byte[8192 * sizeFactor]);
|
|
return fileName;
|
|
});
|
|
mock.Setup(fsf => fsf.GetReader(It.IsAny<string>()))
|
|
.Returns<string>(output => new ServiceBufferFileStreamReader(new MemoryStream(storage[output]), new QueryExecutionSettings()));
|
|
mock.Setup(fsf => fsf.GetWriter(It.IsAny<string>(), It.IsAny<IReadOnlyList<DbColumnWrapper>>()))
|
|
.Returns<string, IReadOnlyList<DbColumnWrapper>>((output, _) => new ServiceBufferFileStreamWriter(new MemoryStream(storage[output]), new QueryExecutionSettings()));
|
|
|
|
return mock.Object;
|
|
}
|
|
|
|
}
|
|
}
|