提交 b56a8018 编写于 作者: Š Šimon Koníček

Test cleanup

上级 4f90119d
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Xml.Linq;
using Microsoft.VisualStudio.IntegrationTest.Utilities;
using Xunit;
namespace Roslyn.VisualStudio.IntegrationTests
{
public abstract class AbstractUpdateProjectTest : AbstractIntegrationTest
{
protected AbstractUpdateProjectTest(VisualStudioInstanceFactory instanceFactory)
: base(instanceFactory)
{
}
protected void VerifyPropertyOutsideConfiguration(XElement projectElement, string name, string value)
{
Assert.True(projectElement.Elements()
.Where(e => e.Name.LocalName == "PropertyGroup" && !e.Attributes().Any(a => a.Name.LocalName == "Condition"))
.Any(g => g.Elements().SingleOrDefault(e => e.Name.LocalName == name)?.Value == value));
}
protected void VerifyPropertyInEachConfiguration(XElement projectElement, string name, string value)
{
Assert.True(projectElement.Elements()
.Where(e => e.Name.LocalName == "PropertyGroup" && e.Attributes().Any(a => a.Name.LocalName == "Condition"))
.All(g => g.Elements().SingleOrDefault(e => e.Name.LocalName == name)?.Value == value));
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
......@@ -12,7 +11,7 @@
namespace Roslyn.VisualStudio.IntegrationTests.Other
{
[Collection(nameof(SharedIntegrationHostFixture))]
public class CSharpUpdateProjectToAllowUnsafe : AbstractIntegrationTest
public class CSharpUpdateProjectToAllowUnsafe : AbstractUpdateProjectTest
{
public CSharpUpdateProjectToAllowUnsafe(VisualStudioInstanceFactory instanceFactory) : base(instanceFactory)
{
......@@ -39,36 +38,32 @@ unsafe class C
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUpdateProjectToAllowUnsafe)]
public void CPSProject_GeneralPropertyGroupUpdated()
{
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
VisualStudio.SolutionExplorer.AddProject(project, WellKnownProjectTemplates.CSharpNetStandardClassLibrary, LanguageNames.CSharp);
Assert.True(InvokeFixAndGetProjectFileElement(project).Elements()
.Where(e => e.Name.LocalName == "PropertyGroup" && !e.Attributes().Any(a => a.Name.LocalName == "Condition"))
.Any(g => g.Elements().SingleOrDefault(e => e.Name.LocalName == "AllowUnsafeBlocks")?.Value == "true"));
VerifyPropertyOutsideConfiguration(InvokeFixAndGetProjectFileElement(project), "AllowUnsafeBlocks", "true");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
public void LegacyProject_AllConfigurationsUpdated()
{
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
VisualStudio.SolutionExplorer.AddProject(project, WellKnownProjectTemplates.ClassLibrary, LanguageNames.CSharp);
Assert.True(InvokeFixAndGetProjectFileElement(project).Elements()
.Where(e => e.Name.LocalName == "PropertyGroup" && e.Attributes().Any(a => a.Name.LocalName == "Condition"))
.All(g => g.Elements().SingleOrDefault(e => e.Name.LocalName == "AllowUnsafeBlocks")?.Value == "true"));
VerifyPropertyInEachConfiguration(InvokeFixAndGetProjectFileElement(project), "AllowUnsafeBlocks", "true");
}
[WorkItem(23342, "https://github.com/dotnet/roslyn/issues/23342")]
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUpdateProjectToAllowUnsafe)]
public void LegacyProject_MultiplePlatforms_AllConfigurationsUpdated()
{
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
VisualStudio.SolutionExplorer.AddCustomProject(project, ".csproj", $@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project ToolsVersion=""15.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" />
......@@ -104,9 +99,7 @@ public void LegacyProject_MultiplePlatforms_AllConfigurationsUpdated()
<Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />
</Project>");
Assert.True(InvokeFixAndGetProjectFileElement(project).Elements()
.Where(e => e.Name.LocalName == "PropertyGroup" && e.Attributes().Any(a => a.Name.LocalName == "Condition"))
.All(g => g.Elements().SingleOrDefault(e => e.Name.LocalName == "AllowUnsafeBlocks")?.Value == "true"));
VerifyPropertyInEachConfiguration(InvokeFixAndGetProjectFileElement(project), "AllowUnsafeBlocks", "true");
}
}
}
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
......@@ -12,7 +11,7 @@
namespace Roslyn.VisualStudio.IntegrationTests.Other
{
[Collection(nameof(SharedIntegrationHostFixture))]
public class CSharpUpgradeProject : AbstractIntegrationTest
public class CSharpUpgradeProject : AbstractUpdateProjectTest
{
public CSharpUpgradeProject(VisualStudioInstanceFactory instanceFactory) : base(instanceFactory)
{
......@@ -40,37 +39,33 @@ class C
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
public void CPSProject_GeneralPropertyGroupUpdated()
{
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
VisualStudio.SolutionExplorer.AddProject(project, WellKnownProjectTemplates.CSharpNetStandardClassLibrary, LanguageNames.CSharp);
Assert.True(InvokeFixAndGetProjectFileElement(project).Elements()
.Where(e => e.Name.LocalName == "PropertyGroup" && !e.Attributes().Any(a => a.Name.LocalName == "Condition"))
.Any(g => g.Elements().SingleOrDefault(e => e.Name.LocalName == "LangVersion")?.Value == "7.1"));
VerifyPropertyOutsideConfiguration(InvokeFixAndGetProjectFileElement(project), "LangVersion", "7.1");
}
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
public void LegacyProject_AllConfigurationsUpdated()
{
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
var project = new ProjectUtils.Project(ProjectName);
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
VisualStudio.SolutionExplorer.AddProject(project, WellKnownProjectTemplates.ClassLibrary, LanguageNames.CSharp);
Assert.True(InvokeFixAndGetProjectFileElement(project).Elements()
.Where(e => e.Name.LocalName == "PropertyGroup" && e.Attributes().Any(a => a.Name.LocalName == "Condition"))
.All(g => g.Elements().SingleOrDefault(e => e.Name.LocalName == "LangVersion")?.Value == "7.1"));
VerifyPropertyInEachConfiguration(InvokeFixAndGetProjectFileElement(project), "LangVersion", "7.1");
}
[WorkItem(23342, "https://github.com/dotnet/roslyn/issues/23342")]
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsUpgradeProject)]
public void LegacyProject_MultiplePlatforms_AllConfigurationsUpdated()
{
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
var project = new ProjectUtils.Project(ProjectName);
// Be explicit about 7.0 in Debug|x64 so that this doesn't break when a new major version is released.
VisualStudio.SolutionExplorer.CreateSolution(SolutionName);
VisualStudio.SolutionExplorer.AddCustomProject(project, ".csproj", $@"<?xml version=""1.0"" encoding=""utf-8""?>
<Project ToolsVersion=""15.0"" xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
<Import Project=""$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"" Condition=""Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"" />
......@@ -106,9 +101,7 @@ public void LegacyProject_MultiplePlatforms_AllConfigurationsUpdated()
<Import Project=""$(MSBuildToolsPath)\Microsoft.CSharp.targets"" />
</Project>");
Assert.True(InvokeFixAndGetProjectFileElement(project).Elements()
.Where(e => e.Name.LocalName == "PropertyGroup" && e.Attributes().Any(a => a.Name.LocalName == "Condition"))
.All(g => g.Elements().SingleOrDefault(e => e.Name.LocalName == "LangVersion")?.Value == "7.1"));
VerifyPropertyInEachConfiguration(InvokeFixAndGetProjectFileElement(project), "LangVersion", "7.1");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册