Changing test project creation to using test asset instead of new command
This commit is contained in:
parent
c18ce0d6af
commit
981e4c6c26
1 changed files with 18 additions and 16 deletions
|
@ -3,7 +3,6 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.DotNet.TestFramework;
|
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
using NuGet.Versioning;
|
using NuGet.Versioning;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
@ -20,18 +19,16 @@ namespace EndToEnd
|
||||||
[Fact]
|
[Fact]
|
||||||
public void DefaultRuntimeVersionsAreUpToDate()
|
public void DefaultRuntimeVersionsAreUpToDate()
|
||||||
{
|
{
|
||||||
var directory = TestAssets.CreateTestDirectory();
|
|
||||||
string projectDirectory = directory.FullName;
|
|
||||||
var outputFile = "resolvedVersions.txt";
|
var outputFile = "resolvedVersions.txt";
|
||||||
|
var testProjectCreator = new TestProjectCreator()
|
||||||
|
{
|
||||||
|
PackageName = "DefaultRuntimeVersionsAreUpToDate",
|
||||||
|
MinorVersion = "3.0"
|
||||||
|
};
|
||||||
|
var testProject = testProjectCreator.Create();
|
||||||
|
|
||||||
new NewCommandShim()
|
var projectFile = new DirectoryInfo(testProject.Root.FullName).GetFiles("*.csproj").First().FullName;
|
||||||
.WithWorkingDirectory(projectDirectory)
|
|
||||||
.Execute("console --no-restore")
|
|
||||||
.Should().Pass();
|
|
||||||
|
|
||||||
var projectFile = new DirectoryInfo(projectDirectory).GetFiles("*.csproj").First().FullName;
|
|
||||||
var project = XDocument.Load(projectFile);
|
var project = XDocument.Load(projectFile);
|
||||||
var ns = project.Root.Name.Namespace;
|
|
||||||
string writeResolvedVersionsTarget = @$"
|
string writeResolvedVersionsTarget = @$"
|
||||||
<Target Name=`WriteResolvedVersions` AfterTargets=`PrepareForBuild;ProcessFrameworkReferences`>
|
<Target Name=`WriteResolvedVersions` AfterTargets=`PrepareForBuild;ProcessFrameworkReferences`>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
@ -44,18 +41,23 @@ namespace EndToEnd
|
||||||
|
|
||||||
</Target>";
|
</Target>";
|
||||||
writeResolvedVersionsTarget = writeResolvedVersionsTarget.Replace('`', '"');
|
writeResolvedVersionsTarget = writeResolvedVersionsTarget.Replace('`', '"');
|
||||||
project.Root.Add(XElement.Parse(writeResolvedVersionsTarget));
|
var targetElement = XElement.Parse(writeResolvedVersionsTarget);
|
||||||
|
var ns = project.Root.Name.Namespace;
|
||||||
|
foreach (var elem in targetElement.Descendants())
|
||||||
|
elem.Name = ns + elem.Name.LocalName;
|
||||||
|
targetElement.Name = ns + targetElement.Name.LocalName;
|
||||||
|
project.Root.Add(targetElement);
|
||||||
using (var file = File.CreateText(projectFile))
|
using (var file = File.CreateText(projectFile))
|
||||||
{
|
{
|
||||||
project.Save(file);
|
project.Save(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
new BuildCommand()
|
new RestoreCommand()
|
||||||
.WithWorkingDirectory(projectDirectory)
|
.WithWorkingDirectory(testProject.Root.FullName)
|
||||||
.Execute()
|
.Execute()
|
||||||
.Should().Pass();
|
.Should().Pass();
|
||||||
|
|
||||||
var binDirectory = new DirectoryInfo(projectDirectory).Sub("bin").Sub("Debug").GetDirectories().FirstOrDefault();
|
var binDirectory = new DirectoryInfo(testProject.Root.FullName).Sub("bin").Sub("Debug").GetDirectories().FirstOrDefault();
|
||||||
binDirectory.Should().HaveFilesMatching(outputFile, SearchOption.TopDirectoryOnly);
|
binDirectory.Should().HaveFilesMatching(outputFile, SearchOption.TopDirectoryOnly);
|
||||||
var resolvedVersionsFile = File.ReadAllLines(Path.Combine(binDirectory.FullName, outputFile));
|
var resolvedVersionsFile = File.ReadAllLines(Path.Combine(binDirectory.FullName, outputFile));
|
||||||
foreach (var framework in frameworks)
|
foreach (var framework in frameworks)
|
||||||
|
|
Loading…
Reference in a new issue