Beispiel #1
0
        public void MoveUpFile_IsSuccessful()
        {
            var tree = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\testing.fsproj""
    File (flags: {}), FilePath: ""C:\Foo\test1.fs"", DisplayOrder: 1, ItemName: ""test1.fs""
    File (flags: {}), FilePath: ""C:\Foo\test2.fs"", DisplayOrder: 2, ItemName: ""test2.fs""
");

            var projectRootElement = @"
<Project>

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include=""test1.fs"" />
    <Compile Include=""test2.fs"" />
  </ItemGroup>

</Project>
".AsProjectRootElement();

            var project = new Project(projectRootElement);

            Assert.True(OrderingHelper.TryMoveUp(project, tree.Children[1]));
            Assert.True(project.IsDirty);

            var expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project>
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include=""test2.fs"" />
    <Compile Include=""test1.fs"" />
  </ItemGroup>
</Project>";

            AssertEqualProject(expected, project);
        }
        protected override async Task <bool> TryHandleCommandAsync(IProjectTree node, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut)
        {
            var nodeToAddTo = GetNodeToAddTo(node);

            // Call OnAddingNodesAsync.
            // Then publish changes that could have taken place in OnAddingNodesAsync.
            await OnAddingNodesAsync(nodeToAddTo).ConfigureAwait(true);

            await _projectTree.TreeService.PublishLatestTreeAsync(waitForFileSystemUpdates : true).ConfigureAwait(true);

            var updatedNode        = _projectTree.CurrentTree.Find(node.Identity);
            var updatedNodeToAddTo = _projectTree.CurrentTree.Find(nodeToAddTo.Identity);
            var addedNodes         = OrderingHelper.GetAddedNodes(nodeToAddTo, updatedNodeToAddTo);

            if (addedNodes.Any())
            {
                // Make sure to change ConfigureAwait to "true" if we need switch back.
                await OnAddedNodesAsync(_projectVsServices.ActiveConfiguredProject, node, addedNodes, updatedNode).ConfigureAwait(false);
            }

            return(true);
        }
 protected override bool CanAdd(IProjectTree target)
 {
     return(OrderingHelper.HasValidDisplayOrder(target));
 }
        public void MoveFileUp_WithImportedFileInterspersed()
        {
            var tree = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\testing.fsproj""
    File (flags: {}), FilePath: ""C:\Foo\test1.fs"", DisplayOrder: 1, ItemName: ""test1.fs""
    File (flags: {}), FilePath: ""C:\Foo\test2.fs"", DisplayOrder: 2, ItemName: ""test2.fs""
    File (flags: {}), FilePath: ""C:\Foo\test3.fs"", DisplayOrder: 2, ItemName: ""test3.fs""
");

            var(tempPath, testPropsFile) = CreateTempPropsFilePath();

            var projectRootElement = string.Format(@"
<Project>

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include=""test1.fs"" />
  </ItemGroup>

  <Import Project=""{0}"" />

  <ItemGroup>
    <Compile Include=""test3.fs"" />
  </ItemGroup>

</Project>
", testPropsFile).AsProjectRootElement();

            var projectImportElement = @"
<Project>
  <ItemGroup>
    <Compile Include=""test2.fs"" />
  </ItemGroup>
</Project>
".AsProjectRootElement();

            var project = CreateProjectWithImport(projectRootElement, projectImportElement, tempPath, testPropsFile);

            Assert.True(OrderingHelper.TryMoveUp(project, tree.Children[2]));
            Assert.True(project.IsDirty);

            // The expected result here may not be the desired behavior, but it is the current behavior that we need to test for.
            // Moving test3.fs up, skips the import, but also moves above test1.fs, that is due to skipping imports during manipulation.
            var expected = string.Format(@"<?xml version=""1.0"" encoding=""utf-16""?>
<Project>
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include=""test3.fs"" />
    <Compile Include=""test1.fs"" />
  </ItemGroup>
  <Import Project=""{0}"" />
  <ItemGroup />
</Project>", testPropsFile);

            AssertEqualProject(expected, project);
        }
        public void AddFile_WithImportedFileAtTop()
        {
            var tree = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\testing.fsproj""
    File (flags: {}), FilePath: ""C:\Foo\test1.fs"", DisplayOrder: 1, ItemName: ""test1.fs""
    File (flags: {}), FilePath: ""C:\Foo\test2.fs"", DisplayOrder: 2, ItemName: ""test2.fs""
");

            var updatedTree = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\testing.fsproj""
    File (flags: {}), FilePath: ""C:\Foo\test1.fs"", DisplayOrder: 1, ItemName: ""test1.fs""
    File (flags: {}), FilePath: ""C:\Foo\test2.fs"", DisplayOrder: 2, ItemName: ""test2.fs""
    File (flags: {}), FilePath: ""C:\Foo\test3.fs"", DisplayOrder: 2, ItemName: ""test3.fs""
");

            var(tempPath, testPropsFile) = CreateTempPropsFilePath();

            var projectRootElement = string.Format(@"
<Project>

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <Import Project=""{0}"" />

  <ItemGroup>
    <Compile Include=""test2.fs"" />
    <Compile Include=""test3.fs"" />
  </ItemGroup>

</Project>
", testPropsFile).AsProjectRootElement();

            var projectImportElement = @"
<Project>
  <ItemGroup>
    <Compile Include=""test1.fs"" />
  </ItemGroup>
</Project>
".AsProjectRootElement();

            var project = CreateProjectWithImport(projectRootElement, projectImportElement, tempPath, testPropsFile);

            var elements =
                OrderingHelper.GetItemElements(project, updatedTree.Children[0], ImmutableArray <string> .Empty)
                .AddRange(OrderingHelper.GetItemElements(project, updatedTree.Children[2], ImmutableArray <string> .Empty));

            Assert.True(OrderingHelper.TryMoveElementsToTop(project, elements, tree), "TryMoveElementsToTop returned false.");
            Assert.True(project.IsDirty);

            var expected = string.Format(@"<?xml version=""1.0"" encoding=""utf-16""?>
<Project>
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <Import Project=""{0}"" />
  <ItemGroup>
    <Compile Include=""test3.fs"" />
    <Compile Include=""test2.fs"" />
  </ItemGroup>
</Project>", testPropsFile);

            AssertEqualProject(expected, project);
        }
        public void AddItemsInNestedFolder_IsSuccessful()
        {
            var tree = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\testing.fsproj""
    Folder (flags: {Folder}), FilePath: ""C:\Foo\test""
        Folder (flags: {Folder}), FilePath: ""C:\Foo\test\nested""
    File (flags: {}), FilePath: ""C:\Foo\test1.fs"", DisplayOrder: 1, ItemName: ""test1.fs""
    File (flags: {}), FilePath: ""C:\Foo\test2.fs"", DisplayOrder: 2, ItemName: ""test2.fs""
    File (flags: {}), FilePath: ""C:\Foo\test3.fs"", DisplayOrder: 3, ItemName: ""test3.fs""
");

            var updatedTree = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\testing.fsproj""
    File (flags: {}), FilePath: ""C:\Foo\test1.fs"", DisplayOrder: 1, ItemName: ""test1.fs""
    File (flags: {}), FilePath: ""C:\Foo\test2.fs"", DisplayOrder: 2, ItemName: ""test2.fs""
    Folder (flags: {Folder}), FilePath: ""C:\Foo\test"", DisplayOrder: 3
        Folder (flags: {Folder}), FilePath: ""C:\Foo\test\nested"", DisplayOrder: 4
            File (flags: {}), FilePath: ""C:\Foo\test\nested\test4.fs"", DisplayOrder: 5, ItemName: ""test\nested\test4.fs""
            File (flags: {}), FilePath: ""C:\Foo\test\tested\test5.fs"", DisplayOrder: 6, ItemName: ""test\nested\test5.fs""
    File (flags: {}), FilePath: ""C:\Foo\test3.fs"", DisplayOrder: 7, ItemName: ""test3.fs""
");

            var projectRootElement = @"
<Project>

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include=""test1.fs"" />
    <Compile Include=""test2.fs"" />
    <Compile Include=""test\nested\test4.fs"" />
    <Compile Include=""test\nested\test5.fs"" />
    <Compile Include=""test3.fs"" />
  </ItemGroup>

</Project>
".AsProjectRootElement();

            var project = new Project(projectRootElement);

            var elements =
                OrderingHelper.GetItemElements(project, updatedTree.Children[2].Children[0].Children[0], ImmutableArray <string> .Empty)
                .AddRange(OrderingHelper.GetItemElements(project, updatedTree.Children[2].Children[0].Children[1], ImmutableArray <string> .Empty));

            Assert.True(OrderingHelper.TryMoveElementsToTop(project, elements, tree), "TryMoveElementsToTop returned false.");
            Assert.True(project.IsDirty);

            var expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project>
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include=""test\nested\test4.fs"" />
    <Compile Include=""test\nested\test5.fs"" />
    <Compile Include=""test1.fs"" />
    <Compile Include=""test2.fs"" />
    <Compile Include=""test3.fs"" />
  </ItemGroup>
</Project>";

            AssertEqualProject(expected, project);
        }
Beispiel #7
0
 protected override Task <bool> TryMoveAsync(ConfiguredProject configuredProject, IProjectTree node)
 {
     return(OrderingHelper.TryMoveUpAsync(configuredProject, node));
 }
Beispiel #8
0
 protected override bool CanMove(IProjectTree node)
 {
     return(OrderingHelper.CanMoveUp(node));
 }
Beispiel #9
0
 protected override bool TryMove(Project project, IProjectTree node)
 {
     return(OrderingHelper.TryMoveDown(project, node));
 }
Beispiel #10
0
        public void AddItems_IsSuccessful()
        {
            var tree = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\testing.fsproj""
    File (flags: {}), FilePath: ""C:\Foo\test1.fs"", DisplayOrder: 1, ItemName: ""test1.fs""
    File (flags: {}), FilePath: ""C:\Foo\test2.fs"", DisplayOrder: 2, ItemName: ""test2.fs""
    File (flags: {}), FilePath: ""C:\Foo\test3.fs"", DisplayOrder: 3, ItemName: ""test3.fs""
");

            var updatedTree = ProjectTreeParser.Parse(@"
Root (flags: {ProjectRoot}), FilePath: ""C:\Foo\testing.fsproj""
    File (flags: {}), FilePath: ""C:\Foo\test1.fs"", DisplayOrder: 1, ItemName: ""test1.fs""
    File (flags: {}), FilePath: ""C:\Foo\test2.fs"", DisplayOrder: 2, ItemName: ""test2.fs""
    File (flags: {}), FilePath: ""C:\Foo\test4.fs"", DisplayOrder: 3, ItemName: ""test4.fs""
    File (flags: {}), FilePath: ""C:\Foo\test5.fs"", DisplayOrder: 4, ItemName: ""test5.fs""
    File (flags: {}), FilePath: ""C:\Foo\test3.fs"", DisplayOrder: 5, ItemName: ""test3.fs""
");

            var addedNodes = new List <IProjectTree>();

            addedNodes.Add(updatedTree.Children[2]);
            addedNodes.Add(updatedTree.Children[3]);

            var projectRootElement = @"
<Project>

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include=""test1.fs"" />
    <Compile Include=""test2.fs"" />
    <Compile Include=""test4.fs"" />
    <Compile Include=""test5.fs"" />
    <Compile Include=""test3.fs"" />
  </ItemGroup>

</Project>
".AsProjectRootElement();

            var project = new Project(projectRootElement);

            Assert.True(OrderingHelper.TryMoveNodesToTop(project, addedNodes, tree), "TryMoveNodesToTop returned false.");
            Assert.True(project.IsDirty);

            var expected = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project>
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include=""test4.fs"" />
    <Compile Include=""test5.fs"" />
    <Compile Include=""test1.fs"" />
    <Compile Include=""test2.fs"" />
    <Compile Include=""test3.fs"" />
  </ItemGroup>
</Project>";

            AssertEqualProject(expected, project);
        }
 protected virtual Task OnAddedNodesAsync(ConfiguredProject configuredProject, IProjectTree target, IEnumerable <IProjectTree> addedNodes, IProjectTree updatedTarget)
 {
     // We are not using the updated target so we don't step over the added nodes.
     return(OrderingHelper.TryMoveNodesToTopAsync(configuredProject, addedNodes, target));
 }
Beispiel #12
0
        protected override async Task <bool> TryHandleCommandAsync(IProjectTree node, bool focused, long commandExecuteOptions, IntPtr variantArgIn, IntPtr variantArgOut)
        {
            var nodeToAddTo = GetNodeToAddTo(node);

            // Publish any existing changes that could potentially be here.
            // Then call OnAddingNodesAsync.
            // Then publish changes that could have taken place in OnAddingNodesAsync.
            await _projectTree.TreeService.PublishLatestTreeAsync(waitForFileSystemUpdates : true).ConfigureAwait(true);

            await OnAddingNodesAsync(nodeToAddTo).ConfigureAwait(true);

            await _projectTree.TreeService.PublishLatestTreeAsync(waitForFileSystemUpdates : true).ConfigureAwait(true);

            // Get the difference to see what was added.
            // We do a sanity check to make sure they have a valid display order.
            // We also order the added nodes by their display order.
            var updatedNode        = _projectTree.CurrentTree.Find(node.Identity);
            var updatedNodeToAddTo = _projectTree.CurrentTree.Find(nodeToAddTo.Identity);
            var addedNodes         =
                updatedNodeToAddTo.Children.Where(x => !nodeToAddTo.TryFind(x.Identity, out var subtree) && OrderingHelper.HasValidDisplayOrder(x))
                .OrderBy(OrderingHelper.GetDisplayOrder).ToList();

            if (addedNodes.Any())
            {
                await OnAddedNodesAsync(_projectVsServices.ActiveConfiguredProject, addedNodes, updatedNode).ConfigureAwait(true);
            }

            return(true);
        }