提交 82ba8acb 编写于 作者: K Kevin Halverson

Fix tests and add missing null checks...

上级 c8a69b9c
......@@ -18,7 +18,7 @@ private class SimpleMRUCache
private readonly Node[] _nodes = new Node[CacheSize];
public bool Empty
public bool IsEmpty
{
get
{
......
......@@ -39,7 +39,7 @@ public bool IsImplicitCacheEmpty
{
lock (_gate)
{
return _implicitCache.Empty;
return _implicitCache?.IsEmpty ?? false;
}
}
}
......@@ -48,7 +48,7 @@ public void ClearImplicitCache()
{
lock (_gate)
{
_implicitCache.Clear();
_implicitCache?.Clear();
}
}
......@@ -56,7 +56,7 @@ public void ClearExpiredImplicitCache(DateTime expirationTime)
{
lock (_gate)
{
_implicitCache.ClearExpiredItems(expirationTime);
_implicitCache?.ClearExpiredItems(expirationTime);
}
}
......
......@@ -107,7 +107,8 @@ public void TestCacheDoesNotKeepObjectsAliveAfterOwnerIsCollected2()
[Fact]
public void TestImplicitCacheKeepsObjectAlive1()
{
var cacheService = new ProjectCacheService(null, int.MaxValue);
var workspace = new AdhocWorkspace(MockHostServices.Instance, workspaceKind: WorkspaceKind.Host);
var cacheService = new ProjectCacheService(workspace, int.MaxValue);
var instance = new object();
var weak = new WeakReference(instance);
cacheService.CacheObjectIfCachingEnabledForKey(ProjectId.CreateNewId(), (object)null, instance);
......@@ -201,7 +202,8 @@ public void TestEjectFromImplicitCache()
var weakFirst = new WeakReference(compilations[0]);
var weakLast = new WeakReference(compilations[compilations.Count - 1]);
var cache = new ProjectCacheService(null, int.MaxValue);
var workspace = new AdhocWorkspace(MockHostServices.Instance, workspaceKind: WorkspaceKind.Host);
var cache = new ProjectCacheService(workspace, int.MaxValue);
for (int i = 0; i < ProjectCacheService.ImplicitCacheSize + 1; i++)
{
cache.CacheObjectIfCachingEnabledForKey(ProjectId.CreateNewId(), (object)null, compilations[i]);
......@@ -225,7 +227,8 @@ public void TestCacheCompilationTwice()
var weak3 = new WeakReference(comp3);
var weak1 = new WeakReference(comp1);
var cache = new ProjectCacheService(null, int.MaxValue);
var workspace = new AdhocWorkspace(MockHostServices.Instance, workspaceKind: WorkspaceKind.Host);
var cache = new ProjectCacheService(workspace, int.MaxValue);
var key = ProjectId.CreateNewId();
var owner = new object();
cache.CacheObjectIfCachingEnabledForKey(key, owner, comp1);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册