public void UniqueSourceFilesPushedToWorkspace()
        {
            var             sourceFilesPushedToWorkspace = new HashSet <string>(StringComparers.Paths);
            Action <string> onSourceFileAdded            = s => Assert.True(sourceFilesPushedToWorkspace.Add(s));
            Action <string> onSourceFileRemoved          = s => sourceFilesPushedToWorkspace.Remove(s);

            var project = UnconfiguredProjectFactory.Create(filePath: @"C:\Myproject.csproj");
            var context = IWorkspaceProjectContextFactory.CreateForSourceFiles(project, onSourceFileAdded, onSourceFileRemoved);

            var handler    = new SourceItemHandler(project);
            var projectDir = Path.GetDirectoryName(project.FullPath);
            var added      = BuildOptions.FromCommonCommandLineArguments(CSharpCommandLineParser.Default.Parse(args: new[] { @"C:\file1.cs", @"C:\file2.cs", @"C:\file1.cs" }, baseDirectory: projectDir, sdkDirectory: null));
            var empty      = BuildOptions.FromCommonCommandLineArguments(CSharpCommandLineParser.Default.Parse(args: new string[] { }, baseDirectory: projectDir, sdkDirectory: null));

            handler.Handle(added: added, removed: empty, context: context, isActiveContext: true);

            Assert.Equal(2, sourceFilesPushedToWorkspace.Count);
            Assert.Contains(@"C:\file1.cs", sourceFilesPushedToWorkspace);
            Assert.Contains(@"C:\file2.cs", sourceFilesPushedToWorkspace);

            var removed = BuildOptions.FromCommonCommandLineArguments(CSharpCommandLineParser.Default.Parse(args: new[] { @"C:\file1.cs", @"C:\file1.cs" }, baseDirectory: projectDir, sdkDirectory: null));

            handler.Handle(added: empty, removed: removed, context: context, isActiveContext: true);

            Assert.Equal(1, sourceFilesPushedToWorkspace.Count);
            Assert.Contains(@"C:\file2.cs", sourceFilesPushedToWorkspace);
        }
Ejemplo n.º 2
0
        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      = BuildOptions.FromCommonCommandLineArguments(CSharpCommandLineParser.Default.Parse(args: new[] { @"/reference:C:\Assembly1.dll", @"/reference:C:\Assembly2.dll", @"/reference:C:\Assembly1.dll" }, baseDirectory: projectDir, sdkDirectory: null));
            var empty      = BuildOptions.FromCommonCommandLineArguments(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 = BuildOptions.FromCommonCommandLineArguments(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);
        }