public void AddItem_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\test3.fs"", DisplayOrder: 4, ItemName: ""test3.fs""
");

            var projectRootElement = @"
<Project>

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

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

</Project>
".AsProjectRootElement();

            var project = new Project(projectRootElement);

            var elements = 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 = @"<?xml version=""1.0"" encoding=""utf-16""?>
<Project>
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include=""test4.fs"" />
    <Compile Include=""test1.fs"" />
    <Compile Include=""test2.fs"" />
    <Compile Include=""test3.fs"" />
  </ItemGroup>
</Project>";

            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);
        }