示例#1
0
        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 logger  = Mock.Of <IProjectLogger>();

            var handler    = new SourceItemHandler(project, context);
            var projectDir = Path.GetDirectoryName(project.FullPath);
            var added      = BuildOptions.FromCommandLineArguments(CSharpCommandLineParser.Default.Parse(args: new[] { @"C:\file1.cs", @"C:\file2.cs", @"C:\file1.cs" }, 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);

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

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

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

            Assert.Equal(1, sourceFilesPushedToWorkspace.Count);
            Assert.Contains(@"C:\file2.cs", sourceFilesPushedToWorkspace);
        }
        private SourceItemHandler CreateInstance(UnconfiguredProject project = null, IWorkspaceProjectContext context = null)
        {
            project = project ?? UnconfiguredProjectFactory.Create();

            var handler = new SourceItemHandler(project);

            if (context != null)
            {
                handler.Initialize(context);
            }

            return(handler);
        }
        public void RootedSourceFilesPushedToWorkspace()
        {
            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:\ProjectFolder\Myproject.csproj");
            var context = IWorkspaceProjectContextFactory.CreateForSourceFiles(project, onSourceFileAdded, onSourceFileRemoved);

            var handler    = new SourceItemHandler(project, IPhysicalProjectTreeFactory.Create());
            var projectDir = Path.GetDirectoryName(project.FullPath);
            var added      = CSharpCommandLineParser.Default.Parse(args: new[] { @"file1.cs", @"..\ProjectFolder\file1.cs" }, baseDirectory: projectDir, sdkDirectory: null);
            var removed    = CSharpCommandLineParser.Default.Parse(args: new string[] { }, baseDirectory: projectDir, sdkDirectory: null);

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

            Assert.Equal(1, sourceFilesPushedToWorkspace.Count);
            Assert.Contains(@"C:\ProjectFolder\file1.cs", sourceFilesPushedToWorkspace);
        }