public void TestP2PReference() { var workspace = new AdhocWorkspace(); var project1 = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "proj1", "proj1", LanguageNames.CSharp); var project2 = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "proj2", "proj2", LanguageNames.CSharp, projectReferences: SpecializedCollections.SingletonEnumerable(new ProjectReference(project1.Id))); var solutionInfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default, projects: new ProjectInfo[] { project1, project2 }); var solution = workspace.AddSolution(solutionInfo); var instance = new object(); var weak = new WeakReference(instance); var cacheService = new ProjectCacheService(workspace, int.MaxValue); using (var cache = cacheService.EnableCaching(project2.Id)) { cacheService.CacheObjectIfCachingEnabledForKey(project1.Id, (object)null, instance); instance = null; solution = null; workspace.OnProjectRemoved(project1.Id); workspace.OnProjectRemoved(project2.Id); } // make sure p2p reference doesn't go to implicit cache CollectGarbage(); Assert.False(weak.IsAlive); }
public void TestP2PReference() { var workspace = new AdhocWorkspace(); var project1 = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "proj1", "proj1", LanguageNames.CSharp); var project2 = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "proj2", "proj2", LanguageNames.CSharp, projectReferences: SpecializedCollections.SingletonEnumerable(new ProjectReference(project1.Id))); var solutionInfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default, projects: new ProjectInfo[] { project1, project2 }); var solution = workspace.AddSolution(solutionInfo); var instanceTracker = ObjectReference.CreateFromFactory(() => new object()); var cacheService = new ProjectCacheService(workspace, TimeSpan.MaxValue); using (var cache = cacheService.EnableCaching(project2.Id)) { instanceTracker.UseReference(r => cacheService.CacheObjectIfCachingEnabledForKey(project1.Id, (object)null, r)); solution = null; workspace.OnProjectRemoved(project1.Id); workspace.OnProjectRemoved(project2.Id); } // make sure p2p reference doesn't go to implicit cache instanceTracker.AssertReleased(); }
public void TestP2PReference() { var workspace = new AdhocWorkspace(); var project1 = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "proj1", "proj1", LanguageNames.CSharp); var project2 = ProjectInfo.Create(ProjectId.CreateNewId(), VersionStamp.Default, "proj2", "proj2", LanguageNames.CSharp, projectReferences: SpecializedCollections.SingletonEnumerable(new ProjectReference(project1.Id))); var solutionInfo = SolutionInfo.Create(SolutionId.CreateNewId(), VersionStamp.Default, projects: new ProjectInfo[] { project1, project2 }); var solution = workspace.AddSolution(solutionInfo); var instance = new object(); var weak = new WeakReference(instance); var cacheService = new ProjectCacheService(workspace, int.MaxValue); using (var cache = cacheService.EnableCaching(project2.Id)) { cacheService.CacheObjectIfCachingEnabledForKey(project1.Id, (object)null, instance); instance = null; solution = null; workspace.OnProjectRemoved(project1.Id); workspace.OnProjectRemoved(project2.Id); } // make sure p2p reference doesnt go to implicit cache CollectGarbage(); Assert.False(weak.IsAlive); }