提交 21798af6 编写于 作者: J Jason Malinowski

Add some unit tests to confirm some behavior around metadata reference conversion

上级 ad16d1ce
......@@ -2,7 +2,7 @@
' The .NET Foundation licenses this file to you under the MIT license.
' See the LICENSE file in the project root for more information.
Imports System.Threading
Imports System.Collections.Immutable
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.Test.Utilities
Imports Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim.Framework
......@@ -138,5 +138,101 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.ProjectSystemShim
Task.WaitAll(task1, task2)
End Using
End Sub
<WpfFact>
Public Sub AddingAndRemovingTwoReferencesWithDifferentPropertiesConvertsCorrectly()
Using environment = New TestEnvironment()
Dim referencingProject = environment.ProjectFactory.CreateAndAddToWorkspace("referencingProject", LanguageNames.CSharp)
Dim referencedProject = environment.ProjectFactory.CreateAndAddToWorkspace("referencedProject", LanguageNames.CSharp)
Const ReferencePath = "C:\project.dll"
referencingProject.AddMetadataReference(ReferencePath, New MetadataReferenceProperties(aliases:=ImmutableArray.Create("alias1")))
referencedProject.OutputFilePath = ReferencePath
Dim getReferencingProject = Function() environment.Workspace.CurrentSolution.GetProject(referencingProject.Id)
' The alias should have flowed through correctly
Assert.Equal("alias1", Assert.Single(Assert.Single(getReferencingProject().ProjectReferences).Aliases))
referencingProject.AddMetadataReference(ReferencePath, New MetadataReferenceProperties(aliases:=ImmutableArray.Create("alias2")))
Assert.Equal(2, getReferencingProject().ProjectReferences.Count())
referencingProject.RemoveMetadataReference(ReferencePath, New MetadataReferenceProperties(aliases:=ImmutableArray.Create("alias2")))
' Should be back to the single reference again
Assert.Equal("alias1", Assert.Single(Assert.Single(getReferencingProject().ProjectReferences).Aliases))
referencingProject.RemoveMetadataReference(ReferencePath, New MetadataReferenceProperties(aliases:=ImmutableArray.Create("alias1")))
Assert.Empty(getReferencingProject().ProjectReferences)
End Using
End Sub
<WpfTheory>
<CombinatorialData>
Public Sub MetadataReferenceBeingAddedWhileOutputPathUpdateInInterleavedBatches(closeReferencedProjectBatchFirst As Boolean)
Using environment = New TestEnvironment()
Dim referencingProject = environment.ProjectFactory.CreateAndAddToWorkspace("referencingProject", LanguageNames.CSharp)
Dim referencedProject = environment.ProjectFactory.CreateAndAddToWorkspace("referencedProject", LanguageNames.CSharp)
Dim referencingProjectBatch = referencingProject.CreateBatchScope()
Dim referencedProjectBatch = referencedProject.CreateBatchScope()
Const ReferencePath = "C:\project.dll"
' Set the OutputFilePath first -- we don't expect this to be visible to other projects until the batch is closed
referencedProject.OutputFilePath = ReferencePath
referencingProject.AddMetadataReference(ReferencePath, MetadataReferenceProperties.Assembly)
If closeReferencedProjectBatchFirst Then
referencedProjectBatch.Dispose()
referencingProjectBatch.Dispose()
Else
referencingProjectBatch.Dispose()
referencedProjectBatch.Dispose()
End If
' Either way, we should have a single project reference
Dim getReferencingProject = Function() environment.Workspace.CurrentSolution.GetProject(referencingProject.Id)
Assert.Single(getReferencingProject().ProjectReferences)
Assert.Empty(getReferencingProject().MetadataReferences)
End Using
End Sub
<WpfTheory>
<CombinatorialData>
Public Sub MetadataReferenceBeingRemovedAndReAddedWhileOutputPathUpdateInInterleavedBatches(closeReferencedProjectBatchFirst As Boolean)
Using environment = New TestEnvironment()
Dim referencingProject = environment.ProjectFactory.CreateAndAddToWorkspace("referencingProject", LanguageNames.CSharp)
Dim referencedProject = environment.ProjectFactory.CreateAndAddToWorkspace("referencedProject", LanguageNames.CSharp)
Const ReferencePath = "C:\project.dll"
referencingProject.AddMetadataReference(ReferencePath, MetadataReferenceProperties.Assembly.WithAliases(ImmutableArray.Create("temporary")))
Dim getReferencingProject = Function() environment.Workspace.CurrentSolution.GetProject(referencingProject.Id)
Dim referencingProjectBatch = referencingProject.CreateBatchScope()
Dim referencedProjectBatch = referencedProject.CreateBatchScope()
' Set the OutputFilePath second -- we don't expect this to be visible to other projects until the batch is closed
referencedProject.OutputFilePath = ReferencePath
referencingProject.RemoveMetadataReference(ReferencePath, MetadataReferenceProperties.Assembly.WithAliases(ImmutableArray.Create("temporary")))
referencingProject.AddMetadataReference(ReferencePath, MetadataReferenceProperties.Assembly)
If closeReferencedProjectBatchFirst Then
referencedProjectBatch.Dispose()
referencingProjectBatch.Dispose()
Else
referencingProjectBatch.Dispose()
referencedProjectBatch.Dispose()
End If
' Either way, we should have a single project reference
Assert.Single(getReferencingProject().ProjectReferences)
Assert.Empty(getReferencingProject().MetadataReferences)
End Using
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册