public void DuplicateMetadataReferencesPushedToWorkspace() { var referencesPushedToWorkspace = new HashSet <string>(StringComparers.Paths); Action <string> onReferenceAdded = s => referencesPushedToWorkspace.Add(s); Action <string> onReferenceRemoved = s => referencesPushedToWorkspace.Remove(s); var project = UnconfiguredProjectFactory.Create(filePath: @"C:\Myproject.csproj"); var context = IWorkspaceProjectContextFactory.CreateForMetadataReferences(project, onReferenceAdded, onReferenceRemoved); var logger = Mock.Of <IProjectLogger>(); var handler = new MetadataReferenceItemHandler(project, context); var projectDir = Path.GetDirectoryName(project.FullPath); var added = BuildOptions.FromCommandLineArguments(CSharpCommandLineParser.Default.Parse(args: new[] { @"/reference:C:\Assembly1.dll", @"/reference:C:\Assembly2.dll", @"/reference:C:\Assembly1.dll" }, baseDirectory: projectDir, sdkDirectory: null)); var empty = BuildOptions.FromCommandLineArguments(CSharpCommandLineParser.Default.Parse(args: new string[] { }, baseDirectory: projectDir, sdkDirectory: null)); handler.Handle(10, added: added, removed: empty, isActiveContext: true, logger: logger); AssertEx.CollectionLength(referencesPushedToWorkspace, 2); Assert.Contains(@"C:\Assembly1.dll", referencesPushedToWorkspace); Assert.Contains(@"C:\Assembly2.dll", referencesPushedToWorkspace); var removed = BuildOptions.FromCommandLineArguments(CSharpCommandLineParser.Default.Parse(args: new[] { @"/reference:C:\Assembly1.dll", @"/reference:C:\Assembly1.dll" }, baseDirectory: projectDir, sdkDirectory: null)); handler.Handle(10, added: empty, removed: removed, isActiveContext: true, logger: logger); Assert.Single(referencesPushedToWorkspace); Assert.Contains(@"C:\Assembly2.dll", referencesPushedToWorkspace); }
public void DuplicateMetadataReferencesPushedToWorkspace() { var referencesPushedToWorkspace = new HashSet <string>(StringComparers.Paths); Action <string> onReferenceAdded = s => referencesPushedToWorkspace.Add(s); Action <string> onReferenceRemoved = s => referencesPushedToWorkspace.Remove(s); var project = UnconfiguredProjectFactory.Create(filePath: @"C:\Myproject.csproj"); var context = IWorkspaceProjectContextFactory.CreateForMetadataReferences(project, onReferenceAdded, onReferenceRemoved); var handler = new MetadataReferenceItemHandler(project); var projectDir = Path.GetDirectoryName(project.FullPath); var added = CSharpCommandLineParser.Default.Parse(args: new[] { @"/reference:C:\Assembly1.dll", @"/reference:C:\Assembly2.dll", @"/reference:C:\Assembly1.dll" }, baseDirectory: projectDir, sdkDirectory: null); var empty = CSharpCommandLineParser.Default.Parse(args: new string[] { }, baseDirectory: projectDir, sdkDirectory: null); handler.Handle(added: added, removed: empty, context: context, isActiveContext: true); Assert.Equal(2, referencesPushedToWorkspace.Count); Assert.Contains(@"C:\Assembly1.dll", referencesPushedToWorkspace); Assert.Contains(@"C:\Assembly2.dll", referencesPushedToWorkspace); var removed = CSharpCommandLineParser.Default.Parse(args: new[] { @"/reference:C:\Assembly1.dll", @"/reference:C:\Assembly1.dll" }, baseDirectory: projectDir, sdkDirectory: null); handler.Handle(added: empty, removed: removed, context: context, isActiveContext: true); Assert.Equal(1, referencesPushedToWorkspace.Count); Assert.Contains(@"C:\Assembly2.dll", referencesPushedToWorkspace); }
private static MetadataReferenceItemHandler CreateInstance(UnconfiguredProject?project = null, IWorkspaceProjectContext?context = null) { project ??= UnconfiguredProjectFactory.Create(); var handler = new MetadataReferenceItemHandler(project); if (context != null) { handler.Initialize(context); } return(handler); }
public void RootedReferencesPushedToWorkspace() { var referencesPushedToWorkspace = new HashSet <string>(StringComparers.Paths); Action <string> onReferenceAdded = s => referencesPushedToWorkspace.Add(s); Action <string> onReferenceRemoved = s => referencesPushedToWorkspace.Remove(s); var project = UnconfiguredProjectFactory.Create(filePath: @"C:\ProjectFolder\Myproject.csproj"); var context = IWorkspaceProjectContextFactory.CreateForMetadataReferences(project, onReferenceAdded, onReferenceRemoved); var handler = new MetadataReferenceItemHandler(project, context); var projectDir = Path.GetDirectoryName(project.FullPath); var added = BuildOptions.FromCommandLineArguments(CSharpCommandLineParser.Default.Parse(args: new[] { @"/reference:Assembly1.dll", @"/reference:C:\ProjectFolder\Assembly2.dll", @"/reference:..\ProjectFolder\Assembly3.dll" }, baseDirectory: projectDir, sdkDirectory: null)); var removed = BuildOptions.FromCommandLineArguments(CSharpCommandLineParser.Default.Parse(args: new string[] { }, baseDirectory: projectDir, sdkDirectory: null)); handler.Handle(10, added: added, removed: removed, isActiveContext: true); Assert.Equal(3, referencesPushedToWorkspace.Count); Assert.Contains(@"C:\ProjectFolder\Assembly1.dll", referencesPushedToWorkspace); Assert.Contains(@"C:\ProjectFolder\Assembly2.dll", referencesPushedToWorkspace); Assert.Contains(@"C:\ProjectFolder\Assembly3.dll", referencesPushedToWorkspace); }