Use a concurrent dict when mocking file stream factory (#465)

This commit is contained in:
Matt Irvine
2017-09-21 10:27:03 -07:00
committed by GitHub
parent 60aad9cf7e
commit 339a9c0fe2
3 changed files with 15 additions and 12 deletions

View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using Microsoft.SqlTools.ServiceLayer.QueryExecution.DataStorage;
@@ -12,17 +13,17 @@ namespace Microsoft.SqlTools.ServiceLayer.Test.Common
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.Setup(fsf => fsf.CreateFile())
.Returns(() =>
{
string fileName = Guid.NewGuid().ToString();
storage.Add(fileName, new byte[8192]);
storage.TryAdd(fileName, new byte[8192]);
return fileName;
});
mock.Setup(fsf => fsf.GetReader(It.IsAny<string>()))