提交 f125368c 编写于 作者: C CyrusNajmabadi

Add tests.

上级 0d01ae98
......@@ -368,11 +368,11 @@ private void DoSimultaneousReads(Func<Task<string>> read, string expectedValue)
Assert.Equal(new List<Exception>(), exceptions);
}
private Solution CreateOrOpenSolution()
protected Solution CreateOrOpenSolution(bool nullPaths = false)
{
string solutionFile = Path.Combine(_persistentFolder, "Solution1.sln");
bool newSolution;
if (newSolution = !File.Exists(solutionFile))
var solutionFile = Path.Combine(_persistentFolder, "Solution1.sln");
var newSolution = !File.Exists(solutionFile);
if (newSolution)
{
File.WriteAllText(solutionFile, "");
}
......@@ -386,20 +386,22 @@ private Solution CreateOrOpenSolution()
if (newSolution)
{
string projectFile = Path.Combine(Path.GetDirectoryName(solutionFile), "Project1.csproj");
var projectFile = Path.Combine(Path.GetDirectoryName(solutionFile), "Project1.csproj");
File.WriteAllText(projectFile, "");
solution = solution.AddProject(ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "Project1", "Project1", LanguageNames.CSharp, projectFile));
solution = solution.AddProject(ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Create(), "Project1", "Project1", LanguageNames.CSharp,
filePath: nullPaths ? null : projectFile));
var project = solution.Projects.Single();
string documentFile = Path.Combine(Path.GetDirectoryName(projectFile), "Document1.cs");
var documentFile = Path.Combine(Path.GetDirectoryName(projectFile), "Document1.cs");
File.WriteAllText(documentFile, "");
solution = solution.AddDocument(DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "Document1", filePath: documentFile));
solution = solution.AddDocument(DocumentInfo.Create(DocumentId.CreateNewId(project.Id), "Document1",
filePath: nullPaths ? null : documentFile));
}
return solution;
}
private IPersistentStorage GetStorage(Solution solution)
protected IPersistentStorage GetStorage(Solution solution)
{
var storage = GetStorageService().GetStorage(solution);
......@@ -409,7 +411,7 @@ private IPersistentStorage GetStorage(Solution solution)
protected abstract IPersistentStorageService GetStorageService();
private Stream EncodeString(string text)
protected Stream EncodeString(string text)
{
var bytes = _encoding.GetBytes(text);
var stream = new MemoryStream(bytes);
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.SQLite;
using Xunit;
namespace Microsoft.CodeAnalysis.UnitTests.WorkspaceServices
{
......@@ -14,5 +17,24 @@ public class SQLitePersistentStorageTests : AbstractPersistentStorageTests
{
protected override IPersistentStorageService GetStorageService()
=> new SQLitePersistentStorageService(_persistentEnabledOptionService, testing: true);
[Fact]
public async Task TestNullFilePaths()
{
var solution = CreateOrOpenSolution(nullPaths: true);
var streamName = "stream";
using (var storage = GetStorage(solution))
{
var project = solution.Projects.First();
var document = project.Documents.First();
Assert.False(await storage.WriteStreamAsync(project, streamName, EncodeString("")));
Assert.False(await storage.WriteStreamAsync(document, streamName, EncodeString("")));
Assert.Null(await storage.ReadStreamAsync(project, streamName));
Assert.Null(await storage.ReadStreamAsync(document, streamName));
}
}
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册